cfdgml.c (daab7fc734a53fdeaf844b7c03053118ad1769da) cfdgml.c (b31fa5bad576cd8180a5ad70c648333b44320d44)
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
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#define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
8
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)

--- 6 unchanged lines hidden (view full) ---

21
22static int cfdgml_receive(struct cflayer *layr, struct cfpkt *pkt);
23static int cfdgml_transmit(struct cflayer *layr, struct cfpkt *pkt);
24
25struct cflayer *cfdgml_create(u8 channel_id, struct dev_info *dev_info)
26{
27 struct cfsrvl *dgm = kmalloc(sizeof(struct cfsrvl), GFP_ATOMIC);
28 if (!dgm) {
9#include <linux/stddef.h>
10#include <linux/spinlock.h>
11#include <linux/slab.h>
12#include <net/caif/caif_layer.h>
13#include <net/caif/cfsrvl.h>
14#include <net/caif/cfpkt.h>
15
16#define container_obj(layr) ((struct cfsrvl *) layr)

--- 6 unchanged lines hidden (view full) ---

23
24static int cfdgml_receive(struct cflayer *layr, struct cfpkt *pkt);
25static int cfdgml_transmit(struct cflayer *layr, struct cfpkt *pkt);
26
27struct cflayer *cfdgml_create(u8 channel_id, struct dev_info *dev_info)
28{
29 struct cfsrvl *dgm = kmalloc(sizeof(struct cfsrvl), GFP_ATOMIC);
30 if (!dgm) {
29 pr_warning("CAIF: %s(): Out of memory\n", __func__);
31 pr_warn("Out of memory\n");
30 return NULL;
31 }
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);

--- 6 unchanged lines hidden (view full) ---

44 u8 cmd = -1;
45 u8 dgmhdr[3];
46 int ret;
47 caif_assert(layr->up != NULL);
48 caif_assert(layr->receive != NULL);
49 caif_assert(layr->ctrlcmd != NULL);
50
51 if (cfpkt_extr_head(pkt, &cmd, 1) < 0) {
32 return NULL;
33 }
34 caif_assert(offsetof(struct cfsrvl, layer) == 0);
35 memset(dgm, 0, sizeof(struct cfsrvl));
36 cfsrvl_init(dgm, channel_id, dev_info, true);
37 dgm->layer.receive = cfdgml_receive;
38 dgm->layer.transmit = cfdgml_transmit;
39 snprintf(dgm->layer.name, CAIF_LAYER_NAME_SZ - 1, "dgm%d", channel_id);

--- 6 unchanged lines hidden (view full) ---

46 u8 cmd = -1;
47 u8 dgmhdr[3];
48 int ret;
49 caif_assert(layr->up != NULL);
50 caif_assert(layr->receive != NULL);
51 caif_assert(layr->ctrlcmd != NULL);
52
53 if (cfpkt_extr_head(pkt, &cmd, 1) < 0) {
52 pr_err("CAIF: %s(): Packet is erroneous!\n", __func__);
54 pr_err("Packet is erroneous!\n");
53 cfpkt_destroy(pkt);
54 return -EPROTO;
55 }
56
57 if ((cmd & DGM_CMD_BIT) == 0) {
58 if (cfpkt_extr_head(pkt, &dgmhdr, 3) < 0) {
55 cfpkt_destroy(pkt);
56 return -EPROTO;
57 }
58
59 if ((cmd & DGM_CMD_BIT) == 0) {
60 if (cfpkt_extr_head(pkt, &dgmhdr, 3) < 0) {
59 pr_err("CAIF: %s(): Packet is erroneous!\n", __func__);
61 pr_err("Packet is erroneous!\n");
60 cfpkt_destroy(pkt);
61 return -EPROTO;
62 }
63 ret = layr->up->receive(layr->up, pkt);
64 return ret;
65 }
66
67 switch (cmd) {
68 case DGM_FLOW_OFF: /* FLOW OFF */
69 layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_OFF_IND, 0);
70 cfpkt_destroy(pkt);
71 return 0;
72 case DGM_FLOW_ON: /* FLOW ON */
73 layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_ON_IND, 0);
74 cfpkt_destroy(pkt);
75 return 0;
76 default:
77 cfpkt_destroy(pkt);
62 cfpkt_destroy(pkt);
63 return -EPROTO;
64 }
65 ret = layr->up->receive(layr->up, pkt);
66 return ret;
67 }
68
69 switch (cmd) {
70 case DGM_FLOW_OFF: /* FLOW OFF */
71 layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_OFF_IND, 0);
72 cfpkt_destroy(pkt);
73 return 0;
74 case DGM_FLOW_ON: /* FLOW ON */
75 layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_ON_IND, 0);
76 cfpkt_destroy(pkt);
77 return 0;
78 default:
79 cfpkt_destroy(pkt);
78 pr_info("CAIF: %s(): Unknown datagram control %d (0x%x)\n",
79 __func__, cmd, cmd);
80 pr_info("Unknown datagram control %d (0x%x)\n", cmd, cmd);
80 return -EPROTO;
81 }
82}
83
84static int cfdgml_transmit(struct cflayer *layr, struct cfpkt *pkt)
85{
86 u32 zero = 0;
87 struct caif_payload_info *info;

--- 26 unchanged lines hidden ---
81 return -EPROTO;
82 }
83}
84
85static int cfdgml_transmit(struct cflayer *layr, struct cfpkt *pkt)
86{
87 u32 zero = 0;
88 struct caif_payload_info *info;

--- 26 unchanged lines hidden ---