1Linux CAIF 2=========== 3copyright (C) ST-Ericsson AB 2010 4Author: Sjur Brendeland/ sjur.brandeland@stericsson.com 5License terms: GNU General Public License (GPL) version 2 6 7 8Introduction 9------------ 10CAIF is a MUX protocol used by ST-Ericsson cellular modems for 11communication between Modem and host. The host processes can open virtual AT 12channels, initiate GPRS Data connections, Video channels and Utility Channels. 13The Utility Channels are general purpose pipes between modem and host. 14 15ST-Ericsson modems support a number of transports between modem 16and host. Currently, UART and Loopback are available for Linux. 17 18 19Architecture: 20------------ 21The implementation of CAIF is divided into: 22* CAIF Socket Layer, Kernel API, and Net Device. 23* CAIF Core Protocol Implementation 24* CAIF Link Layer, implemented as NET devices. 25 26 27 RTNL 28 ! 29 ! +------+ +------+ +------+ 30 ! +------+! +------+! +------+! 31 ! ! Sock !! !Kernel!! ! Net !! 32 ! ! API !+ ! API !+ ! Dev !+ <- CAIF Client APIs 33 ! +------+ +------! +------+ 34 ! ! ! ! 35 ! +----------!----------+ 36 ! +------+ <- CAIF Protocol Implementation 37 +-------> ! CAIF ! 38 ! Core ! 39 +------+ 40 +--------!--------+ 41 ! ! 42 +------+ +-----+ 43 ! ! ! TTY ! <- Link Layer (Net Devices) 44 +------+ +-----+ 45 46 47Using the Kernel API 48---------------------- 49The Kernel API is used for accessing CAIF channels from the 50kernel. 51The user of the API has to implement two callbacks for receive 52and control. 53The receive callback gives a CAIF packet as a SKB. The control 54callback will 55notify of channel initialization complete, and flow-on/flow- 56off. 57 58 59 struct caif_device caif_dev = { 60 .caif_config = { 61 .name = "MYDEV" 62 .type = CAIF_CHTY_AT 63 } 64 .receive_cb = my_receive, 65 .control_cb = my_control, 66 }; 67 caif_add_device(&caif_dev); 68 caif_transmit(&caif_dev, skb); 69 70See the caif_kernel.h for details about the CAIF kernel API. 71 72 73I M P L E M E N T A T I O N 74=========================== 75=========================== 76 77CAIF Core Protocol Layer 78========================================= 79 80CAIF Core layer implements the CAIF protocol as defined by ST-Ericsson. 81It implements the CAIF protocol stack in a layered approach, where 82each layer described in the specification is implemented as a separate layer. 83The architecture is inspired by the design patterns "Protocol Layer" and 84"Protocol Packet". 85 86== CAIF structure == 87The Core CAIF implementation contains: 88 - Simple implementation of CAIF. 89 - Layered architecture (a la Streams), each layer in the CAIF 90 specification is implemented in a separate c-file. 91 - Clients must implement PHY layer to access physical HW 92 with receive and transmit functions. 93 - Clients must call configuration function to add PHY layer. 94 - Clients must implement CAIF layer to consume/produce 95 CAIF payload with receive and transmit functions. 96 - Clients must call configuration function to add and connect the 97 Client layer. 98 - When receiving / transmitting CAIF Packets (cfpkt), ownership is passed 99 to the called function (except for framing layers' receive functions 100 or if a transmit function returns an error, in which case the caller 101 must free the packet). 102 103Layered Architecture 104-------------------- 105The CAIF protocol can be divided into two parts: Support functions and Protocol 106Implementation. The support functions include: 107 108 - CFPKT CAIF Packet. Implementation of CAIF Protocol Packet. The 109 CAIF Packet has functions for creating, destroying and adding content 110 and for adding/extracting header and trailers to protocol packets. 111 112 - CFLST CAIF list implementation. 113 114 - CFGLUE CAIF Glue. Contains OS Specifics, such as memory 115 allocation, endianness, etc. 116 117The CAIF Protocol implementation contains: 118 119 - CFCNFG CAIF Configuration layer. Configures the CAIF Protocol 120 Stack and provides a Client interface for adding Link-Layer and 121 Driver interfaces on top of the CAIF Stack. 122 123 - CFCTRL CAIF Control layer. Encodes and Decodes control messages 124 such as enumeration and channel setup. Also matches request and 125 response messages. 126 127 - CFSERVL General CAIF Service Layer functionality; handles flow 128 control and remote shutdown requests. 129 130 - CFVEI CAIF VEI layer. Handles CAIF AT Channels on VEI (Virtual 131 External Interface). This layer encodes/decodes VEI frames. 132 133 - CFDGML CAIF Datagram layer. Handles CAIF Datagram layer (IP 134 traffic), encodes/decodes Datagram frames. 135 136 - CFMUX CAIF Mux layer. Handles multiplexing between multiple 137 physical bearers and multiple channels such as VEI, Datagram, etc. 138 The MUX keeps track of the existing CAIF Channels and 139 Physical Instances and selects the appropriate instance based 140 on Channel-Id and Physical-ID. 141 142 - CFFRML CAIF Framing layer. Handles Framing i.e. Frame length 143 and frame checksum. 144 145 - CFSERL CAIF Serial layer. Handles concatenation/split of frames 146 into CAIF Frames with correct length. 147 148 149 150 +---------+ 151 | Config | 152 | CFCNFG | 153 +---------+ 154 ! 155 +---------+ +---------+ +---------+ 156 | AT | | Control | | Datagram| 157 | CFVEIL | | CFCTRL | | CFDGML | 158 +---------+ +---------+ +---------+ 159 \_____________!______________/ 160 ! 161 +---------+ 162 | MUX | 163 | | 164 +---------+ 165 _____!_____ 166 / \ 167 +---------+ +---------+ 168 | CFFRML | | CFFRML | 169 | Framing | | Framing | 170 +---------+ +---------+ 171 ! ! 172 +---------+ +---------+ 173 | | | Serial | 174 | | | CFSERL | 175 +---------+ +---------+ 176 177 178In this layered approach the following "rules" apply. 179 - All layers embed the same structure "struct cflayer" 180 - A layer does not depend on any other layer's private data. 181 - Layers are stacked by setting the pointers 182 layer->up , layer->dn 183 - In order to send data upwards, each layer should do 184 layer->up->receive(layer->up, packet); 185 - In order to send data downwards, each layer should do 186 layer->dn->transmit(layer->dn, packet); 187 188 189Linux Driver Implementation 190=========================== 191 192Linux GPRS Net Device and CAIF socket are implemented on top of the 193CAIF Core protocol. The Net device and CAIF socket have an instance of 194'struct cflayer', just like the CAIF Core protocol stack. 195Net device and Socket implement the 'receive()' function defined by 196'struct cflayer', just like the rest of the CAIF stack. In this way, transmit and 197receive of packets is handled as by the rest of the layers: the 'dn->transmit()' 198function is called in order to transmit data. 199 200The layer on top of the CAIF Core implementation is 201sometimes referred to as the "Client layer". 202 203 204Configuration of Link Layer 205--------------------------- 206The Link Layer is implemented as Linux net devices (struct net_device). 207Payload handling and registration is done using standard Linux mechanisms. 208 209The CAIF Protocol relies on a loss-less link layer without implementing 210retransmission. This implies that packet drops must not happen. 211Therefore a flow-control mechanism is implemented where the physical 212interface can initiate flow stop for all CAIF Channels. 213