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
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>
13 int connect_req_to_link_param(struct cfcnfg
*cnfg
,
14 struct caif_connect_request
*s
,
15 struct cfctrl_link_param
*l
)
17 struct dev_info
*dev_info
;
18 enum cfcnfg_phy_preference pref
;
19 memset(l
, 0, sizeof(*l
));
20 l
->priority
= s
->priority
;
22 if (s
->link_name
[0] != '\0')
23 l
->phyid
= cfcnfg_get_named(cnfg
, s
->link_name
);
25 switch (s
->link_selector
) {
26 case CAIF_LINK_HIGH_BANDW
:
27 pref
= CFPHYPREF_HIGH_BW
;
29 case CAIF_LINK_LOW_LATENCY
:
30 pref
= CFPHYPREF_LOW_LAT
;
35 dev_info
= cfcnfg_get_phyid(cnfg
, pref
);
38 l
->phyid
= dev_info
->id
;
40 switch (s
->protocol
) {
42 l
->linktype
= CFCTRL_SRV_VEI
;
43 if (s
->sockaddr
.u
.at
.type
== CAIF_ATTYPE_PLAIN
)
46 l
->chtype
= s
->sockaddr
.u
.at
.type
;
49 case CAIFPROTO_DATAGRAM
:
50 l
->linktype
= CFCTRL_SRV_DATAGRAM
;
52 l
->u
.datagram
.connid
= s
->sockaddr
.u
.dgm
.connection_id
;
54 case CAIFPROTO_DATAGRAM_LOOP
:
55 l
->linktype
= CFCTRL_SRV_DATAGRAM
;
58 l
->u
.datagram
.connid
= s
->sockaddr
.u
.dgm
.connection_id
;
61 l
->linktype
= CFCTRL_SRV_RFM
;
62 l
->u
.datagram
.connid
= s
->sockaddr
.u
.rfm
.connection_id
;
63 strncpy(l
->u
.rfm
.volume
, s
->sockaddr
.u
.rfm
.volume
,
64 sizeof(l
->u
.rfm
.volume
)-1);
65 l
->u
.rfm
.volume
[sizeof(l
->u
.rfm
.volume
)-1] = 0;
68 l
->linktype
= CFCTRL_SRV_UTIL
;
71 strncpy(l
->u
.utility
.name
, s
->sockaddr
.u
.util
.service
,
72 sizeof(l
->u
.utility
.name
)-1);
73 l
->u
.utility
.name
[sizeof(l
->u
.utility
.name
)-1] = 0;
74 caif_assert(sizeof(l
->u
.utility
.name
) > 10);
75 l
->u
.utility
.paramlen
= s
->param
.size
;
76 if (l
->u
.utility
.paramlen
> sizeof(l
->u
.utility
.params
))
77 l
->u
.utility
.paramlen
= sizeof(l
->u
.utility
.params
);
79 memcpy(l
->u
.utility
.params
, s
->param
.data
,
80 l
->u
.utility
.paramlen
);