blob: 373f90feda5a9bcc8c244735ec3c67ffda565561 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * CAPI encoder/decoder for
3 * Portugal Telecom CAPI 2.0
4 *
5 * Copyright (C) 1996 Universidade de Lisboa
Joe Perches475be4d2012-02-19 19:52:38 -08006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
8 *
Joe Perches475be4d2012-02-19 19:52:38 -08009 * This software may be used and distributed according to the terms of
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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 Engelhardt96de0e22007-10-19 23:21:04 +020018 * - "Common ISDN API - Perfil Português - Versão 2.1",
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * Telecom Portugal, Fev 1992.
Jan Engelhardt96de0e22007-10-19 23:21:04 +020020 * - "Common ISDN API - Especificação de protocolos para
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 * 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 Torvalds1da177e2005-04-16 15:20:36 -070030#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 Perches475be4d2012-02-19 19:52:38 -080054int capi_conn_req(const char *calledPN, struct sk_buff **skb, int proto)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
Joe Perches475be4d2012-02-19 19:52:38 -080056 ushort len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Joe Perches475be4d2012-02-19 19:52:38 -080058 /*
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 Torvalds1da177e2005-04-16 15:20:36 -070073
Joe Perches475be4d2012-02-19 19:52:38 -080074 len = 18 + strlen(calledPN);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 if (proto == ISDN_PROTO_L2_TRANS)
77 len++;
78
79 if ((*skb = dev_alloc_skb(len)) == NULL) {
Joe Perches475be4d2012-02-19 19:52:38 -080080
81 printk(KERN_WARNING "capi_conn_req: alloc_skb failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 return -1;
83 }
84
Joe Perches475be4d2012-02-19 19:52:38 -080085 /* InfoElmMask */
86 *((ushort *)skb_put(*skb, 2)) = AppInfoMask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
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 Sheldonaec87552016-08-19 16:42:13 +010095 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 /* 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 Perches475be4d2012-02-19 19:52:38 -0800102 /* Bearer Capability - Optional*/
103 *(skb_put(*skb, 1)) = 0; /* BC1.Length = 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Joe Perches475be4d2012-02-19 19:52:38 -0800105 *(skb_put(*skb, 1)) = 1; /* ChannelID.Length = 1 */
106 *(skb_put(*skb, 1)) = 0x83; /* Basic Interface - Any Channel */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Joe Perches475be4d2012-02-19 19:52:38 -0800108 *(skb_put(*skb, 1)) = 0; /* Keypad.Length = 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Joe Perches475be4d2012-02-19 19:52:38 -0800111 *(skb_put(*skb, 1)) = 0; /* CallingPN.Length = 0 */
112 *(skb_put(*skb, 1)) = 0; /* CallingPSA.Length = 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Joe Perches475be4d2012-02-19 19:52:38 -0800114 /* 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 Torvalds1da177e2005-04-16 15:20:36 -0700118
Joe Perches475be4d2012-02-19 19:52:38 -0800119 /* '#' */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Joe Perches475be4d2012-02-19 19:52:38 -0800121 *(skb_put(*skb, 1)) = 0; /* CalledPSA.Length = 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Joe Perches475be4d2012-02-19 19:52:38 -0800123 /* 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 Torvalds1da177e2005-04-16 15:20:36 -0700130}
131
Joe Perches475be4d2012-02-19 19:52:38 -0800132int capi_conn_resp(struct pcbit_chan *chan, struct sk_buff **skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
Joe Perches475be4d2012-02-19 19:52:38 -0800134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 if ((*skb = dev_alloc_skb(5)) == NULL) {
Joe Perches475be4d2012-02-19 19:52:38 -0800136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 printk(KERN_WARNING "capi_conn_resp: alloc_skb failed\n");
138 return -1;
139 }
140
Joe Perches475be4d2012-02-19 19:52:38 -0800141 *((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 Torvalds1da177e2005-04-16 15:20:36 -0700145
Joe Perches475be4d2012-02-19 19:52:38 -0800146 return 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
Joe Perches475be4d2012-02-19 19:52:38 -0800149int capi_conn_active_req(struct pcbit_chan *chan, struct sk_buff **skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Joe Perches475be4d2012-02-19 19:52:38 -0800151 /*
152 * 8 bytes
153 */
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 if ((*skb = dev_alloc_skb(8)) == NULL) {
Joe Perches475be4d2012-02-19 19:52:38 -0800156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 printk(KERN_WARNING "capi_conn_active_req: alloc_skb failed\n");
158 return -1;
159 }
160
Joe Perches475be4d2012-02-19 19:52:38 -0800161 *((ushort *)skb_put(*skb, 2)) = chan->callref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163#ifdef DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -0800164 printk(KERN_DEBUG "Call Reference: %04x\n", chan->callref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165#endif
166
Joe Perches475be4d2012-02-19 19:52:38 -0800167 *(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 Torvalds1da177e2005-04-16 15:20:36 -0700173
174 return 8;
175}
176
Joe Perches475be4d2012-02-19 19:52:38 -0800177int capi_conn_active_resp(struct pcbit_chan *chan, struct sk_buff **skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
Joe Perches475be4d2012-02-19 19:52:38 -0800179 /*
180 * 2 bytes
181 */
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 if ((*skb = dev_alloc_skb(2)) == NULL) {
Joe Perches475be4d2012-02-19 19:52:38 -0800184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 printk(KERN_WARNING "capi_conn_active_resp: alloc_skb failed\n");
186 return -1;
187 }
188
Joe Perches475be4d2012-02-19 19:52:38 -0800189 *((ushort *)skb_put(*skb, 2)) = chan->callref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Joe Perches475be4d2012-02-19 19:52:38 -0800191 return 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192}
193
194
Joe Perches475be4d2012-02-19 19:52:38 -0800195int capi_select_proto_req(struct pcbit_chan *chan, struct sk_buff **skb,
196 int outgoing)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
198
Joe Perches475be4d2012-02-19 19:52:38 -0800199 /*
200 * 18 bytes
201 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 if ((*skb = dev_alloc_skb(18)) == NULL) {
Joe Perches475be4d2012-02-19 19:52:38 -0800204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 printk(KERN_WARNING "capi_select_proto_req: alloc_skb failed\n");
206 return -1;
207 }
208
Joe Perches475be4d2012-02-19 19:52:38 -0800209 *((ushort *)skb_put(*skb, 2)) = chan->callref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Joe Perches475be4d2012-02-19 19:52:38 -0800211 /* Layer2 protocol */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Joe Perches475be4d2012-02-19 19:52:38 -0800213 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 Torvalds1da177e2005-04-16 15:20:36 -0700220 case ISDN_PROTO_L2_TRANS:
Joe Perches475be4d2012-02-19 19:52:38 -0800221 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 * Voice (a-law)
223 */
224 *(skb_put(*skb, 1)) = 0x06;
225 break;
Joe Perches475be4d2012-02-19 19:52:38 -0800226 default:
227#ifdef DEBUG
228 printk(KERN_DEBUG "Transparent\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229#endif
Joe Perches475be4d2012-02-19 19:52:38 -0800230 *(skb_put(*skb, 1)) = 0x03;
231 break;
232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Joe Perches475be4d2012-02-19 19:52:38 -0800234 *(skb_put(*skb, 1)) = (outgoing ? 0x02 : 0x42); /* Don't ask */
235 *(skb_put(*skb, 1)) = 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Joe Perches475be4d2012-02-19 19:52:38 -0800237 *((ushort *) skb_put(*skb, 2)) = MRU;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Joe Perches475be4d2012-02-19 19:52:38 -0800240 *(skb_put(*skb, 1)) = 0x08; /* Modulo */
241 *(skb_put(*skb, 1)) = 0x07; /* Max Window */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Joe Perches475be4d2012-02-19 19:52:38 -0800243 *(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 Torvalds1da177e2005-04-16 15:20:36 -0700258}
259
260
261int capi_activate_transp_req(struct pcbit_chan *chan, struct sk_buff **skb)
262{
263
264 if ((*skb = dev_alloc_skb(7)) == NULL) {
Joe Perches475be4d2012-02-19 19:52:38 -0800265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 printk(KERN_WARNING "capi_activate_transp_req: alloc_skb failed\n");
267 return -1;
268 }
269
Joe Perches475be4d2012-02-19 19:52:38 -0800270 *((ushort *)skb_put(*skb, 2)) = chan->callref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Joe Perches475be4d2012-02-19 19:52:38 -0800273 *(skb_put(*skb, 1)) = chan->layer2link; /* Layer2 id */
274 *(skb_put(*skb, 1)) = 0x00; /* Transmit by default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Joe Perches475be4d2012-02-19 19:52:38 -0800276 *((ushort *) skb_put(*skb, 2)) = MRU;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Joe Perches475be4d2012-02-19 19:52:38 -0800278 *(skb_put(*skb, 1)) = 0x01; /* Enables reception*/
279
280 return 7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281}
282
Joe Perches475be4d2012-02-19 19:52:38 -0800283int capi_tdata_req(struct pcbit_chan *chan, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
285 ushort data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Joe Perches475be4d2012-02-19 19:52:38 -0800287
288 /*
289 * callref - 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 * layer2link - 1
Joe Perches475be4d2012-02-19 19:52:38 -0800291 * wBlockLength - 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 * data - 4
293 * sernum - 1
294 */
Joe Perches475be4d2012-02-19 19:52:38 -0800295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 data_len = skb->len;
297
Joe Perches475be4d2012-02-19 19:52:38 -0800298 if (skb_headroom(skb) < 10)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 {
300 printk(KERN_CRIT "No headspace (%u) on headroom %p for capi header\n", skb_headroom(skb), skb);
301 }
302 else
Joe Perches475be4d2012-02-19 19:52:38 -0800303 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 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 Perches475be4d2012-02-19 19:52:38 -0800319int capi_tdata_resp(struct pcbit_chan *chan, struct sk_buff **skb)
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
322 if ((*skb = dev_alloc_skb(4)) == NULL) {
Joe Perches475be4d2012-02-19 19:52:38 -0800323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 printk(KERN_WARNING "capi_tdata_resp: alloc_skb failed\n");
325 return -1;
326 }
327
Joe Perches475be4d2012-02-19 19:52:38 -0800328 *((ushort *)skb_put(*skb, 2)) = chan->callref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Joe Perches475be4d2012-02-19 19:52:38 -0800330 *(skb_put(*skb, 1)) = chan->layer2link;
331 *(skb_put(*skb, 1)) = chan->r_refnum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Joe Perches475be4d2012-02-19 19:52:38 -0800333 return (*skb)->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334}
335
336int capi_disc_req(ushort callref, struct sk_buff **skb, u_char cause)
337{
338
339 if ((*skb = dev_alloc_skb(6)) == NULL) {
Joe Perches475be4d2012-02-19 19:52:38 -0800340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 printk(KERN_WARNING "capi_disc_req: alloc_skb failed\n");
342 return -1;
343 }
344
Joe Perches475be4d2012-02-19 19:52:38 -0800345 *((ushort *)skb_put(*skb, 2)) = callref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Joe Perches475be4d2012-02-19 19:52:38 -0800347 *(skb_put(*skb, 1)) = 2; /* Cause.Length = 2; */
348 *(skb_put(*skb, 1)) = 0x80;
349 *(skb_put(*skb, 1)) = 0x80 | cause;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Joe Perches475be4d2012-02-19 19:52:38 -0800351 /*
352 * Change it: we should send 'Sic transit gloria Mundi' here ;-)
353 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Joe Perches475be4d2012-02-19 19:52:38 -0800355 *(skb_put(*skb, 1)) = 0; /* UTUS.Length = 0; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Joe Perches475be4d2012-02-19 19:52:38 -0800357 return 6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
360int capi_disc_resp(struct pcbit_chan *chan, struct sk_buff **skb)
361{
362 if ((*skb = dev_alloc_skb(2)) == NULL) {
Joe Perches475be4d2012-02-19 19:52:38 -0800363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 printk(KERN_WARNING "capi_disc_resp: alloc_skb failed\n");
365 return -1;
366 }
367
Joe Perches475be4d2012-02-19 19:52:38 -0800368 *((ushort *)skb_put(*skb, 2)) = chan->callref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Joe Perches475be4d2012-02-19 19:52:38 -0800370 return 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371}
372
373
374/*
375 * Decoding of CAPI messages
376 *
377 */
378
Joe Perches475be4d2012-02-19 19:52:38 -0800379int capi_decode_conn_ind(struct pcbit_chan *chan,
380 struct sk_buff *skb,
381 struct callb_data *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
Joe Perches475be4d2012-02-19 19:52:38 -0800383 int CIlen, len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Joe Perches475be4d2012-02-19 19:52:38 -0800385 /* Call Reference [CAPI] */
386 chan->callref = *((ushort *)skb->data);
387 skb_pull(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389#ifdef DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -0800390 printk(KERN_DEBUG "Call Reference: %04x\n", chan->callref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#endif
392
Joe Perches475be4d2012-02-19 19:52:38 -0800393 /* Channel Identification */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Joe Perches475be4d2012-02-19 19:52:38 -0800395 /* Expect
396 Len = 1
397 Octect 3 = 0100 10CC - [ 7 Basic, 4 , 2-1 chan ]
398 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Joe Perches475be4d2012-02-19 19:52:38 -0800400 CIlen = skb->data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401#ifdef DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -0800402 if (CIlen == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Joe Perches475be4d2012-02-19 19:52:38 -0800404 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 Torvalds1da177e2005-04-16 15:20:36 -0700408 else
409 printk(KERN_DEBUG "conn_ind: CIlen = %d\n", CIlen);
410#endif
Joe Perches475be4d2012-02-19 19:52:38 -0800411 skb_pull(skb, CIlen + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Joe Perches475be4d2012-02-19 19:52:38 -0800413 /* Calling Party Number */
414 /* An "additional service" as far as Portugal Telecom is concerned */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Joe Perches475be4d2012-02-19 19:52:38 -0800416 len = skb->data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 if (len > 0) {
419 int count = 1;
Joe Perches475be4d2012-02-19 19:52:38 -0800420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#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 Perches475be4d2012-02-19 19:52:38 -0800426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 if (!(info->data.setup.CallingPN = kmalloc(len - count + 1, GFP_ATOMIC)))
428 return -1;
Joe Perches475be4d2012-02-19 19:52:38 -0800429
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300430 skb_copy_from_linear_data_offset(skb, count + 1,
431 info->data.setup.CallingPN,
432 len - count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 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 Perches475be4d2012-02-19 19:52:38 -0800443 /* Calling Party Subaddress */
444 skb_pull(skb, skb->data[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Joe Perches475be4d2012-02-19 19:52:38 -0800446 /* Called Party Number */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Joe Perches475be4d2012-02-19 19:52:38 -0800448 len = skb->data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 if (len > 0) {
451 int count = 1;
Joe Perches475be4d2012-02-19 19:52:38 -0800452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if ((skb->data[1] & 0x80) == 0)
454 count = 2;
Joe Perches475be4d2012-02-19 19:52:38 -0800455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 if (!(info->data.setup.CalledPN = kmalloc(len - count + 1, GFP_ATOMIC)))
457 return -1;
Joe Perches475be4d2012-02-19 19:52:38 -0800458
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300459 skb_copy_from_linear_data_offset(skb, count + 1,
460 info->data.setup.CalledPN,
461 len - count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 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 Perches475be4d2012-02-19 19:52:38 -0800472 /* Called Party Subaddress */
473 skb_pull(skb, skb->data[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Joe Perches475be4d2012-02-19 19:52:38 -0800475 /* LLC */
476 skb_pull(skb, skb->data[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Joe Perches475be4d2012-02-19 19:52:38 -0800478 /* HLC */
479 skb_pull(skb, skb->data[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Joe Perches475be4d2012-02-19 19:52:38 -0800481 /* U2U */
482 skb_pull(skb, skb->data[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Joe Perches475be4d2012-02-19 19:52:38 -0800484 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485}
486
487/*
488 * returns errcode
489 */
490
Joe Perches475be4d2012-02-19 19:52:38 -0800491int capi_decode_conn_conf(struct pcbit_chan *chan, struct sk_buff *skb,
492 int *complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
Joe Perches475be4d2012-02-19 19:52:38 -0800494 int errcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Joe Perches475be4d2012-02-19 19:52:38 -0800496 chan->callref = *((ushort *)skb->data); /* Update CallReference */
497 skb_pull(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Joe Perches475be4d2012-02-19 19:52:38 -0800499 errcode = *((ushort *) skb->data); /* read errcode */
500 skb_pull(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Joe Perches475be4d2012-02-19 19:52:38 -0800502 *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 Torvalds1da177e2005-04-16 15:20:36 -0700512
513
Joe Perches475be4d2012-02-19 19:52:38 -0800514 /* Optional Bearer Capability */
515 skb_pull(skb, *(skb->data) + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Joe Perches475be4d2012-02-19 19:52:38 -0800517 /* Channel Identification */
518 skb_pull(skb, *(skb->data) + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Joe Perches475be4d2012-02-19 19:52:38 -0800520 /* High Layer Compatibility follows */
521 skb_pull(skb, *(skb->data) + 1);
522
523 return errcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524}
525
Joe Perches475be4d2012-02-19 19:52:38 -0800526int capi_decode_conn_actv_ind(struct pcbit_chan *chan, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
Joe Perches475be4d2012-02-19 19:52:38 -0800528 ushort len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#ifdef DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -0800530 char str[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531#endif
532
Joe Perches475be4d2012-02-19 19:52:38 -0800533 /* Yet Another Bearer Capability */
534 skb_pull(skb, *(skb->data) + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Joe Perches475be4d2012-02-19 19:52:38 -0800536
537 /* Connected Party Number */
538 len = *(skb->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540#ifdef DEBUG
541 if (len > 1 && len < 31) {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300542 skb_copy_from_linear_data_offset(skb, 2, str, len - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 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 Perches475be4d2012-02-19 19:52:38 -0800550 skb_pull(skb, len + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Joe Perches475be4d2012-02-19 19:52:38 -0800552 /* Connected Subaddress */
553 skb_pull(skb, *(skb->data) + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Joe Perches475be4d2012-02-19 19:52:38 -0800555 /* Low Layer Capability */
556 skb_pull(skb, *(skb->data) + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
Joe Perches475be4d2012-02-19 19:52:38 -0800558 /* High Layer Capability */
559 skb_pull(skb, *(skb->data) + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Joe Perches475be4d2012-02-19 19:52:38 -0800561 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562}
563
Joe Perches475be4d2012-02-19 19:52:38 -0800564int capi_decode_conn_actv_conf(struct pcbit_chan *chan, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565{
Joe Perches475be4d2012-02-19 19:52:38 -0800566 ushort errcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Joe Perches475be4d2012-02-19 19:52:38 -0800568 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 Torvalds1da177e2005-04-16 15:20:36 -0700575}
576
577
578int capi_decode_sel_proto_conf(struct pcbit_chan *chan, struct sk_buff *skb)
579{
Joe Perches475be4d2012-02-19 19:52:38 -0800580 ushort errcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Joe Perches475be4d2012-02-19 19:52:38 -0800582 chan->layer2link = *(skb->data);
583 skb_pull(skb, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Joe Perches475be4d2012-02-19 19:52:38 -0800585 errcode = *((ushort *)skb->data);
586 skb_pull(skb, 2);
587
588 return errcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589}
590
591int capi_decode_actv_trans_conf(struct pcbit_chan *chan, struct sk_buff *skb)
592{
Joe Perches475be4d2012-02-19 19:52:38 -0800593 ushort errcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Joe Perches475be4d2012-02-19 19:52:38 -0800595 if (chan->layer2link != *(skb->data))
596 printk("capi_decode_actv_trans_conf: layer2link doesn't match\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Joe Perches475be4d2012-02-19 19:52:38 -0800598 skb_pull(skb, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Joe Perches475be4d2012-02-19 19:52:38 -0800600 errcode = *((ushort *)skb->data);
601 skb_pull(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Joe Perches475be4d2012-02-19 19:52:38 -0800603 return errcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605
606int capi_decode_disc_ind(struct pcbit_chan *chan, struct sk_buff *skb)
607{
Joe Perches475be4d2012-02-19 19:52:38 -0800608 ushort len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#ifdef DEBUG
Joe Perches475be4d2012-02-19 19:52:38 -0800610 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611#endif
Joe Perches475be4d2012-02-19 19:52:38 -0800612 /* Cause */
613
614 len = *(skb->data);
615 skb_pull(skb, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617#ifdef DEBUG
618
Joe Perches475be4d2012-02-19 19:52:38 -0800619 for (i = 0; i < len; i++)
620 printk(KERN_DEBUG "Cause Octect %d: %02x\n", i + 3,
621 *(skb->data + i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622#endif
623
Joe Perches475be4d2012-02-19 19:52:38 -0800624 skb_pull(skb, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Joe Perches475be4d2012-02-19 19:52:38 -0800626 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}
628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#ifdef DEBUG
630int capi_decode_debug_188(u_char *hdr, ushort hdrlen)
631{
Joe Perches475be4d2012-02-19 19:52:38 -0800632 char str[64];
633 int len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Joe Perches475be4d2012-02-19 19:52:38 -0800635 len = hdr[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Joe Perches475be4d2012-02-19 19:52:38 -0800637 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 Torvalds1da177e2005-04-16 15:20:36 -0700646}
647#endif