diff options
author | Sjur Braendeland <sjur.brandeland@stericsson.com> | 2010-03-30 09:56:23 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-03-30 22:08:46 -0400 |
commit | b482cd2053e3b90a7b33a78c63cdb6badf2ec383 (patch) | |
tree | 1c05e28f19a194b52bf43730fa498dcdb0e92b59 /net/caif/cfdgml.c | |
parent | 2721c5b9dd2a56a9710021c00146bb26ba8dd7b3 (diff) |
net-caif: add CAIF core protocol stack
CAIF generic protocol implementation. This layer is
somewhat generic in order to be able to use and test it outside
the Linux Kernel.
cfctrl.c - CAIF control protocol layer
cfdbgl.c - CAIF debug protocol layer
cfdgml.c - CAIF datagram protocol layer
cffrml.c - CAIF framing protocol layer
cfmuxl.c - CAIF mux protocol layer
cfrfml.c - CAIF remote file manager protocol layer
cfserl.c - CAIF serial (fragmentation) protocol layer
cfsrvl.c - CAIF generic service layer functions
cfutill.c - CAIF utility protocol layer
cfveil.c - CAIF AT protocol layer
cfvidl.c - CAIF video protocol layer
Signed-off-by: Sjur Braendeland <sjur.brandeland@stericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/caif/cfdgml.c')
-rw-r--r-- | net/caif/cfdgml.c | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/net/caif/cfdgml.c b/net/caif/cfdgml.c new file mode 100644 index 000000000000..53194840ecb6 --- /dev/null +++ b/net/caif/cfdgml.c | |||
@@ -0,0 +1,108 @@ | |||
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/stddef.h> | ||
8 | #include <linux/spinlock.h> | ||
9 | #include <linux/slab.h> | ||
10 | #include <net/caif/caif_layer.h> | ||
11 | #include <net/caif/cfsrvl.h> | ||
12 | #include <net/caif/cfpkt.h> | ||
13 | |||
14 | #define container_obj(layr) ((struct cfsrvl *) layr) | ||
15 | |||
16 | #define DGM_CMD_BIT 0x80 | ||
17 | #define DGM_FLOW_OFF 0x81 | ||
18 | #define DGM_FLOW_ON 0x80 | ||
19 | #define DGM_CTRL_PKT_SIZE 1 | ||
20 | |||
21 | static int cfdgml_receive(struct cflayer *layr, struct cfpkt *pkt); | ||
22 | static int cfdgml_transmit(struct cflayer *layr, struct cfpkt *pkt); | ||
23 | |||
24 | struct cflayer *cfdgml_create(u8 channel_id, struct dev_info *dev_info) | ||
25 | { | ||
26 | struct cfsrvl *dgm = kmalloc(sizeof(struct cfsrvl), GFP_ATOMIC); | ||
27 | if (!dgm) { | ||
28 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
29 | return NULL; | ||
30 | } | ||
31 | caif_assert(offsetof(struct cfsrvl, layer) == 0); | ||
32 | memset(dgm, 0, sizeof(struct cfsrvl)); | ||
33 | cfsrvl_init(dgm, channel_id, dev_info); | ||
34 | dgm->layer.receive = cfdgml_receive; | ||
35 | dgm->layer.transmit = cfdgml_transmit; | ||
36 | snprintf(dgm->layer.name, CAIF_LAYER_NAME_SZ - 1, "dgm%d", channel_id); | ||
37 | dgm->layer.name[CAIF_LAYER_NAME_SZ - 1] = '\0'; | ||
38 | return &dgm->layer; | ||
39 | } | ||
40 | |||
41 | static int cfdgml_receive(struct cflayer *layr, struct cfpkt *pkt) | ||
42 | { | ||
43 | u8 cmd = -1; | ||
44 | u8 dgmhdr[3]; | ||
45 | int ret; | ||
46 | caif_assert(layr->up != NULL); | ||
47 | caif_assert(layr->receive != NULL); | ||
48 | caif_assert(layr->ctrlcmd != NULL); | ||
49 | |||
50 | if (cfpkt_extr_head(pkt, &cmd, 1) < 0) { | ||
51 | pr_err("CAIF: %s(): Packet is erroneous!\n", __func__); | ||
52 | cfpkt_destroy(pkt); | ||
53 | return -EPROTO; | ||
54 | } | ||
55 | |||
56 | if ((cmd & DGM_CMD_BIT) == 0) { | ||
57 | if (cfpkt_extr_head(pkt, &dgmhdr, 3) < 0) { | ||
58 | pr_err("CAIF: %s(): Packet is erroneous!\n", __func__); | ||
59 | cfpkt_destroy(pkt); | ||
60 | return -EPROTO; | ||
61 | } | ||
62 | ret = layr->up->receive(layr->up, pkt); | ||
63 | return ret; | ||
64 | } | ||
65 | |||
66 | switch (cmd) { | ||
67 | case DGM_FLOW_OFF: /* FLOW OFF */ | ||
68 | layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_OFF_IND, 0); | ||
69 | cfpkt_destroy(pkt); | ||
70 | return 0; | ||
71 | case DGM_FLOW_ON: /* FLOW ON */ | ||
72 | layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_ON_IND, 0); | ||
73 | cfpkt_destroy(pkt); | ||
74 | return 0; | ||
75 | default: | ||
76 | cfpkt_destroy(pkt); | ||
77 | pr_info("CAIF: %s(): Unknown datagram control %d (0x%x)\n", | ||
78 | __func__, cmd, cmd); | ||
79 | return -EPROTO; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | static int cfdgml_transmit(struct cflayer *layr, struct cfpkt *pkt) | ||
84 | { | ||
85 | u32 zero = 0; | ||
86 | struct caif_payload_info *info; | ||
87 | struct cfsrvl *service = container_obj(layr); | ||
88 | int ret; | ||
89 | if (!cfsrvl_ready(service, &ret)) | ||
90 | return ret; | ||
91 | |||
92 | cfpkt_add_head(pkt, &zero, 4); | ||
93 | |||
94 | /* Add info for MUX-layer to route the packet out. */ | ||
95 | info = cfpkt_info(pkt); | ||
96 | info->channel_id = service->layer.id; | ||
97 | /* To optimize alignment, we add up the size of CAIF header | ||
98 | * before payload. | ||
99 | */ | ||
100 | info->hdr_len = 4; | ||
101 | info->dev_info = &service->dev_info; | ||
102 | ret = layr->dn->transmit(layr->dn, pkt); | ||
103 | if (ret < 0) { | ||
104 | u32 tmp32; | ||
105 | cfpkt_extr_head(pkt, &tmp32, 4); | ||
106 | } | ||
107 | return ret; | ||
108 | } | ||