Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * CAPI encoder/decoder for |
| 3 | * Portugal Telecom CAPI 2.0 |
| 4 | * |
| 5 | * Copyright (C) 1996 Universidade de Lisboa |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Written by Pedro Roque Marques (roque@di.fc.ul.pt) |
| 8 | * |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 9 | * This software may be used and distributed according to the terms of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * the GNU General Public License, incorporated herein by reference. |
| 11 | * |
| 12 | * Not compatible with the AVM Gmbh. CAPI 2.0 |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * Documentation: |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 18 | * - "Common ISDN API - Perfil Português - Versão 2.1", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * Telecom Portugal, Fev 1992. |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 20 | * - "Common ISDN API - Especificação de protocolos para |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | * acesso aos canais B", Inesc, Jan 1994. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * TODO: better decoding of Information Elements |
| 26 | * for debug purposes mainly |
| 27 | * encode our number in CallerPN and ConnectedPN |
| 28 | */ |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/string.h> |
| 31 | #include <linux/kernel.h> |
| 32 | |
| 33 | #include <linux/types.h> |
| 34 | #include <linux/slab.h> |
| 35 | #include <linux/mm.h> |
| 36 | |
| 37 | #include <linux/skbuff.h> |
| 38 | |
| 39 | #include <asm/io.h> |
| 40 | #include <asm/string.h> |
| 41 | |
| 42 | #include <linux/isdnif.h> |
| 43 | |
| 44 | #include "pcbit.h" |
| 45 | #include "edss1.h" |
| 46 | #include "capi.h" |
| 47 | |
| 48 | |
| 49 | /* |
| 50 | * Encoding of CAPI messages |
| 51 | * |
| 52 | */ |
| 53 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 54 | int capi_conn_req(const char *calledPN, struct sk_buff **skb, int proto) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 56 | ushort len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 58 | /* |
| 59 | * length |
| 60 | * AppInfoMask - 2 |
| 61 | * BC0 - 3 |
| 62 | * BC1 - 1 |
| 63 | * Chan - 2 |
| 64 | * Keypad - 1 |
| 65 | * CPN - 1 |
| 66 | * CPSA - 1 |
| 67 | * CalledPN - 2 + strlen |
| 68 | * CalledPSA - 1 |
| 69 | * rest... - 4 |
| 70 | * ---------------- |
| 71 | * Total 18 + strlen |
| 72 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 74 | len = 18 + strlen(calledPN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | if (proto == ISDN_PROTO_L2_TRANS) |
| 77 | len++; |
| 78 | |
| 79 | if ((*skb = dev_alloc_skb(len)) == NULL) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 80 | |
| 81 | printk(KERN_WARNING "capi_conn_req: alloc_skb failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | return -1; |
| 83 | } |
| 84 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 85 | /* InfoElmMask */ |
| 86 | *((ushort *)skb_put(*skb, 2)) = AppInfoMask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | if (proto == ISDN_PROTO_L2_TRANS) |
| 89 | { |
| 90 | /* Bearer Capability - Mandatory*/ |
| 91 | *(skb_put(*skb, 1)) = 3; /* BC0.Length */ |
| 92 | *(skb_put(*skb, 1)) = 0x80; /* Speech */ |
| 93 | *(skb_put(*skb, 1)) = 0x10; /* Circuit Mode */ |
| 94 | *(skb_put(*skb, 1)) = 0x23; /* A-law */ |
Anthony Sheldon | aec8755 | 2016-08-19 16:42:13 +0100 | [diff] [blame] | 95 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | /* Bearer Capability - Mandatory*/ |
| 97 | *(skb_put(*skb, 1)) = 2; /* BC0.Length */ |
| 98 | *(skb_put(*skb, 1)) = 0x88; /* Digital Information */ |
| 99 | *(skb_put(*skb, 1)) = 0x90; /* BC0.Octect4 */ |
| 100 | } |
| 101 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 102 | /* Bearer Capability - Optional*/ |
| 103 | *(skb_put(*skb, 1)) = 0; /* BC1.Length = 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 105 | *(skb_put(*skb, 1)) = 1; /* ChannelID.Length = 1 */ |
| 106 | *(skb_put(*skb, 1)) = 0x83; /* Basic Interface - Any Channel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 108 | *(skb_put(*skb, 1)) = 0; /* Keypad.Length = 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 111 | *(skb_put(*skb, 1)) = 0; /* CallingPN.Length = 0 */ |
| 112 | *(skb_put(*skb, 1)) = 0; /* CallingPSA.Length = 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 114 | /* Called Party Number */ |
| 115 | *(skb_put(*skb, 1)) = strlen(calledPN) + 1; |
| 116 | *(skb_put(*skb, 1)) = 0x81; |
| 117 | memcpy(skb_put(*skb, strlen(calledPN)), calledPN, strlen(calledPN)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 119 | /* '#' */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 121 | *(skb_put(*skb, 1)) = 0; /* CalledPSA.Length = 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 123 | /* LLC.Length = 0; */ |
| 124 | /* HLC0.Length = 0; */ |
| 125 | /* HLC1.Length = 0; */ |
| 126 | /* UTUS.Length = 0; */ |
| 127 | memset(skb_put(*skb, 4), 0, 4); |
| 128 | |
| 129 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 132 | int capi_conn_resp(struct pcbit_chan *chan, struct sk_buff **skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | if ((*skb = dev_alloc_skb(5)) == NULL) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | printk(KERN_WARNING "capi_conn_resp: alloc_skb failed\n"); |
| 138 | return -1; |
| 139 | } |
| 140 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 141 | *((ushort *)skb_put(*skb, 2)) = chan->callref; |
| 142 | *(skb_put(*skb, 1)) = 0x01; /* ACCEPT_CALL */ |
| 143 | *(skb_put(*skb, 1)) = 0; |
| 144 | *(skb_put(*skb, 1)) = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 146 | return 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 149 | int capi_conn_active_req(struct pcbit_chan *chan, struct sk_buff **skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 151 | /* |
| 152 | * 8 bytes |
| 153 | */ |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | if ((*skb = dev_alloc_skb(8)) == NULL) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | printk(KERN_WARNING "capi_conn_active_req: alloc_skb failed\n"); |
| 158 | return -1; |
| 159 | } |
| 160 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 161 | *((ushort *)skb_put(*skb, 2)) = chan->callref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | #ifdef DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 164 | printk(KERN_DEBUG "Call Reference: %04x\n", chan->callref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | #endif |
| 166 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 167 | *(skb_put(*skb, 1)) = 0; /* BC.Length = 0; */ |
| 168 | *(skb_put(*skb, 1)) = 0; /* ConnectedPN.Length = 0 */ |
| 169 | *(skb_put(*skb, 1)) = 0; /* PSA.Length */ |
| 170 | *(skb_put(*skb, 1)) = 0; /* LLC.Length = 0; */ |
| 171 | *(skb_put(*skb, 1)) = 0; /* HLC.Length = 0; */ |
| 172 | *(skb_put(*skb, 1)) = 0; /* UTUS.Length = 0; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
| 174 | return 8; |
| 175 | } |
| 176 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 177 | int capi_conn_active_resp(struct pcbit_chan *chan, struct sk_buff **skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 179 | /* |
| 180 | * 2 bytes |
| 181 | */ |
| 182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | if ((*skb = dev_alloc_skb(2)) == NULL) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | printk(KERN_WARNING "capi_conn_active_resp: alloc_skb failed\n"); |
| 186 | return -1; |
| 187 | } |
| 188 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 189 | *((ushort *)skb_put(*skb, 2)) = chan->callref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 191 | return 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 195 | int capi_select_proto_req(struct pcbit_chan *chan, struct sk_buff **skb, |
| 196 | int outgoing) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
| 198 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 199 | /* |
| 200 | * 18 bytes |
| 201 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | if ((*skb = dev_alloc_skb(18)) == NULL) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | printk(KERN_WARNING "capi_select_proto_req: alloc_skb failed\n"); |
| 206 | return -1; |
| 207 | } |
| 208 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 209 | *((ushort *)skb_put(*skb, 2)) = chan->callref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 211 | /* Layer2 protocol */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 213 | switch (chan->proto) { |
| 214 | case ISDN_PROTO_L2_X75I: |
| 215 | *(skb_put(*skb, 1)) = 0x05; /* LAPB */ |
| 216 | break; |
| 217 | case ISDN_PROTO_L2_HDLC: |
| 218 | *(skb_put(*skb, 1)) = 0x02; |
| 219 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | case ISDN_PROTO_L2_TRANS: |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 221 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | * Voice (a-law) |
| 223 | */ |
| 224 | *(skb_put(*skb, 1)) = 0x06; |
| 225 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 226 | default: |
| 227 | #ifdef DEBUG |
| 228 | printk(KERN_DEBUG "Transparent\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 230 | *(skb_put(*skb, 1)) = 0x03; |
| 231 | break; |
| 232 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 234 | *(skb_put(*skb, 1)) = (outgoing ? 0x02 : 0x42); /* Don't ask */ |
| 235 | *(skb_put(*skb, 1)) = 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 237 | *((ushort *) skb_put(*skb, 2)) = MRU; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 240 | *(skb_put(*skb, 1)) = 0x08; /* Modulo */ |
| 241 | *(skb_put(*skb, 1)) = 0x07; /* Max Window */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 243 | *(skb_put(*skb, 1)) = 0x01; /* No Layer3 Protocol */ |
| 244 | |
| 245 | /* |
| 246 | * 2 - layer3 MTU [10] |
| 247 | * - Modulo [12] |
| 248 | * - Window |
| 249 | * - layer1 proto [14] |
| 250 | * - bitrate |
| 251 | * - sub-channel [16] |
| 252 | * - layer1dataformat [17] |
| 253 | */ |
| 254 | |
| 255 | memset(skb_put(*skb, 8), 0, 8); |
| 256 | |
| 257 | return 18; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | |
| 261 | int capi_activate_transp_req(struct pcbit_chan *chan, struct sk_buff **skb) |
| 262 | { |
| 263 | |
| 264 | if ((*skb = dev_alloc_skb(7)) == NULL) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | printk(KERN_WARNING "capi_activate_transp_req: alloc_skb failed\n"); |
| 267 | return -1; |
| 268 | } |
| 269 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 270 | *((ushort *)skb_put(*skb, 2)) = chan->callref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 273 | *(skb_put(*skb, 1)) = chan->layer2link; /* Layer2 id */ |
| 274 | *(skb_put(*skb, 1)) = 0x00; /* Transmit by default */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 276 | *((ushort *) skb_put(*skb, 2)) = MRU; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 278 | *(skb_put(*skb, 1)) = 0x01; /* Enables reception*/ |
| 279 | |
| 280 | return 7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 283 | int capi_tdata_req(struct pcbit_chan *chan, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
| 285 | ushort data_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 287 | |
| 288 | /* |
| 289 | * callref - 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | * layer2link - 1 |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 291 | * wBlockLength - 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | * data - 4 |
| 293 | * sernum - 1 |
| 294 | */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | data_len = skb->len; |
| 297 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 298 | if (skb_headroom(skb) < 10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | { |
| 300 | printk(KERN_CRIT "No headspace (%u) on headroom %p for capi header\n", skb_headroom(skb), skb); |
| 301 | } |
| 302 | else |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 303 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | skb_push(skb, 10); |
| 305 | } |
| 306 | |
| 307 | *((u16 *) (skb->data)) = chan->callref; |
| 308 | skb->data[2] = chan->layer2link; |
| 309 | *((u16 *) (skb->data + 3)) = data_len; |
| 310 | |
| 311 | chan->s_refnum = (chan->s_refnum + 1) % 8; |
| 312 | *((u32 *) (skb->data + 5)) = chan->s_refnum; |
| 313 | |
| 314 | skb->data[9] = 0; /* HDLC frame number */ |
| 315 | |
| 316 | return 10; |
| 317 | } |
| 318 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 319 | int capi_tdata_resp(struct pcbit_chan *chan, struct sk_buff **skb) |
| 320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | { |
| 322 | if ((*skb = dev_alloc_skb(4)) == NULL) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | printk(KERN_WARNING "capi_tdata_resp: alloc_skb failed\n"); |
| 325 | return -1; |
| 326 | } |
| 327 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 328 | *((ushort *)skb_put(*skb, 2)) = chan->callref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 330 | *(skb_put(*skb, 1)) = chan->layer2link; |
| 331 | *(skb_put(*skb, 1)) = chan->r_refnum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 333 | return (*skb)->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | int capi_disc_req(ushort callref, struct sk_buff **skb, u_char cause) |
| 337 | { |
| 338 | |
| 339 | if ((*skb = dev_alloc_skb(6)) == NULL) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | printk(KERN_WARNING "capi_disc_req: alloc_skb failed\n"); |
| 342 | return -1; |
| 343 | } |
| 344 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 345 | *((ushort *)skb_put(*skb, 2)) = callref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 347 | *(skb_put(*skb, 1)) = 2; /* Cause.Length = 2; */ |
| 348 | *(skb_put(*skb, 1)) = 0x80; |
| 349 | *(skb_put(*skb, 1)) = 0x80 | cause; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 351 | /* |
| 352 | * Change it: we should send 'Sic transit gloria Mundi' here ;-) |
| 353 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 355 | *(skb_put(*skb, 1)) = 0; /* UTUS.Length = 0; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 357 | return 6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | int capi_disc_resp(struct pcbit_chan *chan, struct sk_buff **skb) |
| 361 | { |
| 362 | if ((*skb = dev_alloc_skb(2)) == NULL) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | printk(KERN_WARNING "capi_disc_resp: alloc_skb failed\n"); |
| 365 | return -1; |
| 366 | } |
| 367 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 368 | *((ushort *)skb_put(*skb, 2)) = chan->callref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 370 | return 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | |
| 374 | /* |
| 375 | * Decoding of CAPI messages |
| 376 | * |
| 377 | */ |
| 378 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 379 | int capi_decode_conn_ind(struct pcbit_chan *chan, |
| 380 | struct sk_buff *skb, |
| 381 | struct callb_data *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 383 | int CIlen, len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 385 | /* Call Reference [CAPI] */ |
| 386 | chan->callref = *((ushort *)skb->data); |
| 387 | skb_pull(skb, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | #ifdef DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 390 | printk(KERN_DEBUG "Call Reference: %04x\n", chan->callref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | #endif |
| 392 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 393 | /* Channel Identification */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 395 | /* Expect |
| 396 | Len = 1 |
| 397 | Octect 3 = 0100 10CC - [ 7 Basic, 4 , 2-1 chan ] |
| 398 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 400 | CIlen = skb->data[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | #ifdef DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 402 | if (CIlen == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 404 | if (((skb->data[1]) & 0xFC) == 0x48) |
| 405 | printk(KERN_DEBUG "decode_conn_ind: chan ok\n"); |
| 406 | printk(KERN_DEBUG "phyChan = %d\n", skb->data[1] & 0x03); |
| 407 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | else |
| 409 | printk(KERN_DEBUG "conn_ind: CIlen = %d\n", CIlen); |
| 410 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 411 | skb_pull(skb, CIlen + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 413 | /* Calling Party Number */ |
| 414 | /* An "additional service" as far as Portugal Telecom is concerned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 416 | len = skb->data[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
| 418 | if (len > 0) { |
| 419 | int count = 1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | #ifdef DEBUG |
| 422 | printk(KERN_DEBUG "CPN: Octect 3 %02x\n", skb->data[1]); |
| 423 | #endif |
| 424 | if ((skb->data[1] & 0x80) == 0) |
| 425 | count = 2; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | if (!(info->data.setup.CallingPN = kmalloc(len - count + 1, GFP_ATOMIC))) |
| 428 | return -1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 429 | |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 430 | skb_copy_from_linear_data_offset(skb, count + 1, |
| 431 | info->data.setup.CallingPN, |
| 432 | len - count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | info->data.setup.CallingPN[len - count] = 0; |
| 434 | |
| 435 | } |
| 436 | else { |
| 437 | info->data.setup.CallingPN = NULL; |
| 438 | printk(KERN_DEBUG "NULL CallingPN\n"); |
| 439 | } |
| 440 | |
| 441 | skb_pull(skb, len + 1); |
| 442 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 443 | /* Calling Party Subaddress */ |
| 444 | skb_pull(skb, skb->data[0] + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 446 | /* Called Party Number */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 448 | len = skb->data[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | if (len > 0) { |
| 451 | int count = 1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | if ((skb->data[1] & 0x80) == 0) |
| 454 | count = 2; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | if (!(info->data.setup.CalledPN = kmalloc(len - count + 1, GFP_ATOMIC))) |
| 457 | return -1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 458 | |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 459 | skb_copy_from_linear_data_offset(skb, count + 1, |
| 460 | info->data.setup.CalledPN, |
| 461 | len - count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | info->data.setup.CalledPN[len - count] = 0; |
| 463 | |
| 464 | } |
| 465 | else { |
| 466 | info->data.setup.CalledPN = NULL; |
| 467 | printk(KERN_DEBUG "NULL CalledPN\n"); |
| 468 | } |
| 469 | |
| 470 | skb_pull(skb, len + 1); |
| 471 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 472 | /* Called Party Subaddress */ |
| 473 | skb_pull(skb, skb->data[0] + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 475 | /* LLC */ |
| 476 | skb_pull(skb, skb->data[0] + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 478 | /* HLC */ |
| 479 | skb_pull(skb, skb->data[0] + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 481 | /* U2U */ |
| 482 | skb_pull(skb, skb->data[0] + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 484 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | /* |
| 488 | * returns errcode |
| 489 | */ |
| 490 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 491 | int capi_decode_conn_conf(struct pcbit_chan *chan, struct sk_buff *skb, |
| 492 | int *complete) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 494 | int errcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 496 | chan->callref = *((ushort *)skb->data); /* Update CallReference */ |
| 497 | skb_pull(skb, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 499 | errcode = *((ushort *) skb->data); /* read errcode */ |
| 500 | skb_pull(skb, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 502 | *complete = *(skb->data); |
| 503 | skb_pull(skb, 1); |
| 504 | |
| 505 | /* FIX ME */ |
| 506 | /* This is actually a firmware bug */ |
| 507 | if (!*complete) |
| 508 | { |
| 509 | printk(KERN_DEBUG "complete=%02x\n", *complete); |
| 510 | *complete = 1; |
| 511 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
| 513 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 514 | /* Optional Bearer Capability */ |
| 515 | skb_pull(skb, *(skb->data) + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 517 | /* Channel Identification */ |
| 518 | skb_pull(skb, *(skb->data) + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 520 | /* High Layer Compatibility follows */ |
| 521 | skb_pull(skb, *(skb->data) + 1); |
| 522 | |
| 523 | return errcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 526 | int capi_decode_conn_actv_ind(struct pcbit_chan *chan, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 528 | ushort len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | #ifdef DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 530 | char str[32]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | #endif |
| 532 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 533 | /* Yet Another Bearer Capability */ |
| 534 | skb_pull(skb, *(skb->data) + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 536 | |
| 537 | /* Connected Party Number */ |
| 538 | len = *(skb->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
| 540 | #ifdef DEBUG |
| 541 | if (len > 1 && len < 31) { |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 542 | skb_copy_from_linear_data_offset(skb, 2, str, len - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | str[len] = 0; |
| 544 | printk(KERN_DEBUG "Connected Party Number: %s\n", str); |
| 545 | } |
| 546 | else |
| 547 | printk(KERN_DEBUG "actv_ind CPN len = %d\n", len); |
| 548 | #endif |
| 549 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 550 | skb_pull(skb, len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 552 | /* Connected Subaddress */ |
| 553 | skb_pull(skb, *(skb->data) + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 555 | /* Low Layer Capability */ |
| 556 | skb_pull(skb, *(skb->data) + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 558 | /* High Layer Capability */ |
| 559 | skb_pull(skb, *(skb->data) + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 561 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 564 | int capi_decode_conn_actv_conf(struct pcbit_chan *chan, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 566 | ushort errcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 568 | errcode = *((ushort *)skb->data); |
| 569 | skb_pull(skb, 2); |
| 570 | |
| 571 | /* Channel Identification |
| 572 | skb_pull(skb, skb->data[0] + 1); |
| 573 | */ |
| 574 | return errcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | |
| 578 | int capi_decode_sel_proto_conf(struct pcbit_chan *chan, struct sk_buff *skb) |
| 579 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 580 | ushort errcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 582 | chan->layer2link = *(skb->data); |
| 583 | skb_pull(skb, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 585 | errcode = *((ushort *)skb->data); |
| 586 | skb_pull(skb, 2); |
| 587 | |
| 588 | return errcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | int capi_decode_actv_trans_conf(struct pcbit_chan *chan, struct sk_buff *skb) |
| 592 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 593 | ushort errcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 595 | if (chan->layer2link != *(skb->data)) |
| 596 | printk("capi_decode_actv_trans_conf: layer2link doesn't match\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 598 | skb_pull(skb, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 600 | errcode = *((ushort *)skb->data); |
| 601 | skb_pull(skb, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 603 | return errcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | int capi_decode_disc_ind(struct pcbit_chan *chan, struct sk_buff *skb) |
| 607 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 608 | ushort len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | #ifdef DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 610 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 612 | /* Cause */ |
| 613 | |
| 614 | len = *(skb->data); |
| 615 | skb_pull(skb, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
| 617 | #ifdef DEBUG |
| 618 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 619 | for (i = 0; i < len; i++) |
| 620 | printk(KERN_DEBUG "Cause Octect %d: %02x\n", i + 3, |
| 621 | *(skb->data + i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | #endif |
| 623 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 624 | skb_pull(skb, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 626 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | #ifdef DEBUG |
| 630 | int capi_decode_debug_188(u_char *hdr, ushort hdrlen) |
| 631 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 632 | char str[64]; |
| 633 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 635 | len = hdr[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 637 | if (len < 64 && len == hdrlen - 1) { |
| 638 | memcpy(str, hdr + 1, hdrlen - 1); |
| 639 | str[hdrlen - 1] = 0; |
| 640 | printk("%s\n", str); |
| 641 | } |
| 642 | else |
| 643 | printk("debug message incorrect\n"); |
| 644 | |
| 645 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
| 647 | #endif |