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/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>
14 #define container_obj(layr) ((struct cfsrvl *) layr)
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
22 static int cfdgml_receive(struct cflayer
*layr
, struct cfpkt
*pkt
);
23 static int cfdgml_transmit(struct cflayer
*layr
, struct cfpkt
*pkt
);
25 struct cflayer
*cfdgml_create(u8 channel_id
, struct dev_info
*dev_info
)
27 struct cfsrvl
*dgm
= kmalloc(sizeof(struct cfsrvl
), GFP_ATOMIC
);
29 pr_warning("CAIF: %s(): Out of memory\n", __func__
);
32 caif_assert(offsetof(struct cfsrvl
, layer
) == 0);
33 memset(dgm
, 0, sizeof(struct cfsrvl
));
34 cfsrvl_init(dgm
, channel_id
, dev_info
, true);
35 dgm
->layer
.receive
= cfdgml_receive
;
36 dgm
->layer
.transmit
= cfdgml_transmit
;
37 snprintf(dgm
->layer
.name
, CAIF_LAYER_NAME_SZ
- 1, "dgm%d", channel_id
);
38 dgm
->layer
.name
[CAIF_LAYER_NAME_SZ
- 1] = '\0';
42 static int cfdgml_receive(struct cflayer
*layr
, struct cfpkt
*pkt
)
47 caif_assert(layr
->up
!= NULL
);
48 caif_assert(layr
->receive
!= NULL
);
49 caif_assert(layr
->ctrlcmd
!= NULL
);
51 if (cfpkt_extr_head(pkt
, &cmd
, 1) < 0) {
52 pr_err("CAIF: %s(): Packet is erroneous!\n", __func__
);
57 if ((cmd
& DGM_CMD_BIT
) == 0) {
58 if (cfpkt_extr_head(pkt
, &dgmhdr
, 3) < 0) {
59 pr_err("CAIF: %s(): Packet is erroneous!\n", __func__
);
63 ret
= layr
->up
->receive(layr
->up
, pkt
);
68 case DGM_FLOW_OFF
: /* FLOW OFF */
69 layr
->ctrlcmd(layr
, CAIF_CTRLCMD_FLOW_OFF_IND
, 0);
72 case DGM_FLOW_ON
: /* FLOW ON */
73 layr
->ctrlcmd(layr
, CAIF_CTRLCMD_FLOW_ON_IND
, 0);
78 pr_info("CAIF: %s(): Unknown datagram control %d (0x%x)\n",
84 static int cfdgml_transmit(struct cflayer
*layr
, struct cfpkt
*pkt
)
87 struct caif_payload_info
*info
;
88 struct cfsrvl
*service
= container_obj(layr
);
90 if (!cfsrvl_ready(service
, &ret
))
93 /* STE Modem cannot handle more than 1500 bytes datagrams */
94 if (cfpkt_getlen(pkt
) > DGM_MTU
)
97 cfpkt_add_head(pkt
, &zero
, 4);
99 /* Add info for MUX-layer to route the packet out. */
100 info
= cfpkt_info(pkt
);
101 info
->channel_id
= service
->layer
.id
;
102 /* To optimize alignment, we add up the size of CAIF header
106 info
->dev_info
= &service
->dev_info
;
107 ret
= layr
->dn
->transmit(layr
->dn
, pkt
);
110 cfpkt_extr_head(pkt
, &tmp32
, 4);