blob: 262224581efafd87ed89af723f1fa91046f1aa15 [file] [log] [blame]
Sjur Braendelandb482cd22010-03-30 13:56:23 +00001/*
2 * Copyright (C) ST-Ericsson AB 2010
sjur.brandeland@stericsson.com26ee65e2013-04-22 23:57:01 +00003 * Author: Sjur Brendeland
Sjur Braendelandb482cd22010-03-30 13:56:23 +00004 * License terms: GNU General Public License (GPL) version 2
5 */
6
Joe Perchesb31fa5b2010-09-05 21:31:11 +00007#define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
8
Sjur Braendelandb482cd22010-03-30 13:56:23 +00009#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>
14
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
Shan Wei441c7932011-01-13 22:19:52 +000020
Sjur Braendelandb482cd22010-03-30 13:56:23 +000021#define container_obj(layr) container_of(layr, struct cfsrvl, layer)
22
23static int cfvei_receive(struct cflayer *layr, struct cfpkt *pkt);
24static int cfvei_transmit(struct cflayer *layr, struct cfpkt *pkt);
25
26struct cflayer *cfvei_create(u8 channel_id, struct dev_info *dev_info)
27{
Joe Perches7ac2ed02011-08-25 13:22:24 +000028 struct cfsrvl *vei = kzalloc(sizeof(struct cfsrvl), GFP_ATOMIC);
29 if (!vei)
Sjur Braendelandb482cd22010-03-30 13:56:23 +000030 return NULL;
Sjur Braendelandb482cd22010-03-30 13:56:23 +000031 caif_assert(offsetof(struct cfsrvl, layer) == 0);
Sjur Braendelandb1c74242010-06-17 06:55:38 +000032 cfsrvl_init(vei, channel_id, dev_info, true);
Sjur Braendelandb482cd22010-03-30 13:56:23 +000033 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);
36 return &vei->layer;
37}
38
39static int cfvei_receive(struct cflayer *layr, struct cfpkt *pkt)
40{
41 u8 cmd;
42 int ret;
43 caif_assert(layr->up != NULL);
44 caif_assert(layr->receive != NULL);
45 caif_assert(layr->ctrlcmd != NULL);
46
47
48 if (cfpkt_extr_head(pkt, &cmd, 1) < 0) {
Joe Perchesb31fa5b2010-09-05 21:31:11 +000049 pr_err("Packet is erroneous!\n");
Sjur Braendelandb482cd22010-03-30 13:56:23 +000050 cfpkt_destroy(pkt);
51 return -EPROTO;
52 }
53 switch (cmd) {
54 case VEI_PAYLOAD:
55 ret = layr->up->receive(layr->up, pkt);
56 return ret;
57 case VEI_FLOW_OFF:
58 layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_OFF_IND, 0);
59 cfpkt_destroy(pkt);
60 return 0;
61 case VEI_FLOW_ON:
62 layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_ON_IND, 0);
63 cfpkt_destroy(pkt);
64 return 0;
65 case VEI_SET_PIN: /* SET RS232 PIN */
66 cfpkt_destroy(pkt);
67 return 0;
68 default: /* SET RS232 PIN */
Joe Perchesb31fa5b2010-09-05 21:31:11 +000069 pr_warn("Unknown VEI control packet %d (0x%x)!\n", cmd, cmd);
Sjur Braendelandb482cd22010-03-30 13:56:23 +000070 cfpkt_destroy(pkt);
71 return -EPROTO;
72 }
73}
74
75static int cfvei_transmit(struct cflayer *layr, struct cfpkt *pkt)
76{
77 u8 tmp = 0;
78 struct caif_payload_info *info;
79 int ret;
80 struct cfsrvl *service = container_obj(layr);
81 if (!cfsrvl_ready(service, &ret))
sjur.brandeland@stericsson.comc85c2952011-05-13 02:44:06 +000082 goto err;
Sjur Braendelandb482cd22010-03-30 13:56:23 +000083 caif_assert(layr->dn != NULL);
84 caif_assert(layr->dn->transmit != NULL);
Sjur Braendelandb482cd22010-03-30 13:56:23 +000085
86 if (cfpkt_add_head(pkt, &tmp, 1) < 0) {
Joe Perchesb31fa5b2010-09-05 21:31:11 +000087 pr_err("Packet is erroneous!\n");
sjur.brandeland@stericsson.comc85c2952011-05-13 02:44:06 +000088 ret = -EPROTO;
89 goto err;
Sjur Braendelandb482cd22010-03-30 13:56:23 +000090 }
91
92 /* Add info-> for MUX-layer to route the packet out. */
93 info = cfpkt_info(pkt);
94 info->channel_id = service->layer.id;
95 info->hdr_len = 1;
96 info->dev_info = &service->dev_info;
Sjur Brændeland4dd820c2011-04-11 10:43:51 +000097 return layr->dn->transmit(layr->dn, pkt);
sjur.brandeland@stericsson.comc85c2952011-05-13 02:44:06 +000098err:
99 cfpkt_destroy(pkt);
100 return ret;
Sjur Braendelandb482cd22010-03-30 13:56:23 +0000101}