~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/caif/cfdgml.c

Version: ~ [ linux-5.3 ] ~ [ linux-5.2.15 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.73 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.144 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.193 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.193 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.73 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright (C) ST-Ericsson AB 2010
  3  * Author:      Sjur Brendeland
  4  * License terms: GNU General Public License (GPL) version 2
  5  */
  6 
  7 #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
  8 
  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 
 17 #define container_obj(layr) ((struct cfsrvl *) layr)
 18 
 19 #define DGM_CMD_BIT  0x80
 20 #define DGM_FLOW_OFF 0x81
 21 #define DGM_FLOW_ON  0x80
 22 #define DGM_MTU 1500
 23 
 24 static int cfdgml_receive(struct cflayer *layr, struct cfpkt *pkt);
 25 static int cfdgml_transmit(struct cflayer *layr, struct cfpkt *pkt);
 26 
 27 struct cflayer *cfdgml_create(u8 channel_id, struct dev_info *dev_info)
 28 {
 29         struct cfsrvl *dgm = kzalloc(sizeof(struct cfsrvl), GFP_ATOMIC);
 30         if (!dgm)
 31                 return NULL;
 32         caif_assert(offsetof(struct cfsrvl, layer) == 0);
 33         cfsrvl_init(dgm, channel_id, dev_info, true);
 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("Packet is erroneous!\n");
 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("Packet is erroneous!\n");
 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("Unknown datagram control %d (0x%x)\n", cmd, cmd);
 78                 return -EPROTO;
 79         }
 80 }
 81 
 82 static int cfdgml_transmit(struct cflayer *layr, struct cfpkt *pkt)
 83 {
 84         u8 packet_type;
 85         u32 zero = 0;
 86         struct caif_payload_info *info;
 87         struct cfsrvl *service = container_obj(layr);
 88         int ret;
 89 
 90         if (!cfsrvl_ready(service, &ret)) {
 91                 cfpkt_destroy(pkt);
 92                 return ret;
 93         }
 94 
 95         /* STE Modem cannot handle more than 1500 bytes datagrams */
 96         if (cfpkt_getlen(pkt) > DGM_MTU) {
 97                 cfpkt_destroy(pkt);
 98                 return -EMSGSIZE;
 99         }
100 
101         cfpkt_add_head(pkt, &zero, 3);
102         packet_type = 0x08; /* B9 set - UNCLASSIFIED */
103         cfpkt_add_head(pkt, &packet_type, 1);
104 
105         /* Add info for MUX-layer to route the packet out. */
106         info = cfpkt_info(pkt);
107         info->channel_id = service->layer.id;
108         /* To optimize alignment, we add up the size of CAIF header
109          * before payload.
110          */
111         info->hdr_len = 4;
112         info->dev_info = &service->dev_info;
113         return layr->dn->transmit(layr->dn, pkt);
114 }
115 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp