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/stddef.h>
8 #include <linux/slab.h>
9 #include <net/caif/caif_layer.h>
10 #include <net/caif/cfsrvl.h>
11 #include <net/caif/cfpkt.h>
13 #define VEI_PAYLOAD 0x00
14 #define VEI_CMD_BIT 0x80
15 #define VEI_FLOW_OFF 0x81
16 #define VEI_FLOW_ON 0x80
17 #define VEI_SET_PIN 0x82
18 #define VEI_CTRL_PKT_SIZE 1
19 #define container_obj(layr) container_of(layr, struct cfsrvl, layer)
21 static int cfvei_receive(struct cflayer
*layr
, struct cfpkt
*pkt
);
22 static int cfvei_transmit(struct cflayer
*layr
, struct cfpkt
*pkt
);
24 struct cflayer
*cfvei_create(u8 channel_id
, struct dev_info
*dev_info
)
26 struct cfsrvl
*vei
= kmalloc(sizeof(struct cfsrvl
), GFP_ATOMIC
);
28 pr_warning("CAIF: %s(): Out of memory\n", __func__
);
31 caif_assert(offsetof(struct cfsrvl
, layer
) == 0);
32 memset(vei
, 0, sizeof(struct cfsrvl
));
33 cfsrvl_init(vei
, channel_id
, dev_info
, true);
34 vei
->layer
.receive
= cfvei_receive
;
35 vei
->layer
.transmit
= cfvei_transmit
;
36 snprintf(vei
->layer
.name
, CAIF_LAYER_NAME_SZ
- 1, "vei%d", channel_id
);
40 static int cfvei_receive(struct cflayer
*layr
, struct cfpkt
*pkt
)
44 caif_assert(layr
->up
!= NULL
);
45 caif_assert(layr
->receive
!= NULL
);
46 caif_assert(layr
->ctrlcmd
!= NULL
);
49 if (cfpkt_extr_head(pkt
, &cmd
, 1) < 0) {
50 pr_err("CAIF: %s(): Packet is erroneous!\n", __func__
);
56 ret
= layr
->up
->receive(layr
->up
, pkt
);
59 layr
->ctrlcmd(layr
, CAIF_CTRLCMD_FLOW_OFF_IND
, 0);
63 layr
->ctrlcmd(layr
, CAIF_CTRLCMD_FLOW_ON_IND
, 0);
66 case VEI_SET_PIN
: /* SET RS232 PIN */
69 default: /* SET RS232 PIN */
70 pr_warning("CAIF: %s():Unknown VEI control packet %d (0x%x)!\n",
77 static int cfvei_transmit(struct cflayer
*layr
, struct cfpkt
*pkt
)
80 struct caif_payload_info
*info
;
82 struct cfsrvl
*service
= container_obj(layr
);
83 if (!cfsrvl_ready(service
, &ret
))
85 caif_assert(layr
->dn
!= NULL
);
86 caif_assert(layr
->dn
->transmit
!= NULL
);
88 if (cfpkt_add_head(pkt
, &tmp
, 1) < 0) {
89 pr_err("CAIF: %s(): Packet is erroneous!\n", __func__
);
93 /* Add info-> for MUX-layer to route the packet out. */
94 info
= cfpkt_info(pkt
);
95 info
->channel_id
= service
->layer
.id
;
97 info
->dev_info
= &service
->dev_info
;
98 ret
= layr
->dn
->transmit(layr
->dn
, pkt
);
100 cfpkt_extr_head(pkt
, &tmp
, 1);