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 #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
9 #include <linux/stddef.h>
10 #include <linux/slab.h>
11 #include <net/caif/caif_layer.h>
12 #include <net/caif/cfsrvl.h>
13 #include <net/caif/cfpkt.h>
15 #define VEI_PAYLOAD 0x00
16 #define VEI_CMD_BIT 0x80
17 #define VEI_FLOW_OFF 0x81
18 #define VEI_FLOW_ON 0x80
19 #define VEI_SET_PIN 0x82
21 #define container_obj(layr) container_of(layr, struct cfsrvl, layer)
23 static int cfvei_receive(struct cflayer *layr, struct cfpkt *pkt);
24 static int cfvei_transmit(struct cflayer *layr, struct cfpkt *pkt);
26 struct cflayer *cfvei_create(u8 channel_id, struct dev_info *dev_info)
28 struct cfsrvl *vei = kzalloc(sizeof(struct cfsrvl), GFP_ATOMIC);
31 caif_assert(offsetof(struct cfsrvl, layer) == 0);
32 cfsrvl_init(vei, channel_id, dev_info, true);
33 vei->layer.receive = cfvei_receive;
34 vei->layer.transmit = cfvei_transmit;
35 snprintf(vei->layer.name, CAIF_LAYER_NAME_SZ - 1, "vei%d", channel_id);
39 static int cfvei_receive(struct cflayer *layr, struct cfpkt *pkt)
43 caif_assert(layr->up != NULL);
44 caif_assert(layr->receive != NULL);
45 caif_assert(layr->ctrlcmd != NULL);
48 if (cfpkt_extr_head(pkt, &cmd, 1) < 0) {
49 pr_err("Packet is erroneous!\n");
55 ret = layr->up->receive(layr->up, pkt);
58 layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_OFF_IND, 0);
62 layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_ON_IND, 0);
65 case VEI_SET_PIN: /* SET RS232 PIN */
68 default: /* SET RS232 PIN */
69 pr_warn("Unknown VEI control packet %d (0x%x)!\n", cmd, cmd);
75 static int cfvei_transmit(struct cflayer *layr, struct cfpkt *pkt)
78 struct caif_payload_info *info;
80 struct cfsrvl *service = container_obj(layr);
81 if (!cfsrvl_ready(service, &ret))
83 caif_assert(layr->dn != NULL);
84 caif_assert(layr->dn->transmit != NULL);
86 if (cfpkt_add_head(pkt, &tmp, 1) < 0) {
87 pr_err("Packet is erroneous!\n");
92 /* Add info-> for MUX-layer to route the packet out. */
93 info = cfpkt_info(pkt);
94 info->channel_id = service->layer.id;
96 info->dev_info = &service->dev_info;
97 return layr->dn->transmit(layr->dn, pkt);