linux/net/caif/caif_config_util.c
<<
>>
Prefs
   1/*
   2 * Copyright (C) ST-Ericsson AB 2010
   3 * Author:      Sjur Brendeland sjur.brandeland@stericsson.com
   4 * License terms: GNU General Public License (GPL) version 2
   5 */
   6
   7#include <linux/module.h>
   8#include <linux/spinlock.h>
   9#include <net/caif/cfctrl.h>
  10#include <net/caif/cfcnfg.h>
  11#include <net/caif/caif_dev.h>
  12
  13int connect_req_to_link_param(struct cfcnfg *cnfg,
  14                                struct caif_connect_request *s,
  15                                struct cfctrl_link_param *l)
  16{
  17        struct dev_info *dev_info;
  18        enum cfcnfg_phy_preference pref;
  19        int res;
  20
  21        memset(l, 0, sizeof(*l));
  22        /* In caif protocol low value is high priority */
  23        l->priority = CAIF_PRIO_MAX - s->priority + 1;
  24
  25        if (s->ifindex != 0){
  26                res = cfcnfg_get_id_from_ifi(cnfg, s->ifindex);
  27                if (res < 0)
  28                        return res;
  29                l->phyid = res;
  30        }
  31        else {
  32                switch (s->link_selector) {
  33                case CAIF_LINK_HIGH_BANDW:
  34                        pref = CFPHYPREF_HIGH_BW;
  35                        break;
  36                case CAIF_LINK_LOW_LATENCY:
  37                        pref = CFPHYPREF_LOW_LAT;
  38                        break;
  39                default:
  40                        return -EINVAL;
  41                }
  42                dev_info = cfcnfg_get_phyid(cnfg, pref);
  43                if (dev_info == NULL)
  44                        return -ENODEV;
  45                l->phyid = dev_info->id;
  46        }
  47        switch (s->protocol) {
  48        case CAIFPROTO_AT:
  49                l->linktype = CFCTRL_SRV_VEI;
  50                if (s->sockaddr.u.at.type == CAIF_ATTYPE_PLAIN)
  51                        l->chtype = 0x02;
  52                else
  53                        l->chtype = s->sockaddr.u.at.type;
  54                l->endpoint = 0x00;
  55                break;
  56        case CAIFPROTO_DATAGRAM:
  57                l->linktype = CFCTRL_SRV_DATAGRAM;
  58                l->chtype = 0x00;
  59                l->u.datagram.connid = s->sockaddr.u.dgm.connection_id;
  60                break;
  61        case CAIFPROTO_DATAGRAM_LOOP:
  62                l->linktype = CFCTRL_SRV_DATAGRAM;
  63                l->chtype = 0x03;
  64                l->endpoint = 0x00;
  65                l->u.datagram.connid = s->sockaddr.u.dgm.connection_id;
  66                break;
  67        case CAIFPROTO_RFM:
  68                l->linktype = CFCTRL_SRV_RFM;
  69                l->u.datagram.connid = s->sockaddr.u.rfm.connection_id;
  70                strncpy(l->u.rfm.volume, s->sockaddr.u.rfm.volume,
  71                        sizeof(l->u.rfm.volume)-1);
  72                l->u.rfm.volume[sizeof(l->u.rfm.volume)-1] = 0;
  73                break;
  74        case CAIFPROTO_UTIL:
  75                l->linktype = CFCTRL_SRV_UTIL;
  76                l->endpoint = 0x00;
  77                l->chtype = 0x00;
  78                strncpy(l->u.utility.name, s->sockaddr.u.util.service,
  79                        sizeof(l->u.utility.name)-1);
  80                l->u.utility.name[sizeof(l->u.utility.name)-1] = 0;
  81                caif_assert(sizeof(l->u.utility.name) > 10);
  82                l->u.utility.paramlen = s->param.size;
  83                if (l->u.utility.paramlen > sizeof(l->u.utility.params))
  84                        l->u.utility.paramlen = sizeof(l->u.utility.params);
  85
  86                memcpy(l->u.utility.params, s->param.data,
  87                       l->u.utility.paramlen);
  88
  89                break;
  90        case CAIFPROTO_DEBUG:
  91                l->linktype = CFCTRL_SRV_DBG;
  92                l->endpoint = s->sockaddr.u.dbg.service;
  93                l->chtype = s->sockaddr.u.dbg.type;
  94                break;
  95        default:
  96                return -EINVAL;
  97        }
  98        return 0;
  99}
 100