aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/isdn')
-rw-r--r--drivers/isdn/capi/capi.c2
-rw-r--r--drivers/isdn/capi/capidrv.c27
-rw-r--r--drivers/isdn/gigaset/Kconfig25
-rw-r--r--drivers/isdn/gigaset/Makefile5
-rw-r--r--drivers/isdn/gigaset/asyncdata.c150
-rw-r--r--drivers/isdn/gigaset/bas-gigaset.c91
-rw-r--r--drivers/isdn/gigaset/capi.c2273
-rw-r--r--drivers/isdn/gigaset/common.c210
-rw-r--r--drivers/isdn/gigaset/dummyll.c68
-rw-r--r--drivers/isdn/gigaset/ev-layer.c118
-rw-r--r--drivers/isdn/gigaset/gigaset.h97
-rw-r--r--drivers/isdn/gigaset/i4l.c529
-rw-r--r--drivers/isdn/gigaset/interface.c9
-rw-r--r--drivers/isdn/gigaset/isocdata.c107
-rw-r--r--drivers/isdn/mISDN/socket.c3
15 files changed, 3170 insertions, 544 deletions
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 2d8352419c0..65bf91e16a4 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -603,7 +603,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
603 603
604 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_CONF) { 604 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_CONF) {
605 u16 info = CAPIMSG_U16(skb->data, 12); // Info field 605 u16 info = CAPIMSG_U16(skb->data, 12); // Info field
606 if (info == 0) { 606 if ((info & 0xff00) == 0) {
607 mutex_lock(&cdev->ncci_list_mtx); 607 mutex_lock(&cdev->ncci_list_mtx);
608 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data)); 608 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data));
609 mutex_unlock(&cdev->ncci_list_mtx); 609 mutex_unlock(&cdev->ncci_list_mtx);
diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c
index 650120261ab..3e6d17f42a9 100644
--- a/drivers/isdn/capi/capidrv.c
+++ b/drivers/isdn/capi/capidrv.c
@@ -40,7 +40,7 @@ static int debugmode = 0;
40MODULE_DESCRIPTION("CAPI4Linux: Interface to ISDN4Linux"); 40MODULE_DESCRIPTION("CAPI4Linux: Interface to ISDN4Linux");
41MODULE_AUTHOR("Carsten Paeth"); 41MODULE_AUTHOR("Carsten Paeth");
42MODULE_LICENSE("GPL"); 42MODULE_LICENSE("GPL");
43module_param(debugmode, uint, 0); 43module_param(debugmode, uint, S_IRUGO|S_IWUSR);
44 44
45/* -------- type definitions ----------------------------------------- */ 45/* -------- type definitions ----------------------------------------- */
46 46
@@ -671,8 +671,8 @@ static void n0(capidrv_contr * card, capidrv_ncci * ncci)
671 NULL, /* Useruserdata */ /* $$$$ */ 671 NULL, /* Useruserdata */ /* $$$$ */
672 NULL /* Facilitydataarray */ 672 NULL /* Facilitydataarray */
673 ); 673 );
674 send_message(card, &cmsg);
675 plci_change_state(card, ncci->plcip, EV_PLCI_DISCONNECT_REQ); 674 plci_change_state(card, ncci->plcip, EV_PLCI_DISCONNECT_REQ);
675 send_message(card, &cmsg);
676 676
677 cmd.command = ISDN_STAT_BHUP; 677 cmd.command = ISDN_STAT_BHUP;
678 cmd.driver = card->myid; 678 cmd.driver = card->myid;
@@ -924,8 +924,8 @@ static void handle_incoming_call(capidrv_contr * card, _cmsg * cmsg)
924 */ 924 */
925 capi_cmsg_answer(cmsg); 925 capi_cmsg_answer(cmsg);
926 cmsg->Reject = 1; /* ignore */ 926 cmsg->Reject = 1; /* ignore */
927 send_message(card, cmsg);
928 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT); 927 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT);
928 send_message(card, cmsg);
929 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s ignored\n", 929 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s ignored\n",
930 card->contrnr, 930 card->contrnr,
931 cmd.parm.setup.phone, 931 cmd.parm.setup.phone,
@@ -974,8 +974,8 @@ static void handle_incoming_call(capidrv_contr * card, _cmsg * cmsg)
974 case 2: /* Call will be rejected. */ 974 case 2: /* Call will be rejected. */
975 capi_cmsg_answer(cmsg); 975 capi_cmsg_answer(cmsg);
976 cmsg->Reject = 2; /* reject call, normal call clearing */ 976 cmsg->Reject = 2; /* reject call, normal call clearing */
977 send_message(card, cmsg);
978 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT); 977 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT);
978 send_message(card, cmsg);
979 break; 979 break;
980 980
981 default: 981 default:
@@ -983,8 +983,8 @@ static void handle_incoming_call(capidrv_contr * card, _cmsg * cmsg)
983 capi_cmsg_answer(cmsg); 983 capi_cmsg_answer(cmsg);
984 cmsg->Reject = 8; /* reject call, 984 cmsg->Reject = 8; /* reject call,
985 destination out of order */ 985 destination out of order */
986 send_message(card, cmsg);
987 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT); 986 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT);
987 send_message(card, cmsg);
988 break; 988 break;
989 } 989 }
990 return; 990 return;
@@ -1020,8 +1020,8 @@ static void handle_plci(_cmsg * cmsg)
1020 card->bchans[plcip->chan].disconnecting = 1; 1020 card->bchans[plcip->chan].disconnecting = 1;
1021 plci_change_state(card, plcip, EV_PLCI_DISCONNECT_IND); 1021 plci_change_state(card, plcip, EV_PLCI_DISCONNECT_IND);
1022 capi_cmsg_answer(cmsg); 1022 capi_cmsg_answer(cmsg);
1023 send_message(card, cmsg);
1024 plci_change_state(card, plcip, EV_PLCI_DISCONNECT_RESP); 1023 plci_change_state(card, plcip, EV_PLCI_DISCONNECT_RESP);
1024 send_message(card, cmsg);
1025 break; 1025 break;
1026 1026
1027 case CAPI_DISCONNECT_CONF: /* plci */ 1027 case CAPI_DISCONNECT_CONF: /* plci */
@@ -1078,8 +1078,8 @@ static void handle_plci(_cmsg * cmsg)
1078 1078
1079 if (card->bchans[plcip->chan].incoming) { 1079 if (card->bchans[plcip->chan].incoming) {
1080 capi_cmsg_answer(cmsg); 1080 capi_cmsg_answer(cmsg);
1081 send_message(card, cmsg);
1082 plci_change_state(card, plcip, EV_PLCI_CONNECT_ACTIVE_IND); 1081 plci_change_state(card, plcip, EV_PLCI_CONNECT_ACTIVE_IND);
1082 send_message(card, cmsg);
1083 } else { 1083 } else {
1084 capidrv_ncci *nccip; 1084 capidrv_ncci *nccip;
1085 capi_cmsg_answer(cmsg); 1085 capi_cmsg_answer(cmsg);
@@ -1098,13 +1098,14 @@ static void handle_plci(_cmsg * cmsg)
1098 NULL /* NCPI */ 1098 NULL /* NCPI */
1099 ); 1099 );
1100 nccip->msgid = cmsg->Messagenumber; 1100 nccip->msgid = cmsg->Messagenumber;
1101 plci_change_state(card, plcip,
1102 EV_PLCI_CONNECT_ACTIVE_IND);
1103 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_REQ);
1101 send_message(card, cmsg); 1104 send_message(card, cmsg);
1102 cmd.command = ISDN_STAT_DCONN; 1105 cmd.command = ISDN_STAT_DCONN;
1103 cmd.driver = card->myid; 1106 cmd.driver = card->myid;
1104 cmd.arg = plcip->chan; 1107 cmd.arg = plcip->chan;
1105 card->interface.statcallb(&cmd); 1108 card->interface.statcallb(&cmd);
1106 plci_change_state(card, plcip, EV_PLCI_CONNECT_ACTIVE_IND);
1107 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_REQ);
1108 } 1109 }
1109 break; 1110 break;
1110 1111
@@ -1193,8 +1194,8 @@ static void handle_ncci(_cmsg * cmsg)
1193 goto notfound; 1194 goto notfound;
1194 1195
1195 capi_cmsg_answer(cmsg); 1196 capi_cmsg_answer(cmsg);
1196 send_message(card, cmsg);
1197 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_ACTIVE_IND); 1197 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_ACTIVE_IND);
1198 send_message(card, cmsg);
1198 1199
1199 cmd.command = ISDN_STAT_BCONN; 1200 cmd.command = ISDN_STAT_BCONN;
1200 cmd.driver = card->myid; 1201 cmd.driver = card->myid;
@@ -1222,8 +1223,8 @@ static void handle_ncci(_cmsg * cmsg)
1222 0, /* Reject */ 1223 0, /* Reject */
1223 NULL /* NCPI */ 1224 NULL /* NCPI */
1224 ); 1225 );
1225 send_message(card, cmsg);
1226 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_RESP); 1226 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_RESP);
1227 send_message(card, cmsg);
1227 break; 1228 break;
1228 } 1229 }
1229 printk(KERN_ERR "capidrv-%d: no mem for ncci, sorry\n", card->contrnr); 1230 printk(KERN_ERR "capidrv-%d: no mem for ncci, sorry\n", card->contrnr);
@@ -1299,8 +1300,8 @@ static void handle_ncci(_cmsg * cmsg)
1299 card->bchans[nccip->chan].disconnecting = 1; 1300 card->bchans[nccip->chan].disconnecting = 1;
1300 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_IND); 1301 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_IND);
1301 capi_cmsg_answer(cmsg); 1302 capi_cmsg_answer(cmsg);
1302 send_message(card, cmsg);
1303 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_RESP); 1303 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_RESP);
1304 send_message(card, cmsg);
1304 break; 1305 break;
1305 1306
1306 case CAPI_DISCONNECT_B3_CONF: /* ncci */ 1307 case CAPI_DISCONNECT_B3_CONF: /* ncci */
@@ -2014,8 +2015,8 @@ static void send_listen(capidrv_contr *card)
2014 card->cipmask, 2015 card->cipmask,
2015 card->cipmask2, 2016 card->cipmask2,
2016 NULL, NULL); 2017 NULL, NULL);
2017 send_message(card, &cmdcmsg);
2018 listen_change_state(card, EV_LISTEN_REQ); 2018 listen_change_state(card, EV_LISTEN_REQ);
2019 send_message(card, &cmdcmsg);
2019} 2020}
2020 2021
2021static void listentimerfunc(unsigned long x) 2022static void listentimerfunc(unsigned long x)
diff --git a/drivers/isdn/gigaset/Kconfig b/drivers/isdn/gigaset/Kconfig
index 18ab8652aa5..dcefedc7044 100644
--- a/drivers/isdn/gigaset/Kconfig
+++ b/drivers/isdn/gigaset/Kconfig
@@ -1,6 +1,5 @@
1menuconfig ISDN_DRV_GIGASET 1menuconfig ISDN_DRV_GIGASET
2 tristate "Siemens Gigaset support" 2 tristate "Siemens Gigaset support"
3 depends on ISDN_I4L
4 select CRC_CCITT 3 select CRC_CCITT
5 select BITREVERSE 4 select BITREVERSE
6 help 5 help
@@ -11,9 +10,33 @@ menuconfig ISDN_DRV_GIGASET
11 If you have one of these devices, say M here and for at least 10 If you have one of these devices, say M here and for at least
12 one of the connection specific parts that follow. 11 one of the connection specific parts that follow.
13 This will build a module called "gigaset". 12 This will build a module called "gigaset".
13 Note: If you build your ISDN subsystem (ISDN_CAPI or ISDN_I4L)
14 as a module, you have to build this driver as a module too,
15 otherwise the Gigaset device won't show up as an ISDN device.
14 16
15if ISDN_DRV_GIGASET 17if ISDN_DRV_GIGASET
16 18
19config GIGASET_CAPI
20 bool "Gigaset CAPI support (EXPERIMENTAL)"
21 depends on EXPERIMENTAL
22 depends on ISDN_CAPI='y'||(ISDN_CAPI='m'&&ISDN_DRV_GIGASET='m')
23 default ISDN_I4L='n'
24 help
25 Build the Gigaset driver as a CAPI 2.0 driver interfacing with
26 the Kernel CAPI subsystem. To use it with the old ISDN4Linux
27 subsystem you'll have to enable the capidrv glue driver.
28 (select ISDN_CAPI_CAPIDRV.)
29 Say N to build the old native ISDN4Linux variant.
30
31config GIGASET_I4L
32 bool
33 depends on ISDN_I4L='y'||(ISDN_I4L='m'&&ISDN_DRV_GIGASET='m')
34 default !GIGASET_CAPI
35
36config GIGASET_DUMMYLL
37 bool
38 default !GIGASET_CAPI&&!GIGASET_I4L
39
17config GIGASET_BASE 40config GIGASET_BASE
18 tristate "Gigaset base station support" 41 tristate "Gigaset base station support"
19 depends on USB 42 depends on USB
diff --git a/drivers/isdn/gigaset/Makefile b/drivers/isdn/gigaset/Makefile
index e9d3189f56b..c453b72272a 100644
--- a/drivers/isdn/gigaset/Makefile
+++ b/drivers/isdn/gigaset/Makefile
@@ -1,4 +1,7 @@
1gigaset-y := common.o interface.o proc.o ev-layer.o i4l.o asyncdata.o 1gigaset-y := common.o interface.o proc.o ev-layer.o asyncdata.o
2gigaset-$(CONFIG_GIGASET_CAPI) += capi.o
3gigaset-$(CONFIG_GIGASET_I4L) += i4l.o
4gigaset-$(CONFIG_GIGASET_DUMMYLL) += dummyll.o
2usb_gigaset-y := usb-gigaset.o 5usb_gigaset-y := usb-gigaset.o
3ser_gigaset-y := ser-gigaset.o 6ser_gigaset-y := ser-gigaset.o
4bas_gigaset-y := bas-gigaset.o isocdata.o 7bas_gigaset-y := bas-gigaset.o isocdata.o
diff --git a/drivers/isdn/gigaset/asyncdata.c b/drivers/isdn/gigaset/asyncdata.c
index 234cc5d5331..a25216bf475 100644
--- a/drivers/isdn/gigaset/asyncdata.c
+++ b/drivers/isdn/gigaset/asyncdata.c
@@ -119,10 +119,7 @@ static inline int hdlc_loop(unsigned char c, unsigned char *src, int numbytes,
119 int inputstate = bcs->inputstate; 119 int inputstate = bcs->inputstate;
120 __u16 fcs = bcs->fcs; 120 __u16 fcs = bcs->fcs;
121 struct sk_buff *skb = bcs->skb; 121 struct sk_buff *skb = bcs->skb;
122 unsigned char error;
123 struct sk_buff *compskb;
124 int startbytes = numbytes; 122 int startbytes = numbytes;
125 int l;
126 123
127 if (unlikely(inputstate & INS_byte_stuff)) { 124 if (unlikely(inputstate & INS_byte_stuff)) {
128 inputstate &= ~INS_byte_stuff; 125 inputstate &= ~INS_byte_stuff;
@@ -158,8 +155,8 @@ byte_stuff:
158#endif 155#endif
159 156
160 /* end of frame */ 157 /* end of frame */
161 error = 1; 158 gigaset_isdn_rcv_err(bcs);
162 gigaset_rcv_error(NULL, cs, bcs); 159 dev_kfree_skb(skb);
163 } else if (!(inputstate & INS_have_data)) { /* 7E 7E */ 160 } else if (!(inputstate & INS_have_data)) { /* 7E 7E */
164#ifdef CONFIG_GIGASET_DEBUG 161#ifdef CONFIG_GIGASET_DEBUG
165 ++bcs->emptycount; 162 ++bcs->emptycount;
@@ -170,54 +167,39 @@ byte_stuff:
170 "7e----------------------------"); 167 "7e----------------------------");
171 168
172 /* end of frame */ 169 /* end of frame */
173 error = 0;
174
175 if (unlikely(fcs != PPP_GOODFCS)) { 170 if (unlikely(fcs != PPP_GOODFCS)) {
176 dev_err(cs->dev, 171 dev_err(cs->dev,
177 "Checksum failed, %u bytes corrupted!\n", 172 "Checksum failed, %u bytes corrupted!\n",
178 skb->len); 173 skb->len);
179 compskb = NULL; 174 gigaset_isdn_rcv_err(bcs);
180 gigaset_rcv_error(compskb, cs, bcs); 175 dev_kfree_skb(skb);
181 error = 1; 176 } else if (likely(skb->len > 2)) {
177 __skb_trim(skb, skb->len - 2);
178 gigaset_skb_rcvd(bcs, skb);
182 } else { 179 } else {
183 if (likely((l = skb->len) > 2)) { 180 if (skb->len) {
184 skb->tail -= 2; 181 dev_err(cs->dev,
185 skb->len -= 2; 182 "invalid packet size (%d)\n", skb->len);
186 } else { 183 gigaset_isdn_rcv_err(bcs);
187 dev_kfree_skb(skb);
188 skb = NULL;
189 inputstate |= INS_skip_frame;
190 if (l == 1) {
191 dev_err(cs->dev,
192 "invalid packet size (1)!\n");
193 error = 1;
194 gigaset_rcv_error(NULL,
195 cs, bcs);
196 }
197 }
198 if (likely(!(error ||
199 (inputstate &
200 INS_skip_frame)))) {
201 gigaset_rcv_skb(skb, cs, bcs);
202 } 184 }
185 dev_kfree_skb(skb);
203 } 186 }
204 } 187 }
205 188
206 if (unlikely(error))
207 if (skb)
208 dev_kfree_skb(skb);
209
210 fcs = PPP_INITFCS; 189 fcs = PPP_INITFCS;
211 inputstate &= ~(INS_have_data | INS_skip_frame); 190 inputstate &= ~(INS_have_data | INS_skip_frame);
212 if (unlikely(bcs->ignore)) { 191 if (unlikely(bcs->ignore)) {
213 inputstate |= INS_skip_frame; 192 inputstate |= INS_skip_frame;
214 skb = NULL; 193 skb = NULL;
215 } else if (likely((skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)) {
216 skb_reserve(skb, HW_HDR_LEN);
217 } else { 194 } else {
218 dev_warn(cs->dev, 195 skb = dev_alloc_skb(SBUFSIZE + cs->hw_hdr_len);
219 "could not allocate new skb\n"); 196 if (skb != NULL) {
220 inputstate |= INS_skip_frame; 197 skb_reserve(skb, cs->hw_hdr_len);
198 } else {
199 dev_warn(cs->dev,
200 "could not allocate new skb\n");
201 inputstate |= INS_skip_frame;
202 }
221 } 203 }
222 204
223 break; 205 break;
@@ -314,18 +296,21 @@ static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes,
314 /* pass data up */ 296 /* pass data up */
315 if (likely(inputstate & INS_have_data)) { 297 if (likely(inputstate & INS_have_data)) {
316 if (likely(!(inputstate & INS_skip_frame))) { 298 if (likely(!(inputstate & INS_skip_frame))) {
317 gigaset_rcv_skb(skb, cs, bcs); 299 gigaset_skb_rcvd(bcs, skb);
318 } 300 }
319 inputstate &= ~(INS_have_data | INS_skip_frame); 301 inputstate &= ~(INS_have_data | INS_skip_frame);
320 if (unlikely(bcs->ignore)) { 302 if (unlikely(bcs->ignore)) {
321 inputstate |= INS_skip_frame; 303 inputstate |= INS_skip_frame;
322 skb = NULL; 304 skb = NULL;
323 } else if (likely((skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN))
324 != NULL)) {
325 skb_reserve(skb, HW_HDR_LEN);
326 } else { 305 } else {
327 dev_warn(cs->dev, "could not allocate new skb\n"); 306 skb = dev_alloc_skb(SBUFSIZE + cs->hw_hdr_len);
328 inputstate |= INS_skip_frame; 307 if (skb != NULL) {
308 skb_reserve(skb, cs->hw_hdr_len);
309 } else {
310 dev_warn(cs->dev,
311 "could not allocate new skb\n");
312 inputstate |= INS_skip_frame;
313 }
329 } 314 }
330 } 315 }
331 316
@@ -334,7 +319,14 @@ static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes,
334 return startbytes - numbytes; 319 return startbytes - numbytes;
335} 320}
336 321
337/* process a block of data received from the device 322/**
323 * gigaset_m10x_input() - process a block of data received from the device
324 * @inbuf: received data and device descriptor structure.
325 *
326 * Called by hardware module {ser,usb}_gigaset with a block of received
327 * bytes. Separates the bytes received over the serial data channel into
328 * user data and command replies (locked/unlocked) according to the
329 * current state of the interface.
338 */ 330 */
339void gigaset_m10x_input(struct inbuf_t *inbuf) 331void gigaset_m10x_input(struct inbuf_t *inbuf)
340{ 332{
@@ -376,7 +368,7 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
376 /* FIXME use function pointers? */ 368 /* FIXME use function pointers? */
377 if (inbuf->inputstate & INS_command) 369 if (inbuf->inputstate & INS_command)
378 procbytes = cmd_loop(c, src, numbytes, inbuf); 370 procbytes = cmd_loop(c, src, numbytes, inbuf);
379 else if (inbuf->bcs->proto2 == ISDN_PROTO_L2_HDLC) 371 else if (inbuf->bcs->proto2 == L2_HDLC)
380 procbytes = hdlc_loop(c, src, numbytes, inbuf); 372 procbytes = hdlc_loop(c, src, numbytes, inbuf);
381 else 373 else
382 procbytes = iraw_loop(c, src, numbytes, inbuf); 374 procbytes = iraw_loop(c, src, numbytes, inbuf);
@@ -433,16 +425,16 @@ EXPORT_SYMBOL_GPL(gigaset_m10x_input);
433 425
434/* == data output ========================================================== */ 426/* == data output ========================================================== */
435 427
436/* Encoding of a PPP packet into an octet stuffed HDLC frame 428/*
437 * with FCS, opening and closing flags. 429 * Encode a data packet into an octet stuffed HDLC frame with FCS,
430 * opening and closing flags, preserving headroom data.
438 * parameters: 431 * parameters:
439 * skb skb containing original packet (freed upon return) 432 * skb skb containing original packet (freed upon return)
440 * head number of headroom bytes to allocate in result skb 433 * headroom number of headroom bytes to preserve
441 * tail number of tailroom bytes to allocate in result skb
442 * Return value: 434 * Return value:
443 * pointer to newly allocated skb containing the result frame 435 * pointer to newly allocated skb containing the result frame
444 */ 436 */
445static struct sk_buff *HDLC_Encode(struct sk_buff *skb, int head, int tail) 437static struct sk_buff *HDLC_Encode(struct sk_buff *skb, int headroom)
446{ 438{
447 struct sk_buff *hdlc_skb; 439 struct sk_buff *hdlc_skb;
448 __u16 fcs; 440 __u16 fcs;
@@ -464,16 +456,17 @@ static struct sk_buff *HDLC_Encode(struct sk_buff *skb, int head, int tail)
464 456
465 /* size of new buffer: original size + number of stuffing bytes 457 /* size of new buffer: original size + number of stuffing bytes
466 * + 2 bytes FCS + 2 stuffing bytes for FCS (if needed) + 2 flag bytes 458 * + 2 bytes FCS + 2 stuffing bytes for FCS (if needed) + 2 flag bytes
459 * + room for acknowledgement header
467 */ 460 */
468 hdlc_skb = dev_alloc_skb(skb->len + stuf_cnt + 6 + tail + head); 461 hdlc_skb = dev_alloc_skb(skb->len + stuf_cnt + 6 + headroom);
469 if (!hdlc_skb) { 462 if (!hdlc_skb) {
470 dev_kfree_skb(skb); 463 dev_kfree_skb(skb);
471 return NULL; 464 return NULL;
472 } 465 }
473 skb_reserve(hdlc_skb, head);
474 466
475 /* Copy acknowledge request into new skb */ 467 /* Copy acknowledgement header into new skb */
476 memcpy(hdlc_skb->head, skb->head, 2); 468 skb_reserve(hdlc_skb, headroom);
469 memcpy(hdlc_skb->head, skb->head, headroom);
477 470
478 /* Add flag sequence in front of everything.. */ 471 /* Add flag sequence in front of everything.. */
479 *(skb_put(hdlc_skb, 1)) = PPP_FLAG; 472 *(skb_put(hdlc_skb, 1)) = PPP_FLAG;
@@ -508,15 +501,16 @@ static struct sk_buff *HDLC_Encode(struct sk_buff *skb, int head, int tail)
508 return hdlc_skb; 501 return hdlc_skb;
509} 502}
510 503
511/* Encoding of a raw packet into an octet stuffed bit inverted frame 504/*
505 * Encode a data packet into an octet stuffed raw bit inverted frame,
506 * preserving headroom data.
512 * parameters: 507 * parameters:
513 * skb skb containing original packet (freed upon return) 508 * skb skb containing original packet (freed upon return)
514 * head number of headroom bytes to allocate in result skb 509 * headroom number of headroom bytes to preserve
515 * tail number of tailroom bytes to allocate in result skb
516 * Return value: 510 * Return value:
517 * pointer to newly allocated skb containing the result frame 511 * pointer to newly allocated skb containing the result frame
518 */ 512 */
519static struct sk_buff *iraw_encode(struct sk_buff *skb, int head, int tail) 513static struct sk_buff *iraw_encode(struct sk_buff *skb, int headroom)
520{ 514{
521 struct sk_buff *iraw_skb; 515 struct sk_buff *iraw_skb;
522 unsigned char c; 516 unsigned char c;
@@ -524,12 +518,15 @@ static struct sk_buff *iraw_encode(struct sk_buff *skb, int head, int tail)
524 int len; 518 int len;
525 519
526 /* worst case: every byte must be stuffed */ 520 /* worst case: every byte must be stuffed */
527 iraw_skb = dev_alloc_skb(2*skb->len + tail + head); 521 iraw_skb = dev_alloc_skb(2*skb->len + headroom);
528 if (!iraw_skb) { 522 if (!iraw_skb) {
529 dev_kfree_skb(skb); 523 dev_kfree_skb(skb);
530 return NULL; 524 return NULL;
531 } 525 }
532 skb_reserve(iraw_skb, head); 526
527 /* Copy acknowledgement header into new skb */
528 skb_reserve(iraw_skb, headroom);
529 memcpy(iraw_skb->head, skb->head, headroom);
533 530
534 cp = skb->data; 531 cp = skb->data;
535 len = skb->len; 532 len = skb->len;
@@ -543,26 +540,29 @@ static struct sk_buff *iraw_encode(struct sk_buff *skb, int head, int tail)
543 return iraw_skb; 540 return iraw_skb;
544} 541}
545 542
546/* gigaset_send_skb 543/**
547 * called by common.c to queue an skb for sending 544 * gigaset_m10x_send_skb() - queue an skb for sending
548 * and start transmission if necessary 545 * @bcs: B channel descriptor structure.
549 * parameters: 546 * @skb: data to send.
550 * B Channel control structure 547 *
551 * skb 548 * Called by LL to encode and queue an skb for sending, and start
549 * transmission if necessary.
550 * Once the payload data has been transmitted completely, gigaset_skb_sent()
551 * will be called with the first cs->hw_hdr_len bytes of skb->head preserved.
552 *
552 * Return value: 553 * Return value:
553 * number of bytes accepted for sending 554 * number of bytes accepted for sending (skb->len) if ok,
554 * (skb->len if ok, 0 if out of buffer space) 555 * error code < 0 (eg. -ENOMEM) on error
555 * or error code (< 0, eg. -EINVAL)
556 */ 556 */
557int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb) 557int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb)
558{ 558{
559 unsigned len = skb->len; 559 unsigned len = skb->len;
560 unsigned long flags; 560 unsigned long flags;
561 561
562 if (bcs->proto2 == ISDN_PROTO_L2_HDLC) 562 if (bcs->proto2 == L2_HDLC)
563 skb = HDLC_Encode(skb, HW_HDR_LEN, 0); 563 skb = HDLC_Encode(skb, bcs->cs->hw_hdr_len);
564 else 564 else
565 skb = iraw_encode(skb, HW_HDR_LEN, 0); 565 skb = iraw_encode(skb, bcs->cs->hw_hdr_len);
566 if (!skb) { 566 if (!skb) {
567 dev_err(bcs->cs->dev, 567 dev_err(bcs->cs->dev,
568 "unable to allocate memory for encoding!\n"); 568 "unable to allocate memory for encoding!\n");
diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
index 781c4041f7b..388e63a8ae9 100644
--- a/drivers/isdn/gigaset/bas-gigaset.c
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -134,6 +134,7 @@ struct bas_cardstate {
134#define BS_ATRDPEND 0x040 /* urb_cmd_in in use */ 134#define BS_ATRDPEND 0x040 /* urb_cmd_in in use */
135#define BS_ATWRPEND 0x080 /* urb_cmd_out in use */ 135#define BS_ATWRPEND 0x080 /* urb_cmd_out in use */
136#define BS_SUSPEND 0x100 /* USB port suspended */ 136#define BS_SUSPEND 0x100 /* USB port suspended */
137#define BS_RESETTING 0x200 /* waiting for HD_RESET_INTERRUPT_PIPE_ACK */
137 138
138 139
139static struct gigaset_driver *driver = NULL; 140static struct gigaset_driver *driver = NULL;
@@ -319,6 +320,21 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
319 return -EINVAL; 320 return -EINVAL;
320} 321}
321 322
323/* set/clear bits in base connection state, return previous state
324 */
325static inline int update_basstate(struct bas_cardstate *ucs,
326 int set, int clear)
327{
328 unsigned long flags;
329 int state;
330
331 spin_lock_irqsave(&ucs->lock, flags);
332 state = ucs->basstate;
333 ucs->basstate = (state & ~clear) | set;
334 spin_unlock_irqrestore(&ucs->lock, flags);
335 return state;
336}
337
322/* error_hangup 338/* error_hangup
323 * hang up any existing connection because of an unrecoverable error 339 * hang up any existing connection because of an unrecoverable error
324 * This function may be called from any context and takes care of scheduling 340 * This function may be called from any context and takes care of scheduling
@@ -350,12 +366,9 @@ static inline void error_hangup(struct bc_state *bcs)
350 */ 366 */
351static inline void error_reset(struct cardstate *cs) 367static inline void error_reset(struct cardstate *cs)
352{ 368{
353 /* close AT command channel to recover (ignore errors) */ 369 /* reset interrupt pipe to recover (ignore errors) */
354 req_submit(cs->bcs, HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT); 370 update_basstate(cs->hw.bas, BS_RESETTING, 0);
355 371 req_submit(cs->bcs, HD_RESET_INTERRUPT_PIPE, 0, BAS_TIMEOUT);
356 //FIXME try to recover without bothering the user
357 dev_err(cs->dev,
358 "unrecoverable error - please disconnect Gigaset base to reset\n");
359} 372}
360 373
361/* check_pending 374/* check_pending
@@ -398,8 +411,13 @@ static void check_pending(struct bas_cardstate *ucs)
398 case HD_DEVICE_INIT_ACK: /* no reply expected */ 411 case HD_DEVICE_INIT_ACK: /* no reply expected */
399 ucs->pending = 0; 412 ucs->pending = 0;
400 break; 413 break;
401 /* HD_READ_ATMESSAGE, HD_WRITE_ATMESSAGE, HD_RESET_INTERRUPTPIPE 414 case HD_RESET_INTERRUPT_PIPE:
402 * are handled separately and should never end up here 415 if (!(ucs->basstate & BS_RESETTING))
416 ucs->pending = 0;
417 break;
418 /*
419 * HD_READ_ATMESSAGE and HD_WRITE_ATMESSAGE are handled separately
420 * and should never end up here
403 */ 421 */
404 default: 422 default:
405 dev_warn(&ucs->interface->dev, 423 dev_warn(&ucs->interface->dev,
@@ -449,21 +467,6 @@ static void cmd_in_timeout(unsigned long data)
449 error_reset(cs); 467 error_reset(cs);
450} 468}
451 469
452/* set/clear bits in base connection state, return previous state
453 */
454inline static int update_basstate(struct bas_cardstate *ucs,
455 int set, int clear)
456{
457 unsigned long flags;
458 int state;
459
460 spin_lock_irqsave(&ucs->lock, flags);
461 state = ucs->basstate;
462 ucs->basstate = (state & ~clear) | set;
463 spin_unlock_irqrestore(&ucs->lock, flags);
464 return state;
465}
466
467/* read_ctrl_callback 470/* read_ctrl_callback
468 * USB completion handler for control pipe input 471 * USB completion handler for control pipe input
469 * called by the USB subsystem in interrupt context 472 * called by the USB subsystem in interrupt context
@@ -762,7 +765,8 @@ static void read_int_callback(struct urb *urb)
762 break; 765 break;
763 766
764 case HD_RESET_INTERRUPT_PIPE_ACK: 767 case HD_RESET_INTERRUPT_PIPE_ACK:
765 gig_dbg(DEBUG_USBREQ, "HD_RESET_INTERRUPT_PIPE_ACK"); 768 update_basstate(ucs, 0, BS_RESETTING);
769 dev_notice(cs->dev, "interrupt pipe reset\n");
766 break; 770 break;
767 771
768 case HD_SUSPEND_END: 772 case HD_SUSPEND_END:
@@ -907,7 +911,7 @@ static int starturbs(struct bc_state *bcs)
907 int rc; 911 int rc;
908 912
909 /* initialize L2 reception */ 913 /* initialize L2 reception */
910 if (bcs->proto2 == ISDN_PROTO_L2_HDLC) 914 if (bcs->proto2 == L2_HDLC)
911 bcs->inputstate |= INS_flag_hunt; 915 bcs->inputstate |= INS_flag_hunt;
912 916
913 /* submit all isochronous input URBs */ 917 /* submit all isochronous input URBs */
@@ -1060,7 +1064,7 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1060 "%s: buffer busy at frame %d", 1064 "%s: buffer busy at frame %d",
1061 __func__, nframe); 1065 __func__, nframe);
1062 /* tasklet will be restarted from 1066 /* tasklet will be restarted from
1063 gigaset_send_skb() */ 1067 gigaset_isoc_send_skb() */
1064 } else { 1068 } else {
1065 dev_err(ucx->bcs->cs->dev, 1069 dev_err(ucx->bcs->cs->dev,
1066 "%s: buffer error %d at frame %d\n", 1070 "%s: buffer error %d at frame %d\n",
@@ -1331,28 +1335,24 @@ static void read_iso_tasklet(unsigned long data)
1331 rcvbuf = urb->transfer_buffer; 1335 rcvbuf = urb->transfer_buffer;
1332 totleft = urb->actual_length; 1336 totleft = urb->actual_length;
1333 for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) { 1337 for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) {
1334 if (unlikely(urb->iso_frame_desc[frame].status)) { 1338 numbytes = urb->iso_frame_desc[frame].actual_length;
1339 if (unlikely(urb->iso_frame_desc[frame].status))
1335 dev_warn(cs->dev, 1340 dev_warn(cs->dev,
1336 "isochronous read: frame %d: %s\n", 1341 "isochronous read: frame %d[%d]: %s\n",
1337 frame, 1342 frame, numbytes,
1338 get_usb_statmsg( 1343 get_usb_statmsg(
1339 urb->iso_frame_desc[frame].status)); 1344 urb->iso_frame_desc[frame].status));
1340 break; 1345 if (unlikely(numbytes > BAS_MAXFRAME))
1341 }
1342 numbytes = urb->iso_frame_desc[frame].actual_length;
1343 if (unlikely(numbytes > BAS_MAXFRAME)) {
1344 dev_warn(cs->dev, 1346 dev_warn(cs->dev,
1345 "isochronous read: frame %d: " 1347 "isochronous read: frame %d: "
1346 "numbytes (%d) > BAS_MAXFRAME\n", 1348 "numbytes (%d) > BAS_MAXFRAME\n",
1347 frame, numbytes); 1349 frame, numbytes);
1348 break;
1349 }
1350 if (unlikely(numbytes > totleft)) { 1350 if (unlikely(numbytes > totleft)) {
1351 dev_warn(cs->dev, 1351 dev_warn(cs->dev,
1352 "isochronous read: frame %d: " 1352 "isochronous read: frame %d: "
1353 "numbytes (%d) > totleft (%d)\n", 1353 "numbytes (%d) > totleft (%d)\n",
1354 frame, numbytes, totleft); 1354 frame, numbytes, totleft);
1355 break; 1355 numbytes = totleft;
1356 } 1356 }
1357 offset = urb->iso_frame_desc[frame].offset; 1357 offset = urb->iso_frame_desc[frame].offset;
1358 if (unlikely(offset + numbytes > BAS_INBUFSIZE)) { 1358 if (unlikely(offset + numbytes > BAS_INBUFSIZE)) {
@@ -1361,7 +1361,7 @@ static void read_iso_tasklet(unsigned long data)
1361 "offset (%d) + numbytes (%d) " 1361 "offset (%d) + numbytes (%d) "
1362 "> BAS_INBUFSIZE\n", 1362 "> BAS_INBUFSIZE\n",
1363 frame, offset, numbytes); 1363 frame, offset, numbytes);
1364 break; 1364 numbytes = BAS_INBUFSIZE - offset;
1365 } 1365 }
1366 gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs); 1366 gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs);
1367 totleft -= numbytes; 1367 totleft -= numbytes;
@@ -1433,6 +1433,7 @@ static void req_timeout(unsigned long data)
1433 1433
1434 case HD_CLOSE_ATCHANNEL: 1434 case HD_CLOSE_ATCHANNEL:
1435 dev_err(bcs->cs->dev, "timeout closing AT channel\n"); 1435 dev_err(bcs->cs->dev, "timeout closing AT channel\n");
1436 error_reset(bcs->cs);
1436 break; 1437 break;
1437 1438
1438 case HD_CLOSE_B2CHANNEL: 1439 case HD_CLOSE_B2CHANNEL:
@@ -1442,6 +1443,13 @@ static void req_timeout(unsigned long data)
1442 error_reset(bcs->cs); 1443 error_reset(bcs->cs);
1443 break; 1444 break;
1444 1445
1446 case HD_RESET_INTERRUPT_PIPE:
1447 /* error recovery escalation */
1448 dev_err(bcs->cs->dev,
1449 "reset interrupt pipe timeout, attempting USB reset\n");
1450 usb_queue_reset_device(bcs->cs->hw.bas->interface);
1451 break;
1452
1445 default: 1453 default:
1446 dev_warn(bcs->cs->dev, "request 0x%02x timed out, clearing\n", 1454 dev_warn(bcs->cs->dev, "request 0x%02x timed out, clearing\n",
1447 pending); 1455 pending);
@@ -1934,6 +1942,15 @@ static int gigaset_write_cmd(struct cardstate *cs,
1934 goto notqueued; 1942 goto notqueued;
1935 } 1943 }
1936 1944
1945 /* translate "+++" escape sequence sent as a single separate command
1946 * into "close AT channel" command for error recovery
1947 * The next command will reopen the AT channel automatically.
1948 */
1949 if (len == 3 && !memcmp(buf, "+++", 3)) {
1950 rc = req_submit(cs->bcs, HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT);
1951 goto notqueued;
1952 }
1953
1937 if (len > IF_WRITEBUF) 1954 if (len > IF_WRITEBUF)
1938 len = IF_WRITEBUF; 1955 len = IF_WRITEBUF;
1939 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) { 1956 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c
new file mode 100644
index 00000000000..c276a925b36
--- /dev/null
+++ b/drivers/isdn/gigaset/capi.c
@@ -0,0 +1,2273 @@
1/*
2 * Kernel CAPI interface for the Gigaset driver
3 *
4 * Copyright (c) 2009 by Tilman Schmidt <tilman@imap.cc>.
5 *
6 * =====================================================================
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 * =====================================================================
12 */
13
14#include "gigaset.h"
15#include <linux/ctype.h>
16#include <linux/isdn/capilli.h>
17#include <linux/isdn/capicmd.h>
18#include <linux/isdn/capiutil.h>
19
20/* missing from kernelcapi.h */
21#define CapiNcpiNotSupportedByProtocol 0x0001
22#define CapiFlagsNotSupportedByProtocol 0x0002
23#define CapiAlertAlreadySent 0x0003
24#define CapiFacilitySpecificFunctionNotSupported 0x3011
25
26/* missing from capicmd.h */
27#define CAPI_CONNECT_IND_BASELEN (CAPI_MSG_BASELEN+4+2+8*1)
28#define CAPI_CONNECT_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+3*1)
29#define CAPI_CONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
30#define CAPI_CONNECT_B3_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
31#define CAPI_DATA_B3_REQ_LEN64 (CAPI_MSG_BASELEN+4+4+2+2+2+8)
32#define CAPI_DATA_B3_CONF_LEN (CAPI_MSG_BASELEN+4+2+2)
33#define CAPI_DISCONNECT_IND_LEN (CAPI_MSG_BASELEN+4+2)
34#define CAPI_DISCONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+2+1)
35#define CAPI_FACILITY_CONF_BASELEN (CAPI_MSG_BASELEN+4+2+2+1)
36/* most _CONF messages contain only Controller/PLCI/NCCI and Info parameters */
37#define CAPI_STDCONF_LEN (CAPI_MSG_BASELEN+4+2)
38
39#define CAPI_FACILITY_HANDSET 0x0000
40#define CAPI_FACILITY_DTMF 0x0001
41#define CAPI_FACILITY_V42BIS 0x0002
42#define CAPI_FACILITY_SUPPSVC 0x0003
43#define CAPI_FACILITY_WAKEUP 0x0004
44#define CAPI_FACILITY_LI 0x0005
45
46#define CAPI_SUPPSVC_GETSUPPORTED 0x0000
47
48/* missing from capiutil.h */
49#define CAPIMSG_PLCI_PART(m) CAPIMSG_U8(m, 9)
50#define CAPIMSG_NCCI_PART(m) CAPIMSG_U16(m, 10)
51#define CAPIMSG_HANDLE_REQ(m) CAPIMSG_U16(m, 18) /* DATA_B3_REQ/_IND only! */
52#define CAPIMSG_FLAGS(m) CAPIMSG_U16(m, 20)
53#define CAPIMSG_SETCONTROLLER(m, contr) capimsg_setu8(m, 8, contr)
54#define CAPIMSG_SETPLCI_PART(m, plci) capimsg_setu8(m, 9, plci)
55#define CAPIMSG_SETNCCI_PART(m, ncci) capimsg_setu16(m, 10, ncci)
56#define CAPIMSG_SETFLAGS(m, flags) capimsg_setu16(m, 20, flags)
57
58/* parameters with differing location in DATA_B3_CONF/_RESP: */
59#define CAPIMSG_SETHANDLE_CONF(m, handle) capimsg_setu16(m, 12, handle)
60#define CAPIMSG_SETINFO_CONF(m, info) capimsg_setu16(m, 14, info)
61
62/* Flags (DATA_B3_REQ/_IND) */
63#define CAPI_FLAGS_DELIVERY_CONFIRMATION 0x04
64#define CAPI_FLAGS_RESERVED (~0x1f)
65
66/* buffer sizes */
67#define MAX_BC_OCTETS 11
68#define MAX_HLC_OCTETS 3
69#define MAX_NUMBER_DIGITS 20
70#define MAX_FMT_IE_LEN 20
71
72/* values for gigaset_capi_appl.connected */
73#define APCONN_NONE 0 /* inactive/listening */
74#define APCONN_SETUP 1 /* connecting */
75#define APCONN_ACTIVE 2 /* B channel up */
76
77/* registered application data structure */
78struct gigaset_capi_appl {
79 struct list_head ctrlist;
80 struct gigaset_capi_appl *bcnext;
81 u16 id;
82 u16 nextMessageNumber;
83 u32 listenInfoMask;
84 u32 listenCIPmask;
85 int connected;
86};
87
88/* CAPI specific controller data structure */
89struct gigaset_capi_ctr {
90 struct capi_ctr ctr;
91 struct list_head appls;
92 struct sk_buff_head sendqueue;
93 atomic_t sendqlen;
94 /* two _cmsg structures possibly used concurrently: */
95 _cmsg hcmsg; /* for message composition triggered from hardware */
96 _cmsg acmsg; /* for dissection of messages sent from application */
97 u8 bc_buf[MAX_BC_OCTETS+1];
98 u8 hlc_buf[MAX_HLC_OCTETS+1];
99 u8 cgpty_buf[MAX_NUMBER_DIGITS+3];
100 u8 cdpty_buf[MAX_NUMBER_DIGITS+2];
101};
102
103/* CIP Value table (from CAPI 2.0 standard, ch. 6.1) */
104static struct {
105 u8 *bc;
106 u8 *hlc;
107} cip2bchlc[] = {
108 [1] = { "8090A3", NULL },
109 /* Speech (A-law) */
110 [2] = { "8890", NULL },
111 /* Unrestricted digital information */
112 [3] = { "8990", NULL },
113 /* Restricted digital information */
114 [4] = { "9090A3", NULL },
115 /* 3,1 kHz audio (A-law) */
116 [5] = { "9190", NULL },
117 /* 7 kHz audio */
118 [6] = { "9890", NULL },
119 /* Video */
120 [7] = { "88C0C6E6", NULL },
121 /* Packet mode */
122 [8] = { "8890218F", NULL },
123 /* 56 kbit/s rate adaptation */
124 [9] = { "9190A5", NULL },
125 /* Unrestricted digital information with tones/announcements */
126 [16] = { "8090A3", "9181" },
127 /* Telephony */
128 [17] = { "9090A3", "9184" },
129 /* Group 2/3 facsimile */
130 [18] = { "8890", "91A1" },
131 /* Group 4 facsimile Class 1 */
132 [19] = { "8890", "91A4" },
133 /* Teletex service basic and mixed mode
134 and Group 4 facsimile service Classes II and III */
135 [20] = { "8890", "91A8" },
136 /* Teletex service basic and processable mode */
137 [21] = { "8890", "91B1" },
138 /* Teletex service basic mode */
139 [22] = { "8890", "91B2" },
140 /* International interworking for Videotex */
141 [23] = { "8890", "91B5" },
142 /* Telex */
143 [24] = { "8890", "91B8" },
144 /* Message Handling Systems in accordance with X.400 */
145 [25] = { "8890", "91C1" },
146 /* OSI application in accordance with X.200 */
147 [26] = { "9190A5", "9181" },
148 /* 7 kHz telephony */
149 [27] = { "9190A5", "916001" },
150 /* Video telephony, first connection */
151 [28] = { "8890", "916002" },
152 /* Video telephony, second connection */
153};
154
155/*
156 * helper functions
157 * ================
158 */
159
160/*
161 * emit unsupported parameter warning
162 */
163static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
164 char *msgname, char *paramname)
165{
166 if (param && *param)
167 dev_warn(cs->dev, "%s: ignoring unsupported parameter: %s\n",
168 msgname, paramname);
169}
170
171static inline void ignore_cmstruct_param(struct cardstate *cs, _cmstruct param,
172 char *msgname, char *paramname)
173{
174 if (param != CAPI_DEFAULT)
175 dev_warn(cs->dev, "%s: ignoring unsupported parameter: %s\n",
176 msgname, paramname);
177}
178
179/*
180 * check for legal hex digit
181 */
182static inline int ishexdigit(char c)
183{
184 if (c >= '0' && c <= '9')
185 return 1;
186 if (c >= 'A' && c <= 'F')
187 return 1;
188 if (c >= 'a' && c <= 'f')
189 return 1;
190 return 0;
191}
192
193/*
194 * convert hex to binary
195 */
196static inline u8 hex2bin(char c)
197{
198 int result = c & 0x0f;
199 if (c & 0x40)
200 result += 9;
201 return result;
202}
203
204/*
205 * convert an IE from Gigaset hex string to ETSI binary representation
206 * including length byte
207 * return value: result length, -1 on error
208 */
209static int encode_ie(char *in, u8 *out, int maxlen)
210{
211 int l = 0;
212 while (*in) {
213 if (!ishexdigit(in[0]) || !ishexdigit(in[1]) || l >= maxlen)
214 return -1;
215 out[++l] = (hex2bin(in[0]) << 4) + hex2bin(in[1]);
216 in += 2;
217 }
218 out[0] = l;
219 return l;
220}
221
222/*
223 * convert an IE from ETSI binary representation including length byte
224 * to Gigaset hex string
225 */
226static void decode_ie(u8 *in, char *out)
227{
228 int i = *in;
229 while (i-- > 0) {
230 /* ToDo: conversion to upper case necessary? */
231 *out++ = toupper(hex_asc_hi(*++in));
232 *out++ = toupper(hex_asc_lo(*in));
233 }
234}
235
236/*
237 * retrieve application data structure for an application ID
238 */
239static inline struct gigaset_capi_appl *
240get_appl(struct gigaset_capi_ctr *iif, u16 appl)
241{
242 struct gigaset_capi_appl *ap;
243
244 list_for_each_entry(ap, &iif->appls, ctrlist)
245 if (ap->id == appl)
246 return ap;
247 return NULL;
248}
249
250/*
251 * dump CAPI message to kernel messages for debugging
252 */
253static inline void dump_cmsg(enum debuglevel level, const char *tag, _cmsg *p)
254{
255#ifdef CONFIG_GIGASET_DEBUG
256 _cdebbuf *cdb;
257
258 if (!(gigaset_debuglevel & level))
259 return;
260
261 cdb = capi_cmsg2str(p);
262 if (cdb) {
263 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId, cdb->buf);
264 cdebbuf_free(cdb);
265 } else {
266 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId,
267 capi_cmd2str(p->Command, p->Subcommand));
268 }
269#endif
270}
271
272static inline void dump_rawmsg(enum debuglevel level, const char *tag,
273 unsigned char *data)
274{
275#ifdef CONFIG_GIGASET_DEBUG
276 char *dbgline;
277 int i, l;
278
279 if (!(gigaset_debuglevel & level))
280 return;
281
282 l = CAPIMSG_LEN(data);
283 if (l < 12) {
284 gig_dbg(level, "%s: ??? LEN=%04d", tag, l);
285 return;
286 }
287 gig_dbg(level, "%s: 0x%02x:0x%02x: ID=%03d #0x%04x LEN=%04d NCCI=0x%x",
288 tag, CAPIMSG_COMMAND(data), CAPIMSG_SUBCOMMAND(data),
289 CAPIMSG_APPID(data), CAPIMSG_MSGID(data), l,
290 CAPIMSG_CONTROL(data));
291 l -= 12;
292 dbgline = kmalloc(3*l, GFP_ATOMIC);
293 if (!dbgline)
294 return;
295 for (i = 0; i < l; i++) {
296 dbgline[3*i] = hex_asc_hi(data[12+i]);
297 dbgline[3*i+1] = hex_asc_lo(data[12+i]);
298 dbgline[3*i+2] = ' ';
299 }
300 dbgline[3*l-1] = '\0';
301 gig_dbg(level, " %s", dbgline);
302 kfree(dbgline);
303 if (CAPIMSG_COMMAND(data) == CAPI_DATA_B3 &&
304 (CAPIMSG_SUBCOMMAND(data) == CAPI_REQ ||
305 CAPIMSG_SUBCOMMAND(data) == CAPI_IND) &&
306 CAPIMSG_DATALEN(data) > 0) {
307 l = CAPIMSG_DATALEN(data);
308 dbgline = kmalloc(3*l, GFP_ATOMIC);
309 if (!dbgline)
310 return;
311 data += CAPIMSG_LEN(data);
312 for (i = 0; i < l; i++) {
313 dbgline[3*i] = hex_asc_hi(data[i]);
314 dbgline[3*i+1] = hex_asc_lo(data[i]);
315 dbgline[3*i+2] = ' ';
316 }
317 dbgline[3*l-1] = '\0';
318 gig_dbg(level, " %s", dbgline);
319 kfree(dbgline);
320 }
321#endif
322}
323
324/*
325 * format CAPI IE as string
326 */
327
328static const char *format_ie(const char *ie)
329{
330 static char result[3*MAX_FMT_IE_LEN];
331 int len, count;
332 char *pout = result;
333
334 if (!ie)
335 return "NULL";
336
337 count = len = ie[0];
338 if (count > MAX_FMT_IE_LEN)
339 count = MAX_FMT_IE_LEN-1;
340 while (count--) {
341 *pout++ = hex_asc_hi(*++ie);
342 *pout++ = hex_asc_lo(*ie);
343 *pout++ = ' ';
344 }
345 if (len > MAX_FMT_IE_LEN) {
346 *pout++ = '.';
347 *pout++ = '.';
348 *pout++ = '.';
349 }
350 *--pout = 0;
351 return result;
352}
353
354
355/*
356 * driver interface functions
357 * ==========================
358 */
359
360/**
361 * gigaset_skb_sent() - acknowledge transmission of outgoing skb
362 * @bcs: B channel descriptor structure.
363 * @skb: sent data.
364 *
365 * Called by hardware module {bas,ser,usb}_gigaset when the data in a
366 * skb has been successfully sent, for signalling completion to the LL.
367 */
368void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *dskb)
369{
370 struct cardstate *cs = bcs->cs;
371 struct gigaset_capi_ctr *iif = cs->iif;
372 struct gigaset_capi_appl *ap = bcs->ap;
373 struct sk_buff *cskb;
374 u16 flags;
375
376 /* update statistics */
377 ++bcs->trans_up;
378
379 if (!ap) {
380 dev_err(cs->dev, "%s: no application\n", __func__);
381 return;
382 }
383
384 /* don't send further B3 messages if disconnected */
385 if (ap->connected < APCONN_ACTIVE) {
386 gig_dbg(DEBUG_LLDATA, "disconnected, discarding ack");
387 return;
388 }
389
390 /* ToDo: honor unset "delivery confirmation" bit */
391 flags = CAPIMSG_FLAGS(dskb->head);
392
393 /* build DATA_B3_CONF message */
394 cskb = alloc_skb(CAPI_DATA_B3_CONF_LEN, GFP_ATOMIC);
395 if (!cskb) {
396 dev_err(cs->dev, "%s: out of memory\n", __func__);
397 return;
398 }
399 /* frequent message, avoid _cmsg overhead */
400 CAPIMSG_SETLEN(cskb->data, CAPI_DATA_B3_CONF_LEN);
401 CAPIMSG_SETAPPID(cskb->data, ap->id);
402 CAPIMSG_SETCOMMAND(cskb->data, CAPI_DATA_B3);
403 CAPIMSG_SETSUBCOMMAND(cskb->data, CAPI_CONF);
404 CAPIMSG_SETMSGID(cskb->data, CAPIMSG_MSGID(dskb->head));
405 CAPIMSG_SETCONTROLLER(cskb->data, iif->ctr.cnr);
406 CAPIMSG_SETPLCI_PART(cskb->data, bcs->channel + 1);
407 CAPIMSG_SETNCCI_PART(cskb->data, 1);
408 CAPIMSG_SETHANDLE_CONF(cskb->data, CAPIMSG_HANDLE_REQ(dskb->head));
409 if (flags & ~CAPI_FLAGS_DELIVERY_CONFIRMATION)
410 CAPIMSG_SETINFO_CONF(cskb->data,
411 CapiFlagsNotSupportedByProtocol);
412 else
413 CAPIMSG_SETINFO_CONF(cskb->data, CAPI_NOERROR);
414
415 /* emit message */
416 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_CONF", cskb->data);
417 capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
418}
419EXPORT_SYMBOL_GPL(gigaset_skb_sent);
420
421/**
422 * gigaset_skb_rcvd() - pass received skb to LL
423 * @bcs: B channel descriptor structure.
424 * @skb: received data.
425 *
426 * Called by hardware module {bas,ser,usb}_gigaset when user data has
427 * been successfully received, for passing to the LL.
428 * Warning: skb must not be accessed anymore!
429 */
430void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
431{
432 struct cardstate *cs = bcs->cs;
433 struct gigaset_capi_ctr *iif = cs->iif;
434 struct gigaset_capi_appl *ap = bcs->ap;
435 int len = skb->len;
436
437 /* update statistics */
438 bcs->trans_down++;
439
440 if (!ap) {
441 dev_err(cs->dev, "%s: no application\n", __func__);
442 return;
443 }
444
445 /* don't send further B3 messages if disconnected */
446 if (ap->connected < APCONN_ACTIVE) {
447 gig_dbg(DEBUG_LLDATA, "disconnected, discarding data");
448 dev_kfree_skb(skb);
449 return;
450 }
451
452 /*
453 * prepend DATA_B3_IND message to payload
454 * Parameters: NCCI = 1, all others 0/unused
455 * frequent message, avoid _cmsg overhead
456 */
457 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
458 CAPIMSG_SETLEN(skb->data, CAPI_DATA_B3_REQ_LEN);
459 CAPIMSG_SETAPPID(skb->data, ap->id);
460 CAPIMSG_SETCOMMAND(skb->data, CAPI_DATA_B3);
461 CAPIMSG_SETSUBCOMMAND(skb->data, CAPI_IND);
462 CAPIMSG_SETMSGID(skb->data, ap->nextMessageNumber++);
463 CAPIMSG_SETCONTROLLER(skb->data, iif->ctr.cnr);
464 CAPIMSG_SETPLCI_PART(skb->data, bcs->channel + 1);
465 CAPIMSG_SETNCCI_PART(skb->data, 1);
466 /* Data parameter not used */
467 CAPIMSG_SETDATALEN(skb->data, len);
468 /* Data handle parameter not used */
469 CAPIMSG_SETFLAGS(skb->data, 0);
470 /* Data64 parameter not present */
471
472 /* emit message */
473 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_IND", skb->data);
474 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
475}
476EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
477
478/**
479 * gigaset_isdn_rcv_err() - signal receive error
480 * @bcs: B channel descriptor structure.
481 *
482 * Called by hardware module {bas,ser,usb}_gigaset when a receive error
483 * has occurred, for signalling to the LL.
484 */
485void gigaset_isdn_rcv_err(struct bc_state *bcs)
486{
487 /* if currently ignoring packets, just count down */
488 if (bcs->ignore) {
489 bcs->ignore--;
490 return;
491 }
492
493 /* update statistics */
494 bcs->corrupted++;
495
496 /* ToDo: signal error -> LL */
497}
498EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
499
500/**
501 * gigaset_isdn_icall() - signal incoming call
502 * @at_state: connection state structure.
503 *
504 * Called by main module at tasklet level to notify the LL that an incoming
505 * call has been received. @at_state contains the parameters of the call.
506 *
507 * Return value: call disposition (ICALL_*)
508 */
509int gigaset_isdn_icall(struct at_state_t *at_state)
510{
511 struct cardstate *cs = at_state->cs;
512 struct bc_state *bcs = at_state->bcs;
513 struct gigaset_capi_ctr *iif = cs->iif;
514 struct gigaset_capi_appl *ap;
515 u32 actCIPmask;
516 struct sk_buff *skb;
517 unsigned int msgsize;
518 int i;
519
520 /*
521 * ToDo: signal calls without a free B channel, too
522 * (requires a u8 handle for the at_state structure that can
523 * be stored in the PLCI and used in the CONNECT_RESP message
524 * handler to retrieve it)
525 */
526 if (!bcs)
527 return ICALL_IGNORE;
528
529 /* prepare CONNECT_IND message, using B channel number as PLCI */
530 capi_cmsg_header(&iif->hcmsg, 0, CAPI_CONNECT, CAPI_IND, 0,
531 iif->ctr.cnr | ((bcs->channel + 1) << 8));
532
533 /* minimum size, all structs empty */
534 msgsize = CAPI_CONNECT_IND_BASELEN;
535
536 /* Bearer Capability (mandatory) */
537 if (at_state->str_var[STR_ZBC]) {
538 /* pass on BC from Gigaset */
539 if (encode_ie(at_state->str_var[STR_ZBC], iif->bc_buf,
540 MAX_BC_OCTETS) < 0) {
541 dev_warn(cs->dev, "RING ignored - bad BC %s\n",
542 at_state->str_var[STR_ZBC]);
543 return ICALL_IGNORE;
544 }
545
546 /* look up corresponding CIP value */
547 iif->hcmsg.CIPValue = 0; /* default if nothing found */
548 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
549 if (cip2bchlc[i].bc != NULL &&
550 cip2bchlc[i].hlc == NULL &&
551 !strcmp(cip2bchlc[i].bc,
552 at_state->str_var[STR_ZBC])) {
553 iif->hcmsg.CIPValue = i;
554 break;
555 }
556 } else {
557 /* no BC (internal call): assume CIP 1 (speech, A-law) */
558 iif->hcmsg.CIPValue = 1;
559 encode_ie(cip2bchlc[1].bc, iif->bc_buf, MAX_BC_OCTETS);
560 }
561 iif->hcmsg.BC = iif->bc_buf;
562 msgsize += iif->hcmsg.BC[0];
563
564 /* High Layer Compatibility (optional) */
565 if (at_state->str_var[STR_ZHLC]) {
566 /* pass on HLC from Gigaset */
567 if (encode_ie(at_state->str_var[STR_ZHLC], iif->hlc_buf,
568 MAX_HLC_OCTETS) < 0) {
569 dev_warn(cs->dev, "RING ignored - bad HLC %s\n",
570 at_state->str_var[STR_ZHLC]);
571 return ICALL_IGNORE;
572 }
573 iif->hcmsg.HLC = iif->hlc_buf;
574 msgsize += iif->hcmsg.HLC[0];
575
576 /* look up corresponding CIP value */
577 /* keep BC based CIP value if none found */
578 if (at_state->str_var[STR_ZBC])
579 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
580 if (cip2bchlc[i].hlc != NULL &&
581 !strcmp(cip2bchlc[i].hlc,
582 at_state->str_var[STR_ZHLC]) &&
583 !strcmp(cip2bchlc[i].bc,
584 at_state->str_var[STR_ZBC])) {
585 iif->hcmsg.CIPValue = i;
586 break;
587 }
588 }
589
590 /* Called Party Number (optional) */
591 if (at_state->str_var[STR_ZCPN]) {
592 i = strlen(at_state->str_var[STR_ZCPN]);
593 if (i > MAX_NUMBER_DIGITS) {
594 dev_warn(cs->dev, "RING ignored - bad number %s\n",
595 at_state->str_var[STR_ZBC]);
596 return ICALL_IGNORE;
597 }
598 iif->cdpty_buf[0] = i + 1;
599 iif->cdpty_buf[1] = 0x80; /* type / numbering plan unknown */
600 memcpy(iif->cdpty_buf+2, at_state->str_var[STR_ZCPN], i);
601 iif->hcmsg.CalledPartyNumber = iif->cdpty_buf;
602 msgsize += iif->hcmsg.CalledPartyNumber[0];
603 }
604
605 /* Calling Party Number (optional) */
606 if (at_state->str_var[STR_NMBR]) {
607 i = strlen(at_state->str_var[STR_NMBR]);
608 if (i > MAX_NUMBER_DIGITS) {
609 dev_warn(cs->dev, "RING ignored - bad number %s\n",
610 at_state->str_var[STR_ZBC]);
611 return ICALL_IGNORE;
612 }
613 iif->cgpty_buf[0] = i + 2;
614 iif->cgpty_buf[1] = 0x00; /* type / numbering plan unknown */
615 iif->cgpty_buf[2] = 0x80; /* pres. allowed, not screened */
616 memcpy(iif->cgpty_buf+3, at_state->str_var[STR_NMBR], i);
617 iif->hcmsg.CallingPartyNumber = iif->cgpty_buf;
618 msgsize += iif->hcmsg.CallingPartyNumber[0];
619 }
620
621 /* remaining parameters (not supported, always left NULL):
622 * - CalledPartySubaddress
623 * - CallingPartySubaddress
624 * - AdditionalInfo
625 * - BChannelinformation
626 * - Keypadfacility
627 * - Useruserdata
628 * - Facilitydataarray
629 */
630
631 gig_dbg(DEBUG_CMD, "icall: PLCI %x CIP %d BC %s",
632 iif->hcmsg.adr.adrPLCI, iif->hcmsg.CIPValue,
633 format_ie(iif->hcmsg.BC));
634 gig_dbg(DEBUG_CMD, "icall: HLC %s",
635 format_ie(iif->hcmsg.HLC));
636 gig_dbg(DEBUG_CMD, "icall: CgPty %s",
637 format_ie(iif->hcmsg.CallingPartyNumber));
638 gig_dbg(DEBUG_CMD, "icall: CdPty %s",
639 format_ie(iif->hcmsg.CalledPartyNumber));
640
641 /* scan application list for matching listeners */
642 bcs->ap = NULL;
643 actCIPmask = 1 | (1 << iif->hcmsg.CIPValue);
644 list_for_each_entry(ap, &iif->appls, ctrlist)
645 if (actCIPmask & ap->listenCIPmask) {
646 /* build CONNECT_IND message for this application */
647 iif->hcmsg.ApplId = ap->id;
648 iif->hcmsg.Messagenumber = ap->nextMessageNumber++;
649
650 skb = alloc_skb(msgsize, GFP_ATOMIC);
651 if (!skb) {
652 dev_err(cs->dev, "%s: out of memory\n",
653 __func__);
654 break;
655 }
656 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
657 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
658
659 /* add to listeners on this B channel, update state */
660 ap->bcnext = bcs->ap;
661 bcs->ap = ap;
662 bcs->chstate |= CHS_NOTIFY_LL;
663 ap->connected = APCONN_SETUP;
664
665 /* emit message */
666 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
667 }
668
669 /*
670 * Return "accept" if any listeners.
671 * Gigaset will send ALERTING.
672 * There doesn't seem to be a way to avoid this.
673 */
674 return bcs->ap ? ICALL_ACCEPT : ICALL_IGNORE;
675}
676
677/*
678 * send a DISCONNECT_IND message to an application
679 * does not sleep, clobbers the controller's hcmsg structure
680 */
681static void send_disconnect_ind(struct bc_state *bcs,
682 struct gigaset_capi_appl *ap, u16 reason)
683{
684 struct cardstate *cs = bcs->cs;
685 struct gigaset_capi_ctr *iif = cs->iif;
686 struct sk_buff *skb;
687
688 if (ap->connected == APCONN_NONE)
689 return;
690
691 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT, CAPI_IND,
692 ap->nextMessageNumber++,
693 iif->ctr.cnr | ((bcs->channel + 1) << 8));
694 iif->hcmsg.Reason = reason;
695 skb = alloc_skb(CAPI_DISCONNECT_IND_LEN, GFP_ATOMIC);
696 if (!skb) {
697 dev_err(cs->dev, "%s: out of memory\n", __func__);
698 return;
699 }
700 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, CAPI_DISCONNECT_IND_LEN));
701 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
702 ap->connected = APCONN_NONE;
703 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
704}
705
706/*
707 * send a DISCONNECT_B3_IND message to an application
708 * Parameters: NCCI = 1, NCPI empty, Reason_B3 = 0
709 * does not sleep, clobbers the controller's hcmsg structure
710 */
711static void send_disconnect_b3_ind(struct bc_state *bcs,
712 struct gigaset_capi_appl *ap)
713{
714 struct cardstate *cs = bcs->cs;
715 struct gigaset_capi_ctr *iif = cs->iif;
716 struct sk_buff *skb;
717
718 /* nothing to do if no logical connection active */
719 if (ap->connected < APCONN_ACTIVE)
720 return;
721 ap->connected = APCONN_SETUP;
722
723 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
724 ap->nextMessageNumber++,
725 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
726 skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_ATOMIC);
727 if (!skb) {
728 dev_err(cs->dev, "%s: out of memory\n", __func__);
729 return;
730 }
731 capi_cmsg2message(&iif->hcmsg,
732 __skb_put(skb, CAPI_DISCONNECT_B3_IND_BASELEN));
733 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
734 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
735}
736
737/**
738 * gigaset_isdn_connD() - signal D channel connect
739 * @bcs: B channel descriptor structure.
740 *
741 * Called by main module at tasklet level to notify the LL that the D channel
742 * connection has been established.
743 */
744void gigaset_isdn_connD(struct bc_state *bcs)
745{
746 struct cardstate *cs = bcs->cs;
747 struct gigaset_capi_ctr *iif = cs->iif;
748 struct gigaset_capi_appl *ap = bcs->ap;
749 struct sk_buff *skb;
750 unsigned int msgsize;
751
752 if (!ap) {
753 dev_err(cs->dev, "%s: no application\n", __func__);
754 return;
755 }
756 while (ap->bcnext) {
757 /* this should never happen */
758 dev_warn(cs->dev, "%s: dropping extra application %u\n",
759 __func__, ap->bcnext->id);
760 send_disconnect_ind(bcs, ap->bcnext,
761 CapiCallGivenToOtherApplication);
762 ap->bcnext = ap->bcnext->bcnext;
763 }
764 if (ap->connected == APCONN_NONE) {
765 dev_warn(cs->dev, "%s: application %u not connected\n",
766 __func__, ap->id);
767 return;
768 }
769
770 /* prepare CONNECT_ACTIVE_IND message
771 * Note: LLC not supported by device
772 */
773 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_CONNECT_ACTIVE, CAPI_IND,
774 ap->nextMessageNumber++,
775 iif->ctr.cnr | ((bcs->channel + 1) << 8));
776
777 /* minimum size, all structs empty */
778 msgsize = CAPI_CONNECT_ACTIVE_IND_BASELEN;
779
780 /* ToDo: set parameter: Connected number
781 * (requires ev-layer state machine extension to collect
782 * ZCON device reply)
783 */
784
785 /* build and emit CONNECT_ACTIVE_IND message */
786 skb = alloc_skb(msgsize, GFP_ATOMIC);
787 if (!skb) {
788 dev_err(cs->dev, "%s: out of memory\n", __func__);
789 return;
790 }
791 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
792 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
793 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
794}
795
796/**
797 * gigaset_isdn_hupD() - signal D channel hangup
798 * @bcs: B channel descriptor structure.
799 *
800 * Called by main module at tasklet level to notify the LL that the D channel
801 * connection has been shut down.
802 */
803void gigaset_isdn_hupD(struct bc_state *bcs)
804{
805 struct gigaset_capi_appl *ap;
806
807 /*
808 * ToDo: pass on reason code reported by device
809 * (requires ev-layer state machine extension to collect
810 * ZCAU device reply)
811 */
812 for (ap = bcs->ap; ap != NULL; ap = ap->bcnext) {
813 send_disconnect_b3_ind(bcs, ap);
814 send_disconnect_ind(bcs, ap, 0);
815 }
816 bcs->ap = NULL;
817}
818
819/**
820 * gigaset_isdn_connB() - signal B channel connect
821 * @bcs: B channel descriptor structure.
822 *
823 * Called by main module at tasklet level to notify the LL that the B channel
824 * connection has been established.
825 */
826void gigaset_isdn_connB(struct bc_state *bcs)
827{
828 struct cardstate *cs = bcs->cs;
829 struct gigaset_capi_ctr *iif = cs->iif;
830 struct gigaset_capi_appl *ap = bcs->ap;
831 struct sk_buff *skb;
832 unsigned int msgsize;
833 u8 command;
834
835 if (!ap) {
836 dev_err(cs->dev, "%s: no application\n", __func__);
837 return;
838 }
839 while (ap->bcnext) {
840 /* this should never happen */
841 dev_warn(cs->dev, "%s: dropping extra application %u\n",
842 __func__, ap->bcnext->id);
843 send_disconnect_ind(bcs, ap->bcnext,
844 CapiCallGivenToOtherApplication);
845 ap->bcnext = ap->bcnext->bcnext;
846 }
847 if (!ap->connected) {
848 dev_warn(cs->dev, "%s: application %u not connected\n",
849 __func__, ap->id);
850 return;
851 }
852
853 /*
854 * emit CONNECT_B3_ACTIVE_IND if we already got CONNECT_B3_REQ;
855 * otherwise we have to emit CONNECT_B3_IND first, and follow up with
856 * CONNECT_B3_ACTIVE_IND in reply to CONNECT_B3_RESP
857 * Parameters in both cases always: NCCI = 1, NCPI empty
858 */
859 if (ap->connected >= APCONN_ACTIVE) {
860 command = CAPI_CONNECT_B3_ACTIVE;
861 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
862 } else {
863 command = CAPI_CONNECT_B3;
864 msgsize = CAPI_CONNECT_B3_IND_BASELEN;
865 }
866 capi_cmsg_header(&iif->hcmsg, ap->id, command, CAPI_IND,
867 ap->nextMessageNumber++,
868 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
869 skb = alloc_skb(msgsize, GFP_ATOMIC);
870 if (!skb) {
871 dev_err(cs->dev, "%s: out of memory\n", __func__);
872 return;
873 }
874 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
875 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
876 ap->connected = APCONN_ACTIVE;
877 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
878}
879
880/**
881 * gigaset_isdn_hupB() - signal B channel hangup
882 * @bcs: B channel descriptor structure.
883 *
884 * Called by main module to notify the LL that the B channel connection has
885 * been shut down.
886 */
887void gigaset_isdn_hupB(struct bc_state *bcs)
888{
889 struct cardstate *cs = bcs->cs;
890 struct gigaset_capi_appl *ap = bcs->ap;
891
892 /* ToDo: assure order of DISCONNECT_B3_IND and DISCONNECT_IND ? */
893
894 if (!ap) {
895 dev_err(cs->dev, "%s: no application\n", __func__);
896 return;
897 }
898
899 send_disconnect_b3_ind(bcs, ap);
900}
901
902/**
903 * gigaset_isdn_start() - signal device availability
904 * @cs: device descriptor structure.
905 *
906 * Called by main module to notify the LL that the device is available for
907 * use.
908 */
909void gigaset_isdn_start(struct cardstate *cs)
910{
911 struct gigaset_capi_ctr *iif = cs->iif;
912
913 /* fill profile data: manufacturer name */
914 strcpy(iif->ctr.manu, "Siemens");
915 /* CAPI and device version */
916 iif->ctr.version.majorversion = 2; /* CAPI 2.0 */
917 iif->ctr.version.minorversion = 0;
918 /* ToDo: check/assert cs->gotfwver? */
919 iif->ctr.version.majormanuversion = cs->fwver[0];
920 iif->ctr.version.minormanuversion = cs->fwver[1];
921 /* number of B channels supported */
922 iif->ctr.profile.nbchannel = cs->channels;
923 /* global options: internal controller, supplementary services */
924 iif->ctr.profile.goptions = 0x11;
925 /* B1 protocols: 64 kbit/s HDLC or transparent */
926 iif->ctr.profile.support1 = 0x03;
927 /* B2 protocols: transparent only */
928 /* ToDo: X.75 SLP ? */
929 iif->ctr.profile.support2 = 0x02;
930 /* B3 protocols: transparent only */
931 iif->ctr.profile.support3 = 0x01;
932 /* no serial number */
933 strcpy(iif->ctr.serial, "0");
934 capi_ctr_ready(&iif->ctr);
935}
936
937/**
938 * gigaset_isdn_stop() - signal device unavailability
939 * @cs: device descriptor structure.
940 *
941 * Called by main module to notify the LL that the device is no longer
942 * available for use.
943 */
944void gigaset_isdn_stop(struct cardstate *cs)
945{
946 struct gigaset_capi_ctr *iif = cs->iif;
947 capi_ctr_down(&iif->ctr);
948}
949
950/*
951 * kernel CAPI callback methods
952 * ============================
953 */
954
955/*
956 * load firmware
957 */
958static int gigaset_load_firmware(struct capi_ctr *ctr, capiloaddata *data)
959{
960 struct cardstate *cs = ctr->driverdata;
961
962 /* AVM specific operation, not needed for Gigaset -- ignore */
963 dev_notice(cs->dev, "load_firmware ignored\n");
964
965 return 0;
966}
967
968/*
969 * reset (deactivate) controller
970 */
971static void gigaset_reset_ctr(struct capi_ctr *ctr)
972{
973 struct cardstate *cs = ctr->driverdata;
974
975 /* AVM specific operation, not needed for Gigaset -- ignore */
976 dev_notice(cs->dev, "reset_ctr ignored\n");
977}
978
979/*
980 * register CAPI application
981 */
982static void gigaset_register_appl(struct capi_ctr *ctr, u16 appl,
983 capi_register_params *rp)
984{
985 struct gigaset_capi_ctr *iif
986 = container_of(ctr, struct gigaset_capi_ctr, ctr);
987 struct cardstate *cs = ctr->driverdata;
988 struct gigaset_capi_appl *ap;
989
990 list_for_each_entry(ap, &iif->appls, ctrlist)
991 if (ap->id == appl) {
992 dev_notice(cs->dev,
993 "application %u already registered\n", appl);
994 return;
995 }
996
997 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
998 if (!ap) {
999 dev_err(cs->dev, "%s: out of memory\n", __func__);
1000 return;
1001 }
1002 ap->id = appl;
1003
1004 list_add(&ap->ctrlist, &iif->appls);
1005}
1006
1007/*
1008 * release CAPI application
1009 */
1010static void gigaset_release_appl(struct capi_ctr *ctr, u16 appl)
1011{
1012 struct gigaset_capi_ctr *iif
1013 = container_of(ctr, struct gigaset_capi_ctr, ctr);
1014 struct cardstate *cs = iif->ctr.driverdata;
1015 struct gigaset_capi_appl *ap, *tmp;
1016
1017 list_for_each_entry_safe(ap, tmp, &iif->appls, ctrlist)
1018 if (ap->id == appl) {
1019 if (ap->connected != APCONN_NONE) {
1020 dev_err(cs->dev,
1021 "%s: application %u still connected\n",
1022 __func__, ap->id);
1023 /* ToDo: clear active connection */
1024 }
1025 list_del(&ap->ctrlist);
1026 kfree(ap);
1027 }
1028
1029}
1030
1031/*
1032 * =====================================================================
1033 * outgoing CAPI message handler
1034 * =====================================================================
1035 */
1036
1037/*
1038 * helper function: emit reply message with given Info value
1039 */
1040static void send_conf(struct gigaset_capi_ctr *iif,
1041 struct gigaset_capi_appl *ap,
1042 struct sk_buff *skb,
1043 u16 info)
1044{
1045 /*
1046 * _CONF replies always only have NCCI and Info parameters
1047 * so they'll fit into the _REQ message skb
1048 */
1049 capi_cmsg_answer(&iif->acmsg);
1050 iif->acmsg.Info = info;
1051 capi_cmsg2message(&iif->acmsg, skb->data);
1052 __skb_trim(skb, CAPI_STDCONF_LEN);
1053 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1054 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1055}
1056
1057/*
1058 * process FACILITY_REQ message
1059 */
1060static void do_facility_req(struct gigaset_capi_ctr *iif,
1061 struct gigaset_capi_appl *ap,
1062 struct sk_buff *skb)
1063{
1064 struct cardstate *cs = iif->ctr.driverdata;
1065 struct sk_buff *cskb;
1066 u8 *pparam;
1067 unsigned int msgsize = CAPI_FACILITY_CONF_BASELEN;
1068 u16 function, info;
1069 static u8 confparam[10]; /* max. 9 octets + length byte */
1070
1071 /* decode message */
1072 capi_message2cmsg(&iif->acmsg, skb->data);
1073 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1074
1075 /*
1076 * Facility Request Parameter is not decoded by capi_message2cmsg()
1077 * encoding depends on Facility Selector
1078 */
1079 switch (iif->acmsg.FacilitySelector) {
1080 case CAPI_FACILITY_DTMF: /* ToDo */
1081 info = CapiFacilityNotSupported;
1082 confparam[0] = 2; /* length */
1083 /* DTMF information: Unknown DTMF request */
1084 capimsg_setu16(confparam, 1, 2);
1085 break;
1086
1087 case CAPI_FACILITY_V42BIS: /* not supported */
1088 info = CapiFacilityNotSupported;
1089 confparam[0] = 2; /* length */
1090 /* V.42 bis information: not available */
1091 capimsg_setu16(confparam, 1, 1);
1092 break;
1093
1094 case CAPI_FACILITY_SUPPSVC:
1095 /* decode Function parameter */
1096 pparam = iif->acmsg.FacilityRequestParameter;
1097 if (pparam == NULL || *pparam < 2) {
1098 dev_notice(cs->dev, "%s: %s missing\n", "FACILITY_REQ",
1099 "Facility Request Parameter");
1100 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
1101 return;
1102 }
1103 function = CAPIMSG_U16(pparam, 1);
1104 switch (function) {
1105 case CAPI_SUPPSVC_GETSUPPORTED:
1106 info = CapiSuccess;
1107 /* Supplementary Service specific parameter */
1108 confparam[3] = 6; /* length */
1109 /* Supplementary services info: Success */
1110 capimsg_setu16(confparam, 4, CapiSuccess);
1111 /* Supported Services: none */
1112 capimsg_setu32(confparam, 6, 0);
1113 break;
1114 /* ToDo: add supported services */
1115 default:
1116 info = CapiFacilitySpecificFunctionNotSupported;
1117 /* Supplementary Service specific parameter */
1118 confparam[3] = 2; /* length */
1119 /* Supplementary services info: not supported */
1120 capimsg_setu16(confparam, 4,
1121 CapiSupplementaryServiceNotSupported);
1122 }
1123
1124 /* Facility confirmation parameter */
1125 confparam[0] = confparam[3] + 3; /* total length */
1126 /* Function: copy from _REQ message */
1127 capimsg_setu16(confparam, 1, function);
1128 /* Supplementary Service specific parameter already set above */
1129 break;
1130
1131 case CAPI_FACILITY_WAKEUP: /* ToDo */
1132 info = CapiFacilityNotSupported;
1133 confparam[0] = 2; /* length */
1134 /* Number of accepted awake request parameters: 0 */
1135 capimsg_setu16(confparam, 1, 0);
1136 break;
1137
1138 default:
1139 info = CapiFacilityNotSupported;
1140 confparam[0] = 0; /* empty struct */
1141 }
1142
1143 /* send FACILITY_CONF with given Info and confirmation parameter */
1144 capi_cmsg_answer(&iif->acmsg);
1145 iif->acmsg.Info = info;
1146 iif->acmsg.FacilityConfirmationParameter = confparam;
1147 msgsize += confparam[0]; /* length */
1148 cskb = alloc_skb(msgsize, GFP_ATOMIC);
1149 if (!cskb) {
1150 dev_err(cs->dev, "%s: out of memory\n", __func__);
1151 return;
1152 }
1153 capi_cmsg2message(&iif->acmsg, __skb_put(cskb, msgsize));
1154 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1155 capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
1156}
1157
1158
1159/*
1160 * process LISTEN_REQ message
1161 * just store the masks in the application data structure
1162 */
1163static void do_listen_req(struct gigaset_capi_ctr *iif,
1164 struct gigaset_capi_appl *ap,
1165 struct sk_buff *skb)
1166{
1167 /* decode message */
1168 capi_message2cmsg(&iif->acmsg, skb->data);
1169 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1170
1171 /* store listening parameters */
1172 ap->listenInfoMask = iif->acmsg.InfoMask;
1173 ap->listenCIPmask = iif->acmsg.CIPmask;
1174 send_conf(iif, ap, skb, CapiSuccess);
1175}
1176
1177/*
1178 * process ALERT_REQ message
1179 * nothing to do, Gigaset always alerts anyway
1180 */
1181static void do_alert_req(struct gigaset_capi_ctr *iif,
1182 struct gigaset_capi_appl *ap,
1183 struct sk_buff *skb)
1184{
1185 /* decode message */
1186 capi_message2cmsg(&iif->acmsg, skb->data);
1187 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1188 send_conf(iif, ap, skb, CapiAlertAlreadySent);
1189}
1190
1191/*
1192 * process CONNECT_REQ message
1193 * allocate a B channel, prepare dial commands, queue a DIAL event,
1194 * emit CONNECT_CONF reply
1195 */
1196static void do_connect_req(struct gigaset_capi_ctr *iif,
1197 struct gigaset_capi_appl *ap,
1198 struct sk_buff *skb)
1199{
1200 struct cardstate *cs = iif->ctr.driverdata;
1201 _cmsg *cmsg = &iif->acmsg;
1202 struct bc_state *bcs;
1203 char **commands;
1204 char *s;
1205 u8 *pp;
1206 int i, l;
1207 u16 info;
1208
1209 /* decode message */
1210 capi_message2cmsg(&iif->acmsg, skb->data);
1211 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1212
1213 /* get free B channel & construct PLCI */
1214 bcs = gigaset_get_free_channel(cs);
1215 if (!bcs) {
1216 dev_notice(cs->dev, "%s: no B channel available\n",
1217 "CONNECT_REQ");
1218 send_conf(iif, ap, skb, CapiNoPlciAvailable);
1219 return;
1220 }
1221 ap->bcnext = NULL;
1222 bcs->ap = ap;
1223 cmsg->adr.adrPLCI |= (bcs->channel + 1) << 8;
1224
1225 /* build command table */
1226 commands = kzalloc(AT_NUM*(sizeof *commands), GFP_KERNEL);
1227 if (!commands)
1228 goto oom;
1229
1230 /* encode parameter: Called party number */
1231 pp = cmsg->CalledPartyNumber;
1232 if (pp == NULL || *pp == 0) {
1233 dev_notice(cs->dev, "%s: %s missing\n",
1234 "CONNECT_REQ", "Called party number");
1235 info = CapiIllMessageParmCoding;
1236 goto error;
1237 }
1238 l = *pp++;
1239 /* check type of number/numbering plan byte */
1240 switch (*pp) {
1241 case 0x80: /* unknown type / unknown numbering plan */
1242 case 0x81: /* unknown type / ISDN/Telephony numbering plan */
1243 break;
1244 default: /* others: warn about potential misinterpretation */
1245 dev_notice(cs->dev, "%s: %s type/plan 0x%02x unsupported\n",
1246 "CONNECT_REQ", "Called party number", *pp);
1247 }
1248 pp++;
1249 l--;
1250 /* translate "**" internal call prefix to CTP value */
1251 if (l >= 2 && pp[0] == '*' && pp[1] == '*') {
1252 s = "^SCTP=0\r";
1253 pp += 2;
1254 l -= 2;
1255 } else {
1256 s = "^SCTP=1\r";
1257 }
1258 commands[AT_TYPE] = kstrdup(s, GFP_KERNEL);
1259 if (!commands[AT_TYPE])
1260 goto oom;
1261 commands[AT_DIAL] = kmalloc(l+3, GFP_KERNEL);
1262 if (!commands[AT_DIAL])
1263 goto oom;
1264 snprintf(commands[AT_DIAL], l+3, "D%*s\r", l, pp);
1265
1266 /* encode parameter: Calling party number */
1267 pp = cmsg->CallingPartyNumber;
1268 if (pp != NULL && *pp > 0) {
1269 l = *pp++;
1270
1271 /* check type of number/numbering plan byte */
1272 /* ToDo: allow for/handle Ext=1? */
1273 switch (*pp) {
1274 case 0x00: /* unknown type / unknown numbering plan */
1275 case 0x01: /* unknown type / ISDN/Telephony num. plan */
1276 break;
1277 default:
1278 dev_notice(cs->dev,
1279 "%s: %s type/plan 0x%02x unsupported\n",
1280 "CONNECT_REQ", "Calling party number", *pp);
1281 }
1282 pp++;
1283 l--;
1284
1285 /* check presentation indicator */
1286 if (!l) {
1287 dev_notice(cs->dev, "%s: %s IE truncated\n",
1288 "CONNECT_REQ", "Calling party number");
1289 info = CapiIllMessageParmCoding;
1290 goto error;
1291 }
1292 switch (*pp & 0xfc) { /* ignore Screening indicator */
1293 case 0x80: /* Presentation allowed */
1294 s = "^SCLIP=1\r";
1295 break;
1296 case 0xa0: /* Presentation restricted */
1297 s = "^SCLIP=0\r";
1298 break;
1299 default:
1300 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1301 "CONNECT_REQ",
1302 "Presentation/Screening indicator",
1303 *pp);
1304 s = "^SCLIP=1\r";
1305 }
1306 commands[AT_CLIP] = kstrdup(s, GFP_KERNEL);
1307 if (!commands[AT_CLIP])
1308 goto oom;
1309 pp++;
1310 l--;
1311
1312 if (l) {
1313 /* number */
1314 commands[AT_MSN] = kmalloc(l+8, GFP_KERNEL);
1315 if (!commands[AT_MSN])
1316 goto oom;
1317 snprintf(commands[AT_MSN], l+8, "^SMSN=%*s\r", l, pp);
1318 }
1319 }
1320
1321 /* check parameter: CIP Value */
1322 if (cmsg->CIPValue > ARRAY_SIZE(cip2bchlc) ||
1323 (cmsg->CIPValue > 0 && cip2bchlc[cmsg->CIPValue].bc == NULL)) {
1324 dev_notice(cs->dev, "%s: unknown CIP value %d\n",
1325 "CONNECT_REQ", cmsg->CIPValue);
1326 info = CapiCipValueUnknown;
1327 goto error;
1328 }
1329
1330 /* check/encode parameter: BC */
1331 if (cmsg->BC && cmsg->BC[0]) {
1332 /* explicit BC overrides CIP */
1333 l = 2*cmsg->BC[0] + 7;
1334 commands[AT_BC] = kmalloc(l, GFP_KERNEL);
1335 if (!commands[AT_BC])
1336 goto oom;
1337 strcpy(commands[AT_BC], "^SBC=");
1338 decode_ie(cmsg->BC, commands[AT_BC]+5);
1339 strcpy(commands[AT_BC] + l - 2, "\r");
1340 } else if (cip2bchlc[cmsg->CIPValue].bc) {
1341 l = strlen(cip2bchlc[cmsg->CIPValue].bc) + 7;
1342 commands[AT_BC] = kmalloc(l, GFP_KERNEL);
1343 if (!commands[AT_BC])
1344 goto oom;
1345 snprintf(commands[AT_BC], l, "^SBC=%s\r",
1346 cip2bchlc[cmsg->CIPValue].bc);
1347 }
1348
1349 /* check/encode parameter: HLC */
1350 if (cmsg->HLC && cmsg->HLC[0]) {
1351 /* explicit HLC overrides CIP */
1352 l = 2*cmsg->HLC[0] + 7;
1353 commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
1354 if (!commands[AT_HLC])
1355 goto oom;
1356 strcpy(commands[AT_HLC], "^SHLC=");
1357 decode_ie(cmsg->HLC, commands[AT_HLC]+5);
1358 strcpy(commands[AT_HLC] + l - 2, "\r");
1359 } else if (cip2bchlc[cmsg->CIPValue].hlc) {
1360 l = strlen(cip2bchlc[cmsg->CIPValue].hlc) + 7;
1361 commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
1362 if (!commands[AT_HLC])
1363 goto oom;
1364 snprintf(commands[AT_HLC], l, "^SHLC=%s\r",
1365 cip2bchlc[cmsg->CIPValue].hlc);
1366 }
1367
1368 /* check/encode parameter: B Protocol */
1369 if (cmsg->BProtocol == CAPI_DEFAULT) {
1370 bcs->proto2 = L2_HDLC;
1371 dev_warn(cs->dev,
1372 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1373 } else {
1374 switch (cmsg->B1protocol) {
1375 case 0:
1376 bcs->proto2 = L2_HDLC;
1377 break;
1378 case 1:
1379 bcs->proto2 = L2_BITSYNC;
1380 break;
1381 default:
1382 dev_warn(cs->dev,
1383 "B1 Protocol %u unsupported, using Transparent\n",
1384 cmsg->B1protocol);
1385 bcs->proto2 = L2_BITSYNC;
1386 }
1387 if (cmsg->B2protocol != 1)
1388 dev_warn(cs->dev,
1389 "B2 Protocol %u unsupported, using Transparent\n",
1390 cmsg->B2protocol);
1391 if (cmsg->B3protocol != 0)
1392 dev_warn(cs->dev,
1393 "B3 Protocol %u unsupported, using Transparent\n",
1394 cmsg->B3protocol);
1395 ignore_cstruct_param(cs, cmsg->B1configuration,
1396 "CONNECT_REQ", "B1 Configuration");
1397 ignore_cstruct_param(cs, cmsg->B2configuration,
1398 "CONNECT_REQ", "B2 Configuration");
1399 ignore_cstruct_param(cs, cmsg->B3configuration,
1400 "CONNECT_REQ", "B3 Configuration");
1401 }
1402 commands[AT_PROTO] = kmalloc(9, GFP_KERNEL);
1403 if (!commands[AT_PROTO])
1404 goto oom;
1405 snprintf(commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2);
1406
1407 /* ToDo: check/encode remaining parameters */
1408 ignore_cstruct_param(cs, cmsg->CalledPartySubaddress,
1409 "CONNECT_REQ", "Called pty subaddr");
1410 ignore_cstruct_param(cs, cmsg->CallingPartySubaddress,
1411 "CONNECT_REQ", "Calling pty subaddr");
1412 ignore_cstruct_param(cs, cmsg->LLC,
1413 "CONNECT_REQ", "LLC");
1414 ignore_cmstruct_param(cs, cmsg->AdditionalInfo,
1415 "CONNECT_REQ", "Additional Info");
1416
1417 /* encode parameter: B channel to use */
1418 commands[AT_ISO] = kmalloc(9, GFP_KERNEL);
1419 if (!commands[AT_ISO])
1420 goto oom;
1421 snprintf(commands[AT_ISO], 9, "^SISO=%u\r",
1422 (unsigned) bcs->channel + 1);
1423
1424 /* queue & schedule EV_DIAL event */
1425 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands,
1426 bcs->at_state.seq_index, NULL))
1427 goto oom;
1428 gig_dbg(DEBUG_CMD, "scheduling DIAL");
1429 gigaset_schedule_event(cs);
1430 ap->connected = APCONN_SETUP;
1431 send_conf(iif, ap, skb, CapiSuccess);
1432 return;
1433
1434oom:
1435 dev_err(cs->dev, "%s: out of memory\n", __func__);
1436 info = CAPI_MSGOSRESOURCEERR;
1437error:
1438 if (commands)
1439 for (i = 0; i < AT_NUM; i++)
1440 kfree(commands[i]);
1441 kfree(commands);
1442 gigaset_free_channel(bcs);
1443 send_conf(iif, ap, skb, info);
1444}
1445
1446/*
1447 * process CONNECT_RESP message
1448 * checks protocol parameters and queues an ACCEPT or HUP event
1449 */
1450static void do_connect_resp(struct gigaset_capi_ctr *iif,
1451 struct gigaset_capi_appl *ap,
1452 struct sk_buff *skb)
1453{
1454 struct cardstate *cs = iif->ctr.driverdata;
1455 _cmsg *cmsg = &iif->acmsg;
1456 struct bc_state *bcs;
1457 struct gigaset_capi_appl *oap;
1458 int channel;
1459
1460 /* decode message */
1461 capi_message2cmsg(&iif->acmsg, skb->data);
1462 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1463 dev_kfree_skb(skb);
1464
1465 /* extract and check channel number from PLCI */
1466 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1467 if (!channel || channel > cs->channels) {
1468 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1469 "CONNECT_RESP", "PLCI", cmsg->adr.adrPLCI);
1470 return;
1471 }
1472 bcs = cs->bcs + channel - 1;
1473
1474 switch (cmsg->Reject) {
1475 case 0: /* Accept */
1476 /* drop all competing applications, keep only this one */
1477 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
1478 if (oap != ap)
1479 send_disconnect_ind(bcs, oap,
1480 CapiCallGivenToOtherApplication);
1481 ap->bcnext = NULL;
1482 bcs->ap = ap;
1483 bcs->chstate |= CHS_NOTIFY_LL;
1484
1485 /* check/encode B channel protocol */
1486 if (cmsg->BProtocol == CAPI_DEFAULT) {
1487 bcs->proto2 = L2_HDLC;
1488 dev_warn(cs->dev,
1489 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1490 } else {
1491 switch (cmsg->B1protocol) {
1492 case 0:
1493 bcs->proto2 = L2_HDLC;
1494 break;
1495 case 1:
1496 bcs->proto2 = L2_BITSYNC;
1497 break;
1498 default:
1499 dev_warn(cs->dev,
1500 "B1 Protocol %u unsupported, using Transparent\n",
1501 cmsg->B1protocol);
1502 bcs->proto2 = L2_BITSYNC;
1503 }
1504 if (cmsg->B2protocol != 1)
1505 dev_warn(cs->dev,
1506 "B2 Protocol %u unsupported, using Transparent\n",
1507 cmsg->B2protocol);
1508 if (cmsg->B3protocol != 0)
1509 dev_warn(cs->dev,
1510 "B3 Protocol %u unsupported, using Transparent\n",
1511 cmsg->B3protocol);
1512 ignore_cstruct_param(cs, cmsg->B1configuration,
1513 "CONNECT_RESP", "B1 Configuration");
1514 ignore_cstruct_param(cs, cmsg->B2configuration,
1515 "CONNECT_RESP", "B2 Configuration");
1516 ignore_cstruct_param(cs, cmsg->B3configuration,
1517 "CONNECT_RESP", "B3 Configuration");
1518 }
1519
1520 /* ToDo: check/encode remaining parameters */
1521 ignore_cstruct_param(cs, cmsg->ConnectedNumber,
1522 "CONNECT_RESP", "Connected Number");
1523 ignore_cstruct_param(cs, cmsg->ConnectedSubaddress,
1524 "CONNECT_RESP", "Connected Subaddress");
1525 ignore_cstruct_param(cs, cmsg->LLC,
1526 "CONNECT_RESP", "LLC");
1527 ignore_cmstruct_param(cs, cmsg->AdditionalInfo,
1528 "CONNECT_RESP", "Additional Info");
1529
1530 /* Accept call */
1531 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1532 EV_ACCEPT, NULL, 0, NULL))
1533 return;
1534 gig_dbg(DEBUG_CMD, "scheduling ACCEPT");
1535 gigaset_schedule_event(cs);
1536 return;
1537
1538 case 1: /* Ignore */
1539 /* send DISCONNECT_IND to this application */
1540 send_disconnect_ind(bcs, ap, 0);
1541
1542 /* remove it from the list of listening apps */
1543 if (bcs->ap == ap) {
1544 bcs->ap = ap->bcnext;
1545 if (bcs->ap == NULL)
1546 /* last one: stop ev-layer hupD notifications */
1547 bcs->chstate &= ~CHS_NOTIFY_LL;
1548 return;
1549 }
1550 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext) {
1551 if (oap->bcnext == ap) {
1552 oap->bcnext = oap->bcnext->bcnext;
1553 return;
1554 }
1555 }
1556 dev_err(cs->dev, "%s: application %u not found\n",
1557 __func__, ap->id);
1558 return;
1559
1560 default: /* Reject */
1561 /* drop all competing applications, keep only this one */
1562 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
1563 if (oap != ap)
1564 send_disconnect_ind(bcs, oap,
1565 CapiCallGivenToOtherApplication);
1566 ap->bcnext = NULL;
1567 bcs->ap = ap;
1568
1569 /* reject call - will trigger DISCONNECT_IND for this app */
1570 dev_info(cs->dev, "%s: Reject=%x\n",
1571 "CONNECT_RESP", cmsg->Reject);
1572 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1573 EV_HUP, NULL, 0, NULL))
1574 return;
1575 gig_dbg(DEBUG_CMD, "scheduling HUP");
1576 gigaset_schedule_event(cs);
1577 return;
1578 }
1579}
1580
1581/*
1582 * process CONNECT_B3_REQ message
1583 * build NCCI and emit CONNECT_B3_CONF reply
1584 */
1585static void do_connect_b3_req(struct gigaset_capi_ctr *iif,
1586 struct gigaset_capi_appl *ap,
1587 struct sk_buff *skb)
1588{
1589 struct cardstate *cs = iif->ctr.driverdata;
1590 int channel;
1591
1592 /* decode message */
1593 capi_message2cmsg(&iif->acmsg, skb->data);
1594 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1595
1596 /* extract and check channel number from PLCI */
1597 channel = (iif->acmsg.adr.adrPLCI >> 8) & 0xff;
1598 if (!channel || channel > cs->channels) {
1599 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1600 "CONNECT_B3_REQ", "PLCI", iif->acmsg.adr.adrPLCI);
1601 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1602 return;
1603 }
1604
1605 /* mark logical connection active */
1606 ap->connected = APCONN_ACTIVE;
1607
1608 /* build NCCI: always 1 (one B3 connection only) */
1609 iif->acmsg.adr.adrNCCI |= 1 << 16;
1610
1611 /* NCPI parameter: not applicable for B3 Transparent */
1612 ignore_cstruct_param(cs, iif->acmsg.NCPI,
1613 "CONNECT_B3_REQ", "NCPI");
1614 send_conf(iif, ap, skb,
1615 (iif->acmsg.NCPI && iif->acmsg.NCPI[0]) ?
1616 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1617}
1618
1619/*
1620 * process CONNECT_B3_RESP message
1621 * Depending on the Reject parameter, either emit CONNECT_B3_ACTIVE_IND
1622 * or queue EV_HUP and emit DISCONNECT_B3_IND.
1623 * The emitted message is always shorter than the received one,
1624 * allowing to reuse the skb.
1625 */
1626static void do_connect_b3_resp(struct gigaset_capi_ctr *iif,
1627 struct gigaset_capi_appl *ap,
1628 struct sk_buff *skb)
1629{
1630 struct cardstate *cs = iif->ctr.driverdata;
1631 struct bc_state *bcs = NULL;
1632 int channel;
1633 unsigned int msgsize;
1634 u8 command;
1635
1636 /* decode message */
1637 capi_message2cmsg(&iif->acmsg, skb->data);
1638 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1639
1640 /* extract and check channel number and NCCI */
1641 channel = (iif->acmsg.adr.adrNCCI >> 8) & 0xff;
1642 if (!channel || channel > cs->channels ||
1643 ((iif->acmsg.adr.adrNCCI >> 16) & 0xffff) != 1) {
1644 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1645 "CONNECT_B3_RESP", "NCCI", iif->acmsg.adr.adrNCCI);
1646 dev_kfree_skb(skb);
1647 return;
1648 }
1649 bcs = &cs->bcs[channel-1];
1650
1651 if (iif->acmsg.Reject) {
1652 /* Reject: clear B3 connect received flag */
1653 ap->connected = APCONN_SETUP;
1654
1655 /* trigger hangup, causing eventual DISCONNECT_IND */
1656 if (!gigaset_add_event(cs, &bcs->at_state,
1657 EV_HUP, NULL, 0, NULL)) {
1658 dev_err(cs->dev, "%s: out of memory\n", __func__);
1659 dev_kfree_skb(skb);
1660 return;
1661 }
1662 gig_dbg(DEBUG_CMD, "scheduling HUP");
1663 gigaset_schedule_event(cs);
1664
1665 /* emit DISCONNECT_B3_IND */
1666 command = CAPI_DISCONNECT_B3;
1667 msgsize = CAPI_DISCONNECT_B3_IND_BASELEN;
1668 } else {
1669 /*
1670 * Accept: emit CONNECT_B3_ACTIVE_IND immediately, as
1671 * we only send CONNECT_B3_IND if the B channel is up
1672 */
1673 command = CAPI_CONNECT_B3_ACTIVE;
1674 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
1675 }
1676 capi_cmsg_header(&iif->acmsg, ap->id, command, CAPI_IND,
1677 ap->nextMessageNumber++, iif->acmsg.adr.adrNCCI);
1678 __skb_trim(skb, msgsize);
1679 capi_cmsg2message(&iif->acmsg, skb->data);
1680 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1681 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1682}
1683
1684/*
1685 * process DISCONNECT_REQ message
1686 * schedule EV_HUP and emit DISCONNECT_B3_IND if necessary,
1687 * emit DISCONNECT_CONF reply
1688 */
1689static void do_disconnect_req(struct gigaset_capi_ctr *iif,
1690 struct gigaset_capi_appl *ap,
1691 struct sk_buff *skb)
1692{
1693 struct cardstate *cs = iif->ctr.driverdata;
1694 struct bc_state *bcs;
1695 _cmsg *b3cmsg;
1696 struct sk_buff *b3skb;
1697 int channel;
1698
1699 /* decode message */
1700 capi_message2cmsg(&iif->acmsg, skb->data);
1701 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1702
1703 /* extract and check channel number from PLCI */
1704 channel = (iif->acmsg.adr.adrPLCI >> 8) & 0xff;
1705 if (!channel || channel > cs->channels) {
1706 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1707 "DISCONNECT_REQ", "PLCI", iif->acmsg.adr.adrPLCI);
1708 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1709 return;
1710 }
1711 bcs = cs->bcs + channel - 1;
1712
1713 /* ToDo: process parameter: Additional info */
1714 ignore_cmstruct_param(cs, iif->acmsg.AdditionalInfo,
1715 "DISCONNECT_REQ", "Additional Info");
1716
1717 /* skip if DISCONNECT_IND already sent */
1718 if (!ap->connected)
1719 return;
1720
1721 /* check for active logical connection */
1722 if (ap->connected >= APCONN_ACTIVE) {
1723 /*
1724 * emit DISCONNECT_B3_IND with cause 0x3301
1725 * use separate cmsg structure, as the content of iif->acmsg
1726 * is still needed for creating the _CONF message
1727 */
1728 b3cmsg = kmalloc(sizeof(*b3cmsg), GFP_KERNEL);
1729 if (!b3cmsg) {
1730 dev_err(cs->dev, "%s: out of memory\n", __func__);
1731 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1732 return;
1733 }
1734 capi_cmsg_header(b3cmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
1735 ap->nextMessageNumber++,
1736 iif->acmsg.adr.adrPLCI | (1 << 16));
1737 b3cmsg->Reason_B3 = CapiProtocolErrorLayer1;
1738 b3skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_KERNEL);
1739 if (b3skb == NULL) {
1740 dev_err(cs->dev, "%s: out of memory\n", __func__);
1741 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1742 return;
1743 }
1744 capi_cmsg2message(b3cmsg,
1745 __skb_put(b3skb, CAPI_DISCONNECT_B3_IND_BASELEN));
1746 kfree(b3cmsg);
1747 capi_ctr_handle_message(&iif->ctr, ap->id, b3skb);
1748 }
1749
1750 /* trigger hangup, causing eventual DISCONNECT_IND */
1751 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
1752 dev_err(cs->dev, "%s: out of memory\n", __func__);
1753 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1754 return;
1755 }
1756 gig_dbg(DEBUG_CMD, "scheduling HUP");
1757 gigaset_schedule_event(cs);
1758
1759 /* emit reply */
1760 send_conf(iif, ap, skb, CapiSuccess);
1761}
1762
1763/*
1764 * process DISCONNECT_B3_REQ message
1765 * schedule EV_HUP and emit DISCONNECT_B3_CONF reply
1766 */
1767static void do_disconnect_b3_req(struct gigaset_capi_ctr *iif,
1768 struct gigaset_capi_appl *ap,
1769 struct sk_buff *skb)
1770{
1771 struct cardstate *cs = iif->ctr.driverdata;
1772 int channel;
1773
1774 /* decode message */
1775 capi_message2cmsg(&iif->acmsg, skb->data);
1776 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1777
1778 /* extract and check channel number and NCCI */
1779 channel = (iif->acmsg.adr.adrNCCI >> 8) & 0xff;
1780 if (!channel || channel > cs->channels ||
1781 ((iif->acmsg.adr.adrNCCI >> 16) & 0xffff) != 1) {
1782 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1783 "DISCONNECT_B3_REQ", "NCCI", iif->acmsg.adr.adrNCCI);
1784 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1785 return;
1786 }
1787
1788 /* reject if logical connection not active */
1789 if (ap->connected < APCONN_ACTIVE) {
1790 send_conf(iif, ap, skb,
1791 CapiMessageNotSupportedInCurrentState);
1792 return;
1793 }
1794
1795 /* trigger hangup, causing eventual DISCONNECT_B3_IND */
1796 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1797 EV_HUP, NULL, 0, NULL)) {
1798 dev_err(cs->dev, "%s: out of memory\n", __func__);
1799 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1800 return;
1801 }
1802 gig_dbg(DEBUG_CMD, "scheduling HUP");
1803 gigaset_schedule_event(cs);
1804
1805 /* NCPI parameter: not applicable for B3 Transparent */
1806 ignore_cstruct_param(cs, iif->acmsg.NCPI,
1807 "DISCONNECT_B3_REQ", "NCPI");
1808 send_conf(iif, ap, skb,
1809 (iif->acmsg.NCPI && iif->acmsg.NCPI[0]) ?
1810 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1811}
1812
1813/*
1814 * process DATA_B3_REQ message
1815 */
1816static void do_data_b3_req(struct gigaset_capi_ctr *iif,
1817 struct gigaset_capi_appl *ap,
1818 struct sk_buff *skb)
1819{
1820 struct cardstate *cs = iif->ctr.driverdata;
1821 int channel = CAPIMSG_PLCI_PART(skb->data);
1822 u16 ncci = CAPIMSG_NCCI_PART(skb->data);
1823 u16 msglen = CAPIMSG_LEN(skb->data);
1824 u16 datalen = CAPIMSG_DATALEN(skb->data);
1825 u16 flags = CAPIMSG_FLAGS(skb->data);
1826
1827 /* frequent message, avoid _cmsg overhead */
1828 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_REQ", skb->data);
1829
1830 gig_dbg(DEBUG_LLDATA,
1831 "Receiving data from LL (ch: %d, flg: %x, sz: %d|%d)",
1832 channel, flags, msglen, datalen);
1833
1834 /* check parameters */
1835 if (channel == 0 || channel > cs->channels || ncci != 1) {
1836 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1837 "DATA_B3_REQ", "NCCI", CAPIMSG_NCCI(skb->data));
1838 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1839 return;
1840 }
1841 if (msglen != CAPI_DATA_B3_REQ_LEN && msglen != CAPI_DATA_B3_REQ_LEN64)
1842 dev_notice(cs->dev, "%s: unexpected length %d\n",
1843 "DATA_B3_REQ", msglen);
1844 if (msglen + datalen != skb->len)
1845 dev_notice(cs->dev, "%s: length mismatch (%d+%d!=%d)\n",
1846 "DATA_B3_REQ", msglen, datalen, skb->len);
1847 if (msglen + datalen > skb->len) {
1848 /* message too short for announced data length */
1849 send_conf(iif, ap, skb, CapiIllMessageParmCoding); /* ? */
1850 return;
1851 }
1852 if (flags & CAPI_FLAGS_RESERVED) {
1853 dev_notice(cs->dev, "%s: reserved flags set (%x)\n",
1854 "DATA_B3_REQ", flags);
1855 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
1856 return;
1857 }
1858
1859 /* reject if logical connection not active */
1860 if (ap->connected < APCONN_ACTIVE) {
1861 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
1862 return;
1863 }
1864
1865 /*
1866 * pull CAPI message from skb,
1867 * pass payload data to device-specific module
1868 * CAPI message will be preserved in headroom
1869 */
1870 skb_pull(skb, msglen);
1871 if (cs->ops->send_skb(&cs->bcs[channel-1], skb) < 0) {
1872 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1873 return;
1874 }
1875
1876 /* DATA_B3_CONF reply will be sent by gigaset_skb_sent() */
1877
1878 /*
1879 * ToDo: honor unset "delivery confirmation" bit
1880 * (send DATA_B3_CONF immediately?)
1881 */
1882}
1883
1884/*
1885 * process RESET_B3_REQ message
1886 * just always reply "not supported by current protocol"
1887 */
1888static void do_reset_b3_req(struct gigaset_capi_ctr *iif,
1889 struct gigaset_capi_appl *ap,
1890 struct sk_buff *skb)
1891{
1892 /* decode message */
1893 capi_message2cmsg(&iif->acmsg, skb->data);
1894 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1895 send_conf(iif, ap, skb,
1896 CapiResetProcedureNotSupportedByCurrentProtocol);
1897}
1898
1899/*
1900 * dump unsupported/ignored messages at most twice per minute,
1901 * some apps send those very frequently
1902 */
1903static unsigned long ignored_msg_dump_time;
1904
1905/*
1906 * unsupported CAPI message handler
1907 */
1908static void do_unsupported(struct gigaset_capi_ctr *iif,
1909 struct gigaset_capi_appl *ap,
1910 struct sk_buff *skb)
1911{
1912 /* decode message */
1913 capi_message2cmsg(&iif->acmsg, skb->data);
1914 if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000))
1915 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1916 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
1917}
1918
1919/*
1920 * CAPI message handler: no-op
1921 */
1922static void do_nothing(struct gigaset_capi_ctr *iif,
1923 struct gigaset_capi_appl *ap,
1924 struct sk_buff *skb)
1925{
1926 if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000)) {
1927 /* decode message */
1928 capi_message2cmsg(&iif->acmsg, skb->data);
1929 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1930 }
1931 dev_kfree_skb(skb);
1932}
1933
1934static void do_data_b3_resp(struct gigaset_capi_ctr *iif,
1935 struct gigaset_capi_appl *ap,
1936 struct sk_buff *skb)
1937{
1938 dump_rawmsg(DEBUG_LLDATA, __func__, skb->data);
1939 dev_kfree_skb(skb);
1940}
1941
1942/* table of outgoing CAPI message handlers with lookup function */
1943typedef void (*capi_send_handler_t)(struct gigaset_capi_ctr *,
1944 struct gigaset_capi_appl *,
1945 struct sk_buff *);
1946
1947static struct {
1948 u16 cmd;
1949 capi_send_handler_t handler;
1950} capi_send_handler_table[] = {
1951 /* most frequent messages first for faster lookup */
1952 { CAPI_DATA_B3_REQ, do_data_b3_req },
1953 { CAPI_DATA_B3_RESP, do_data_b3_resp },
1954
1955 { CAPI_ALERT_REQ, do_alert_req },
1956 { CAPI_CONNECT_ACTIVE_RESP, do_nothing },
1957 { CAPI_CONNECT_B3_ACTIVE_RESP, do_nothing },
1958 { CAPI_CONNECT_B3_REQ, do_connect_b3_req },
1959 { CAPI_CONNECT_B3_RESP, do_connect_b3_resp },
1960 { CAPI_CONNECT_B3_T90_ACTIVE_RESP, do_nothing },
1961 { CAPI_CONNECT_REQ, do_connect_req },
1962 { CAPI_CONNECT_RESP, do_connect_resp },
1963 { CAPI_DISCONNECT_B3_REQ, do_disconnect_b3_req },
1964 { CAPI_DISCONNECT_B3_RESP, do_nothing },
1965 { CAPI_DISCONNECT_REQ, do_disconnect_req },
1966 { CAPI_DISCONNECT_RESP, do_nothing },
1967 { CAPI_FACILITY_REQ, do_facility_req },
1968 { CAPI_FACILITY_RESP, do_nothing },
1969 { CAPI_LISTEN_REQ, do_listen_req },
1970 { CAPI_SELECT_B_PROTOCOL_REQ, do_unsupported },
1971 { CAPI_RESET_B3_REQ, do_reset_b3_req },
1972 { CAPI_RESET_B3_RESP, do_nothing },
1973
1974 /*
1975 * ToDo: support overlap sending (requires ev-layer state
1976 * machine extension to generate additional ATD commands)
1977 */
1978 { CAPI_INFO_REQ, do_unsupported },
1979 { CAPI_INFO_RESP, do_nothing },
1980
1981 /*
1982 * ToDo: what's the proper response for these?
1983 */
1984 { CAPI_MANUFACTURER_REQ, do_nothing },
1985 { CAPI_MANUFACTURER_RESP, do_nothing },
1986};
1987
1988/* look up handler */
1989static inline capi_send_handler_t lookup_capi_send_handler(const u16 cmd)
1990{
1991 size_t i;
1992
1993 for (i = 0; i < ARRAY_SIZE(capi_send_handler_table); i++)
1994 if (capi_send_handler_table[i].cmd == cmd)
1995 return capi_send_handler_table[i].handler;
1996 return NULL;
1997}
1998
1999
2000/**
2001 * gigaset_send_message() - accept a CAPI message from an application
2002 * @ctr: controller descriptor structure.
2003 * @skb: CAPI message.
2004 *
2005 * Return value: CAPI error code
2006 * Note: capidrv (and probably others, too) only uses the return value to
2007 * decide whether it has to free the skb (only if result != CAPI_NOERROR (0))
2008 */
2009static u16 gigaset_send_message(struct capi_ctr *ctr, struct sk_buff *skb)
2010{
2011 struct gigaset_capi_ctr *iif
2012 = container_of(ctr, struct gigaset_capi_ctr, ctr);
2013 struct cardstate *cs = ctr->driverdata;
2014 struct gigaset_capi_appl *ap;
2015 capi_send_handler_t handler;
2016
2017 /* can only handle linear sk_buffs */
2018 if (skb_linearize(skb) < 0) {
2019 dev_warn(cs->dev, "%s: skb_linearize failed\n", __func__);
2020 return CAPI_MSGOSRESOURCEERR;
2021 }
2022
2023 /* retrieve application data structure */
2024 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2025 if (!ap) {
2026 dev_notice(cs->dev, "%s: application %u not registered\n",
2027 __func__, CAPIMSG_APPID(skb->data));
2028 return CAPI_ILLAPPNR;
2029 }
2030
2031 /* look up command */
2032 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2033 if (!handler) {
2034 /* unknown/unsupported message type */
2035 if (printk_ratelimit())
2036 dev_notice(cs->dev, "%s: unsupported message %u\n",
2037 __func__, CAPIMSG_CMD(skb->data));
2038 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
2039 }
2040
2041 /* serialize */
2042 if (atomic_add_return(1, &iif->sendqlen) > 1) {
2043 /* queue behind other messages */
2044 skb_queue_tail(&iif->sendqueue, skb);
2045 return CAPI_NOERROR;
2046 }
2047
2048 /* process message */
2049 handler(iif, ap, skb);
2050
2051 /* process other messages arrived in the meantime */
2052 while (atomic_sub_return(1, &iif->sendqlen) > 0) {
2053 skb = skb_dequeue(&iif->sendqueue);
2054 if (!skb) {
2055 /* should never happen */
2056 dev_err(cs->dev, "%s: send queue empty\n", __func__);
2057 continue;
2058 }
2059 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2060 if (!ap) {
2061 /* could that happen? */
2062 dev_warn(cs->dev, "%s: application %u vanished\n",
2063 __func__, CAPIMSG_APPID(skb->data));
2064 continue;
2065 }
2066 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2067 if (!handler) {
2068 /* should never happen */
2069 dev_err(cs->dev, "%s: handler %x vanished\n",
2070 __func__, CAPIMSG_CMD(skb->data));
2071 continue;
2072 }
2073 handler(iif, ap, skb);
2074 }
2075
2076 return CAPI_NOERROR;
2077}
2078
2079/**
2080 * gigaset_procinfo() - build single line description for controller
2081 * @ctr: controller descriptor structure.
2082 *
2083 * Return value: pointer to generated string (null terminated)
2084 */
2085static char *gigaset_procinfo(struct capi_ctr *ctr)
2086{
2087 return ctr->name; /* ToDo: more? */
2088}
2089
2090/**
2091 * gigaset_ctr_read_proc() - build controller proc file entry
2092 * @page: buffer of PAGE_SIZE bytes for receiving the entry.
2093 * @start: unused.
2094 * @off: unused.
2095 * @count: unused.
2096 * @eof: unused.
2097 * @ctr: controller descriptor structure.
2098 *
2099 * Return value: length of generated entry
2100 */
2101static int gigaset_ctr_read_proc(char *page, char **start, off_t off,
2102 int count, int *eof, struct capi_ctr *ctr)
2103{
2104 struct cardstate *cs = ctr->driverdata;
2105 char *s;
2106 int i;
2107 int len = 0;
2108 len += sprintf(page+len, "%-16s %s\n", "name", ctr->name);
2109 len += sprintf(page+len, "%-16s %s %s\n", "dev",
2110 dev_driver_string(cs->dev), dev_name(cs->dev));
2111 len += sprintf(page+len, "%-16s %d\n", "id", cs->myid);
2112 if (cs->gotfwver)
2113 len += sprintf(page+len, "%-16s %d.%d.%d.%d\n", "firmware",
2114 cs->fwver[0], cs->fwver[1], cs->fwver[2], cs->fwver[3]);
2115 len += sprintf(page+len, "%-16s %d\n", "channels",
2116 cs->channels);
2117 len += sprintf(page+len, "%-16s %s\n", "onechannel",
2118 cs->onechannel ? "yes" : "no");
2119
2120 switch (cs->mode) {
2121 case M_UNKNOWN:
2122 s = "unknown";
2123 break;
2124 case M_CONFIG:
2125 s = "config";
2126 break;
2127 case M_UNIMODEM:
2128 s = "Unimodem";
2129 break;
2130 case M_CID:
2131 s = "CID";
2132 break;
2133 default:
2134 s = "??";
2135 }
2136 len += sprintf(page+len, "%-16s %s\n", "mode", s);
2137
2138 switch (cs->mstate) {
2139 case MS_UNINITIALIZED:
2140 s = "uninitialized";
2141 break;
2142 case MS_INIT:
2143 s = "init";
2144 break;
2145 case MS_LOCKED:
2146 s = "locked";
2147 break;
2148 case MS_SHUTDOWN:
2149 s = "shutdown";
2150 break;
2151 case MS_RECOVER:
2152 s = "recover";
2153 break;
2154 case MS_READY:
2155 s = "ready";
2156 break;
2157 default:
2158 s = "??";
2159 }
2160 len += sprintf(page+len, "%-16s %s\n", "mstate", s);
2161
2162 len += sprintf(page+len, "%-16s %s\n", "running",
2163 cs->running ? "yes" : "no");
2164 len += sprintf(page+len, "%-16s %s\n", "connected",
2165 cs->connected ? "yes" : "no");
2166 len += sprintf(page+len, "%-16s %s\n", "isdn_up",
2167 cs->isdn_up ? "yes" : "no");
2168 len += sprintf(page+len, "%-16s %s\n", "cidmode",
2169 cs->cidmode ? "yes" : "no");
2170
2171 for (i = 0; i < cs->channels; i++) {
2172 len += sprintf(page+len, "[%d]%-13s %d\n", i, "corrupted",
2173 cs->bcs[i].corrupted);
2174 len += sprintf(page+len, "[%d]%-13s %d\n", i, "trans_down",
2175 cs->bcs[i].trans_down);
2176 len += sprintf(page+len, "[%d]%-13s %d\n", i, "trans_up",
2177 cs->bcs[i].trans_up);
2178 len += sprintf(page+len, "[%d]%-13s %d\n", i, "chstate",
2179 cs->bcs[i].chstate);
2180 switch (cs->bcs[i].proto2) {
2181 case L2_BITSYNC:
2182 s = "bitsync";
2183 break;
2184 case L2_HDLC:
2185 s = "HDLC";
2186 break;
2187 case L2_VOICE:
2188 s = "voice";
2189 break;
2190 default:
2191 s = "??";
2192 }
2193 len += sprintf(page+len, "[%d]%-13s %s\n", i, "proto2", s);
2194 }
2195 return len;
2196}
2197
2198
2199static struct capi_driver capi_driver_gigaset = {
2200 .name = "gigaset",
2201 .revision = "1.0",
2202};
2203
2204/**
2205 * gigaset_isdn_register() - register to LL
2206 * @cs: device descriptor structure.
2207 * @isdnid: device name.
2208 *
2209 * Called by main module to register the device with the LL.
2210 *
2211 * Return value: 1 for success, 0 for failure
2212 */
2213int gigaset_isdn_register(struct cardstate *cs, const char *isdnid)
2214{
2215 struct gigaset_capi_ctr *iif;
2216 int rc;
2217
2218 pr_info("Kernel CAPI interface\n");
2219
2220 iif = kmalloc(sizeof(*iif), GFP_KERNEL);
2221 if (!iif) {
2222 pr_err("%s: out of memory\n", __func__);
2223 return 0;
2224 }
2225
2226 /* register driver with CAPI (ToDo: what for?) */
2227 register_capi_driver(&capi_driver_gigaset);
2228
2229 /* prepare controller structure */
2230 iif->ctr.owner = THIS_MODULE;
2231 iif->ctr.driverdata = cs;
2232 strncpy(iif->ctr.name, isdnid, sizeof(iif->ctr.name));
2233 iif->ctr.driver_name = "gigaset";
2234 iif->ctr.load_firmware = gigaset_load_firmware;
2235 iif->ctr.reset_ctr = gigaset_reset_ctr;
2236 iif->ctr.register_appl = gigaset_register_appl;
2237 iif->ctr.release_appl = gigaset_release_appl;
2238 iif->ctr.send_message = gigaset_send_message;
2239 iif->ctr.procinfo = gigaset_procinfo;
2240 iif->ctr.ctr_read_proc = gigaset_ctr_read_proc;
2241 INIT_LIST_HEAD(&iif->appls);
2242 skb_queue_head_init(&iif->sendqueue);
2243 atomic_set(&iif->sendqlen, 0);
2244
2245 /* register controller with CAPI */
2246 rc = attach_capi_ctr(&iif->ctr);
2247 if (rc) {
2248 pr_err("attach_capi_ctr failed (%d)\n", rc);
2249 unregister_capi_driver(&capi_driver_gigaset);
2250 kfree(iif);
2251 return 0;
2252 }
2253
2254 cs->iif = iif;
2255 cs->hw_hdr_len = CAPI_DATA_B3_REQ_LEN;
2256 return 1;
2257}
2258
2259/**
2260 * gigaset_isdn_unregister() - unregister from LL
2261 * @cs: device descriptor structure.
2262 *
2263 * Called by main module to unregister the device from the LL.
2264 */
2265void gigaset_isdn_unregister(struct cardstate *cs)
2266{
2267 struct gigaset_capi_ctr *iif = cs->iif;
2268
2269 detach_capi_ctr(&iif->ctr);
2270 kfree(iif);
2271 cs->iif = NULL;
2272 unregister_capi_driver(&capi_driver_gigaset);
2273}
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
index e4141bf8b2f..1d2ae2e05e0 100644
--- a/drivers/isdn/gigaset/common.c
+++ b/drivers/isdn/gigaset/common.c
@@ -22,6 +22,12 @@
22#define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Tilman Schmidt <tilman@imap.cc>, Stefan Eilers" 22#define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Tilman Schmidt <tilman@imap.cc>, Stefan Eilers"
23#define DRIVER_DESC "Driver for Gigaset 307x" 23#define DRIVER_DESC "Driver for Gigaset 307x"
24 24
25#ifdef CONFIG_GIGASET_DEBUG
26#define DRIVER_DESC_DEBUG " (debug build)"
27#else
28#define DRIVER_DESC_DEBUG ""
29#endif
30
25/* Module parameters */ 31/* Module parameters */
26int gigaset_debuglevel = DEBUG_DEFAULT; 32int gigaset_debuglevel = DEBUG_DEFAULT;
27EXPORT_SYMBOL_GPL(gigaset_debuglevel); 33EXPORT_SYMBOL_GPL(gigaset_debuglevel);
@@ -32,6 +38,17 @@ MODULE_PARM_DESC(debug, "debug level");
32#define VALID_MINOR 0x01 38#define VALID_MINOR 0x01
33#define VALID_ID 0x02 39#define VALID_ID 0x02
34 40
41/**
42 * gigaset_dbg_buffer() - dump data in ASCII and hex for debugging
43 * @level: debugging level.
44 * @msg: message prefix.
45 * @len: number of bytes to dump.
46 * @buf: data to dump.
47 *
48 * If the current debugging level includes one of the bits set in @level,
49 * @len bytes starting at @buf are logged to dmesg at KERN_DEBUG prio,
50 * prefixed by the text @msg.
51 */
35void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, 52void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
36 size_t len, const unsigned char *buf) 53 size_t len, const unsigned char *buf)
37{ 54{
@@ -190,6 +207,32 @@ int gigaset_get_channel(struct bc_state *bcs)
190 return 1; 207 return 1;
191} 208}
192 209
210struct bc_state *gigaset_get_free_channel(struct cardstate *cs)
211{
212 unsigned long flags;
213 int i;
214
215 spin_lock_irqsave(&cs->lock, flags);
216 if (!try_module_get(cs->driver->owner)) {
217 gig_dbg(DEBUG_ANY,
218 "could not get module for allocating channel");
219 spin_unlock_irqrestore(&cs->lock, flags);
220 return NULL;
221 }
222 for (i = 0; i < cs->channels; ++i)
223 if (!cs->bcs[i].use_count) {
224 ++cs->bcs[i].use_count;
225 cs->bcs[i].busy = 1;
226 spin_unlock_irqrestore(&cs->lock, flags);
227 gig_dbg(DEBUG_ANY, "allocated channel %d", i);
228 return cs->bcs + i;
229 }
230 module_put(cs->driver->owner);
231 spin_unlock_irqrestore(&cs->lock, flags);
232 gig_dbg(DEBUG_ANY, "no free channel");
233 return NULL;
234}
235
193void gigaset_free_channel(struct bc_state *bcs) 236void gigaset_free_channel(struct bc_state *bcs)
194{ 237{
195 unsigned long flags; 238 unsigned long flags;
@@ -274,6 +317,20 @@ static void clear_events(struct cardstate *cs)
274 spin_unlock_irqrestore(&cs->ev_lock, flags); 317 spin_unlock_irqrestore(&cs->ev_lock, flags);
275} 318}
276 319
320/**
321 * gigaset_add_event() - add event to device event queue
322 * @cs: device descriptor structure.
323 * @at_state: connection state structure.
324 * @type: event type.
325 * @ptr: pointer parameter for event.
326 * @parameter: integer parameter for event.
327 * @arg: pointer parameter for event.
328 *
329 * Allocate an event queue entry from the device's event queue, and set it up
330 * with the parameters given.
331 *
332 * Return value: added event
333 */
277struct event_t *gigaset_add_event(struct cardstate *cs, 334struct event_t *gigaset_add_event(struct cardstate *cs,
278 struct at_state_t *at_state, int type, 335 struct at_state_t *at_state, int type,
279 void *ptr, int parameter, void *arg) 336 void *ptr, int parameter, void *arg)
@@ -398,6 +455,15 @@ static void make_invalid(struct cardstate *cs, unsigned mask)
398 spin_unlock_irqrestore(&drv->lock, flags); 455 spin_unlock_irqrestore(&drv->lock, flags);
399} 456}
400 457
458/**
459 * gigaset_freecs() - free all associated ressources of a device
460 * @cs: device descriptor structure.
461 *
462 * Stops all tasklets and timers, unregisters the device from all
463 * subsystems it was registered to, deallocates the device structure
464 * @cs and all structures referenced from it.
465 * Operations on the device should be stopped before calling this.
466 */
401void gigaset_freecs(struct cardstate *cs) 467void gigaset_freecs(struct cardstate *cs)
402{ 468{
403 int i; 469 int i;
@@ -423,6 +489,12 @@ void gigaset_freecs(struct cardstate *cs)
423 489
424 switch (cs->cs_init) { 490 switch (cs->cs_init) {
425 default: 491 default:
492 /* clear B channel structures */
493 for (i = 0; i < cs->channels; ++i) {
494 gig_dbg(DEBUG_INIT, "clearing bcs[%d]", i);
495 gigaset_freebcs(cs->bcs + i);
496 }
497
426 /* clear device sysfs */ 498 /* clear device sysfs */
427 gigaset_free_dev_sysfs(cs); 499 gigaset_free_dev_sysfs(cs);
428 500
@@ -437,22 +509,16 @@ void gigaset_freecs(struct cardstate *cs)
437 case 2: /* error in initcshw */ 509 case 2: /* error in initcshw */
438 /* Deregister from LL */ 510 /* Deregister from LL */
439 make_invalid(cs, VALID_ID); 511 make_invalid(cs, VALID_ID);
440 gig_dbg(DEBUG_INIT, "clearing iif"); 512 gigaset_isdn_unregister(cs);
441 gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD);
442 513
443 /* fall through */ 514 /* fall through */
444 case 1: /* error when regestering to LL */ 515 case 1: /* error when registering to LL */
445 gig_dbg(DEBUG_INIT, "clearing at_state"); 516 gig_dbg(DEBUG_INIT, "clearing at_state");
446 clear_at_state(&cs->at_state); 517 clear_at_state(&cs->at_state);
447 dealloc_at_states(cs); 518 dealloc_at_states(cs);
448 519
449 /* fall through */ 520 /* fall through */
450 case 0: /* error in one call to initbcs */ 521 case 0: /* error in basic setup */
451 for (i = 0; i < cs->channels; ++i) {
452 gig_dbg(DEBUG_INIT, "clearing bcs[%d]", i);
453 gigaset_freebcs(cs->bcs + i);
454 }
455
456 clear_events(cs); 522 clear_events(cs);
457 gig_dbg(DEBUG_INIT, "freeing inbuf"); 523 gig_dbg(DEBUG_INIT, "freeing inbuf");
458 kfree(cs->inbuf); 524 kfree(cs->inbuf);
@@ -506,7 +572,12 @@ static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs,
506 inbuf->inputstate = inputstate; 572 inbuf->inputstate = inputstate;
507} 573}
508 574
509/* append received bytes to inbuf */ 575/**
576 * gigaset_fill_inbuf() - append received data to input buffer
577 * @inbuf: buffer structure.
578 * @src: received data.
579 * @numbytes: number of bytes received.
580 */
510int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src, 581int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
511 unsigned numbytes) 582 unsigned numbytes)
512{ 583{
@@ -575,11 +646,14 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
575 if (cs->ignoreframes) { 646 if (cs->ignoreframes) {
576 bcs->inputstate |= INS_skip_frame; 647 bcs->inputstate |= INS_skip_frame;
577 bcs->skb = NULL; 648 bcs->skb = NULL;
578 } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 649 } else {
579 skb_reserve(bcs->skb, HW_HDR_LEN); 650 bcs->skb = dev_alloc_skb(SBUFSIZE + cs->hw_hdr_len);
580 else { 651 if (bcs->skb != NULL)
581 pr_err("out of memory\n"); 652 skb_reserve(bcs->skb, cs->hw_hdr_len);
582 bcs->inputstate |= INS_skip_frame; 653 else {
654 pr_err("out of memory\n");
655 bcs->inputstate |= INS_skip_frame;
656 }
583 } 657 }
584 658
585 bcs->channel = channel; 659 bcs->channel = channel;
@@ -606,20 +680,22 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
606 return NULL; 680 return NULL;
607} 681}
608 682
609/* gigaset_initcs 683/**
684 * gigaset_initcs() - initialize device structure
685 * @drv: hardware driver the device belongs to
686 * @channels: number of B channels supported by device
687 * @onechannel: !=0 if B channel data and AT commands share one
688 * communication channel (M10x),
689 * ==0 if B channels have separate communication channels (base)
690 * @ignoreframes: number of frames to ignore after setting up B channel
691 * @cidmode: !=0: start in CallID mode
692 * @modulename: name of driver module for LL registration
693 *
610 * Allocate and initialize cardstate structure for Gigaset driver 694 * Allocate and initialize cardstate structure for Gigaset driver
611 * Calls hardware dependent gigaset_initcshw() function 695 * Calls hardware dependent gigaset_initcshw() function
612 * Calls B channel initialization function gigaset_initbcs() for each B channel 696 * Calls B channel initialization function gigaset_initbcs() for each B channel
613 * parameters: 697 *
614 * drv hardware driver the device belongs to 698 * Return value:
615 * channels number of B channels supported by device
616 * onechannel !=0: B channel data and AT commands share one
617 * communication channel
618 * ==0: B channels have separate communication channels
619 * ignoreframes number of frames to ignore after setting up B channel
620 * cidmode !=0: start in CallID mode
621 * modulename name of driver module (used for I4L registration)
622 * return value:
623 * pointer to cardstate structure 699 * pointer to cardstate structure
624 */ 700 */
625struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, 701struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
@@ -679,14 +755,6 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
679 cs->mode = M_UNKNOWN; 755 cs->mode = M_UNKNOWN;
680 cs->mstate = MS_UNINITIALIZED; 756 cs->mstate = MS_UNINITIALIZED;
681 757
682 for (i = 0; i < channels; ++i) {
683 gig_dbg(DEBUG_INIT, "setting up bcs[%d].read", i);
684 if (!gigaset_initbcs(cs->bcs + i, cs, i)) {
685 pr_err("could not allocate channel %d data\n", i);
686 goto error;
687 }
688 }
689
690 ++cs->cs_init; 758 ++cs->cs_init;
691 759
692 gig_dbg(DEBUG_INIT, "setting up at_state"); 760 gig_dbg(DEBUG_INIT, "setting up at_state");
@@ -711,7 +779,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
711 cs->cmdbytes = 0; 779 cs->cmdbytes = 0;
712 780
713 gig_dbg(DEBUG_INIT, "setting up iif"); 781 gig_dbg(DEBUG_INIT, "setting up iif");
714 if (!gigaset_register_to_LL(cs, modulename)) { 782 if (!gigaset_isdn_register(cs, modulename)) {
715 pr_err("error registering ISDN device\n"); 783 pr_err("error registering ISDN device\n");
716 goto error; 784 goto error;
717 } 785 }
@@ -730,6 +798,15 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
730 /* set up device sysfs */ 798 /* set up device sysfs */
731 gigaset_init_dev_sysfs(cs); 799 gigaset_init_dev_sysfs(cs);
732 800
801 /* set up channel data structures */
802 for (i = 0; i < channels; ++i) {
803 gig_dbg(DEBUG_INIT, "setting up bcs[%d]", i);
804 if (!gigaset_initbcs(cs->bcs + i, cs, i)) {
805 pr_err("could not allocate channel %d data\n", i);
806 goto error;
807 }
808 }
809
733 spin_lock_irqsave(&cs->lock, flags); 810 spin_lock_irqsave(&cs->lock, flags);
734 cs->running = 1; 811 cs->running = 1;
735 spin_unlock_irqrestore(&cs->lock, flags); 812 spin_unlock_irqrestore(&cs->lock, flags);
@@ -837,6 +914,17 @@ static void cleanup_cs(struct cardstate *cs)
837} 914}
838 915
839 916
917/**
918 * gigaset_start() - start device operations
919 * @cs: device descriptor structure.
920 *
921 * Prepares the device for use by setting up communication parameters,
922 * scheduling an EV_START event to initiate device initialization, and
923 * waiting for completion of the initialization.
924 *
925 * Return value:
926 * 1 - success, 0 - error
927 */
840int gigaset_start(struct cardstate *cs) 928int gigaset_start(struct cardstate *cs)
841{ 929{
842 unsigned long flags; 930 unsigned long flags;
@@ -879,9 +967,15 @@ error:
879} 967}
880EXPORT_SYMBOL_GPL(gigaset_start); 968EXPORT_SYMBOL_GPL(gigaset_start);
881 969
882/* gigaset_shutdown 970/**
883 * check if a device is associated to the cardstate structure and stop it 971 * gigaset_shutdown() - shut down device operations
884 * return value: 0 if ok, -1 if no device was associated 972 * @cs: device descriptor structure.
973 *
974 * Deactivates the device by scheduling an EV_SHUTDOWN event and
975 * waiting for completion of the shutdown.
976 *
977 * Return value:
978 * 0 - success, -1 - error (no device associated)
885 */ 979 */
886int gigaset_shutdown(struct cardstate *cs) 980int gigaset_shutdown(struct cardstate *cs)
887{ 981{
@@ -912,6 +1006,13 @@ exit:
912} 1006}
913EXPORT_SYMBOL_GPL(gigaset_shutdown); 1007EXPORT_SYMBOL_GPL(gigaset_shutdown);
914 1008
1009/**
1010 * gigaset_stop() - stop device operations
1011 * @cs: device descriptor structure.
1012 *
1013 * Stops operations on the device by scheduling an EV_STOP event and
1014 * waiting for completion of the shutdown.
1015 */
915void gigaset_stop(struct cardstate *cs) 1016void gigaset_stop(struct cardstate *cs)
916{ 1017{
917 mutex_lock(&cs->mutex); 1018 mutex_lock(&cs->mutex);
@@ -1020,6 +1121,14 @@ struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty)
1020 return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start); 1121 return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start);
1021} 1122}
1022 1123
1124/**
1125 * gigaset_freedriver() - free all associated ressources of a driver
1126 * @drv: driver descriptor structure.
1127 *
1128 * Unregisters the driver from the system and deallocates the driver
1129 * structure @drv and all structures referenced from it.
1130 * All devices should be shut down before calling this.
1131 */
1023void gigaset_freedriver(struct gigaset_driver *drv) 1132void gigaset_freedriver(struct gigaset_driver *drv)
1024{ 1133{
1025 unsigned long flags; 1134 unsigned long flags;
@@ -1035,14 +1144,16 @@ void gigaset_freedriver(struct gigaset_driver *drv)
1035} 1144}
1036EXPORT_SYMBOL_GPL(gigaset_freedriver); 1145EXPORT_SYMBOL_GPL(gigaset_freedriver);
1037 1146
1038/* gigaset_initdriver 1147/**
1148 * gigaset_initdriver() - initialize driver structure
1149 * @minor: First minor number
1150 * @minors: Number of minors this driver can handle
1151 * @procname: Name of the driver
1152 * @devname: Name of the device files (prefix without minor number)
1153 *
1039 * Allocate and initialize gigaset_driver structure. Initialize interface. 1154 * Allocate and initialize gigaset_driver structure. Initialize interface.
1040 * parameters: 1155 *
1041 * minor First minor number 1156 * Return value:
1042 * minors Number of minors this driver can handle
1043 * procname Name of the driver
1044 * devname Name of the device files (prefix without minor number)
1045 * return value:
1046 * Pointer to the gigaset_driver structure on success, NULL on failure. 1157 * Pointer to the gigaset_driver structure on success, NULL on failure.
1047 */ 1158 */
1048struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, 1159struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
@@ -1095,6 +1206,13 @@ error:
1095} 1206}
1096EXPORT_SYMBOL_GPL(gigaset_initdriver); 1207EXPORT_SYMBOL_GPL(gigaset_initdriver);
1097 1208
1209/**
1210 * gigaset_blockdriver() - block driver
1211 * @drv: driver descriptor structure.
1212 *
1213 * Prevents the driver from attaching new devices, in preparation for
1214 * deregistration.
1215 */
1098void gigaset_blockdriver(struct gigaset_driver *drv) 1216void gigaset_blockdriver(struct gigaset_driver *drv)
1099{ 1217{
1100 drv->blocked = 1; 1218 drv->blocked = 1;
@@ -1110,7 +1228,7 @@ static int __init gigaset_init_module(void)
1110 if (gigaset_debuglevel == 1) 1228 if (gigaset_debuglevel == 1)
1111 gigaset_debuglevel = DEBUG_DEFAULT; 1229 gigaset_debuglevel = DEBUG_DEFAULT;
1112 1230
1113 pr_info(DRIVER_DESC "\n"); 1231 pr_info(DRIVER_DESC DRIVER_DESC_DEBUG "\n");
1114 return 0; 1232 return 0;
1115} 1233}
1116 1234
diff --git a/drivers/isdn/gigaset/dummyll.c b/drivers/isdn/gigaset/dummyll.c
new file mode 100644
index 00000000000..5b27c996af6
--- /dev/null
+++ b/drivers/isdn/gigaset/dummyll.c
@@ -0,0 +1,68 @@
1/*
2 * Dummy LL interface for the Gigaset driver
3 *
4 * Copyright (c) 2009 by Tilman Schmidt <tilman@imap.cc>.
5 *
6 * =====================================================================
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 * =====================================================================
12 */
13
14#include "gigaset.h"
15
16void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb)
17{
18}
19EXPORT_SYMBOL_GPL(gigaset_skb_sent);
20
21void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
22{
23}
24EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
25
26void gigaset_isdn_rcv_err(struct bc_state *bcs)
27{
28}
29EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
30
31int gigaset_isdn_icall(struct at_state_t *at_state)
32{
33 return ICALL_IGNORE;
34}
35
36void gigaset_isdn_connD(struct bc_state *bcs)
37{
38}
39
40void gigaset_isdn_hupD(struct bc_state *bcs)
41{
42}
43
44void gigaset_isdn_connB(struct bc_state *bcs)
45{
46}
47
48void gigaset_isdn_hupB(struct bc_state *bcs)
49{
50}
51
52void gigaset_isdn_start(struct cardstate *cs)
53{
54}
55
56void gigaset_isdn_stop(struct cardstate *cs)
57{
58}
59
60int gigaset_isdn_register(struct cardstate *cs, const char *isdnid)
61{
62 pr_info("no ISDN subsystem interface\n");
63 return 1;
64}
65
66void gigaset_isdn_unregister(struct cardstate *cs)
67{
68}
diff --git a/drivers/isdn/gigaset/ev-layer.c b/drivers/isdn/gigaset/ev-layer.c
index 2d91049571a..369927f9072 100644
--- a/drivers/isdn/gigaset/ev-layer.c
+++ b/drivers/isdn/gigaset/ev-layer.c
@@ -127,7 +127,6 @@
127#define ACT_NOTIFY_BC_UP 39 127#define ACT_NOTIFY_BC_UP 39
128#define ACT_DIAL 40 128#define ACT_DIAL 40
129#define ACT_ACCEPT 41 129#define ACT_ACCEPT 41
130#define ACT_PROTO_L2 42
131#define ACT_HUP 43 130#define ACT_HUP 43
132#define ACT_IF_LOCK 44 131#define ACT_IF_LOCK 44
133#define ACT_START 45 132#define ACT_START 45
@@ -207,7 +206,6 @@ struct reply_t gigaset_tab_nocid[] =
207 /* leave dle mode */ 206 /* leave dle mode */
208 {RSP_INIT, 0, 0,SEQ_DLE0, 201, 5, {0}, "^SDLE=0\r"}, 207 {RSP_INIT, 0, 0,SEQ_DLE0, 201, 5, {0}, "^SDLE=0\r"},
209 {RSP_OK, 201,201, -1, 202,-1}, 208 {RSP_OK, 201,201, -1, 202,-1},
210 //{RSP_ZDLE, 202,202, 0, 202, 0, {ACT_ERROR}},//DELETE
211 {RSP_ZDLE, 202,202, 0, 0, 0, {ACT_DLE0}}, 209 {RSP_ZDLE, 202,202, 0, 0, 0, {ACT_DLE0}},
212 {RSP_NODEV, 200,249, -1, 0, 0, {ACT_FAKEDLE0}}, 210 {RSP_NODEV, 200,249, -1, 0, 0, {ACT_FAKEDLE0}},
213 {RSP_ERROR, 200,249, -1, 0, 0, {ACT_FAILDLE0}}, 211 {RSP_ERROR, 200,249, -1, 0, 0, {ACT_FAILDLE0}},
@@ -265,6 +263,7 @@ struct reply_t gigaset_tab_nocid[] =
265 {EV_SHUTDOWN, -1, -1, -1, -1,-1, {ACT_SHUTDOWN}}, //FIXME 263 {EV_SHUTDOWN, -1, -1, -1, -1,-1, {ACT_SHUTDOWN}}, //FIXME
266 264
267 /* misc. */ 265 /* misc. */
266 {RSP_ERROR, -1, -1, -1, -1, -1, {ACT_ERROR} },
268 {RSP_EMPTY, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME 267 {RSP_EMPTY, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
269 {RSP_ZCFGT, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME 268 {RSP_ZCFGT, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
270 {RSP_ZCFG, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME 269 {RSP_ZCFG, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
@@ -292,21 +291,23 @@ struct reply_t gigaset_tab_cid[] =
292 {RSP_OK, 602,602, -1, 603, 5, {ACT_CMD+AT_PROTO}}, 291 {RSP_OK, 602,602, -1, 603, 5, {ACT_CMD+AT_PROTO}},
293 {RSP_OK, 603,603, -1, 604, 5, {ACT_CMD+AT_TYPE}}, 292 {RSP_OK, 603,603, -1, 604, 5, {ACT_CMD+AT_TYPE}},
294 {RSP_OK, 604,604, -1, 605, 5, {ACT_CMD+AT_MSN}}, 293 {RSP_OK, 604,604, -1, 605, 5, {ACT_CMD+AT_MSN}},
295 {RSP_OK, 605,605, -1, 606, 5, {ACT_CMD+AT_ISO}}, 294 {RSP_NULL, 605, 605, -1, 606, 5, {ACT_CMD+AT_CLIP} },
296 {RSP_NULL, 605,605, -1, 606, 5, {ACT_CMD+AT_ISO}}, 295 {RSP_OK, 605, 605, -1, 606, 5, {ACT_CMD+AT_CLIP} },
297 {RSP_OK, 606,606, -1, 607, 5, {0}, "+VLS=17\r"}, 296 {RSP_NULL, 606, 606, -1, 607, 5, {ACT_CMD+AT_ISO} },
298 {RSP_OK, 607,607, -1, 608,-1}, 297 {RSP_OK, 606, 606, -1, 607, 5, {ACT_CMD+AT_ISO} },
299 {RSP_ZSAU, 608,608,ZSAU_PROCEEDING, 609, 5, {ACT_CMD+AT_DIAL}}, 298 {RSP_OK, 607, 607, -1, 608, 5, {0}, "+VLS=17\r"},
300 {RSP_OK, 609,609, -1, 650, 0, {ACT_DIALING}}, 299 {RSP_OK, 608, 608, -1, 609, -1},
301 300 {RSP_ZSAU, 609, 609, ZSAU_PROCEEDING, 610, 5, {ACT_CMD+AT_DIAL} },
302 {RSP_ERROR, 601,609, -1, 0, 0, {ACT_ABORTDIAL}}, 301 {RSP_OK, 610, 610, -1, 650, 0, {ACT_DIALING} },
303 {EV_TIMEOUT, 601,609, -1, 0, 0, {ACT_ABORTDIAL}}, 302
303 {RSP_ERROR, 601, 610, -1, 0, 0, {ACT_ABORTDIAL} },
304 {EV_TIMEOUT, 601, 610, -1, 0, 0, {ACT_ABORTDIAL} },
304 305
305 /* optional dialing responses */ 306 /* optional dialing responses */
306 {EV_BC_OPEN, 650,650, -1, 651,-1}, 307 {EV_BC_OPEN, 650,650, -1, 651,-1},
307 {RSP_ZVLS, 608,651, 17, -1,-1, {ACT_DEBUG}}, 308 {RSP_ZVLS, 609, 651, 17, -1, -1, {ACT_DEBUG} },
308 {RSP_ZCTP, 609,651, -1, -1,-1, {ACT_DEBUG}}, 309 {RSP_ZCTP, 610, 651, -1, -1, -1, {ACT_DEBUG} },
309 {RSP_ZCPN, 609,651, -1, -1,-1, {ACT_DEBUG}}, 310 {RSP_ZCPN, 610, 651, -1, -1, -1, {ACT_DEBUG} },
310 {RSP_ZSAU, 650,651,ZSAU_CALL_DELIVERED, -1,-1, {ACT_DEBUG}}, 311 {RSP_ZSAU, 650,651,ZSAU_CALL_DELIVERED, -1,-1, {ACT_DEBUG}},
311 312
312 /* connect */ 313 /* connect */
@@ -328,10 +329,9 @@ struct reply_t gigaset_tab_cid[] =
328 {RSP_INIT, -1, -1,SEQ_HUP, 401, 5, {0}, "+VLS=0\r"}, /* hang up */ //-1,-1? 329 {RSP_INIT, -1, -1,SEQ_HUP, 401, 5, {0}, "+VLS=0\r"}, /* hang up */ //-1,-1?
329 {RSP_OK, 401,401, -1, 402, 5}, 330 {RSP_OK, 401,401, -1, 402, 5},
330 {RSP_ZVLS, 402,402, 0, 403, 5}, 331 {RSP_ZVLS, 402,402, 0, 403, 5},
331 {RSP_ZSAU, 403,403,ZSAU_DISCONNECT_REQ, -1,-1, {ACT_DEBUG}}, /* if not remote hup */ 332 {RSP_ZSAU, 403, 403, ZSAU_DISCONNECT_REQ, -1, -1, {ACT_DEBUG} },
332 //{RSP_ZSAU, 403,403,ZSAU_NULL, 401, 0, {ACT_ERROR}}, //DELETE//FIXME -> DLE0 // should we do this _before_ hanging up for base driver? 333 {RSP_ZSAU, 403, 403, ZSAU_NULL, 0, 0, {ACT_DISCONNECT} },
333 {RSP_ZSAU, 403,403,ZSAU_NULL, 0, 0, {ACT_DISCONNECT}}, //FIXME -> DLE0 // should we do this _before_ hanging up for base driver? 334 {RSP_NODEV, 401, 403, -1, 0, 0, {ACT_FAKEHUP} },
334 {RSP_NODEV, 401,403, -1, 0, 0, {ACT_FAKEHUP}}, //FIXME -> DLE0 // should we do this _before_ hanging up for base driver?
335 {RSP_ERROR, 401,401, -1, 0, 0, {ACT_ABORTHUP}}, 335 {RSP_ERROR, 401,401, -1, 0, 0, {ACT_ABORTHUP}},
336 {EV_TIMEOUT, 401,403, -1, 0, 0, {ACT_ABORTHUP}}, 336 {EV_TIMEOUT, 401,403, -1, 0, 0, {ACT_ABORTHUP}},
337 337
@@ -366,8 +366,6 @@ struct reply_t gigaset_tab_cid[] =
366 {EV_BC_CLOSED, -1, -1, -1, -1,-1, {ACT_NOTIFY_BC_DOWN}}, //FIXME 366 {EV_BC_CLOSED, -1, -1, -1, -1,-1, {ACT_NOTIFY_BC_DOWN}}, //FIXME
367 367
368 /* misc. */ 368 /* misc. */
369 {EV_PROTO_L2, -1, -1, -1, -1,-1, {ACT_PROTO_L2}}, //FIXME
370
371 {RSP_ZCON, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME 369 {RSP_ZCON, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
372 {RSP_ZCCR, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME 370 {RSP_ZCCR, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
373 {RSP_ZAOC, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME 371 {RSP_ZAOC, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
@@ -474,8 +472,13 @@ static int cid_of_response(char *s)
474 //FIXME is ;<digit>+ at end of non-CID response really impossible? 472 //FIXME is ;<digit>+ at end of non-CID response really impossible?
475} 473}
476 474
477/* This function will be called via task queue from the callback handler. 475/**
478 * We received a modem response and have to handle it.. 476 * gigaset_handle_modem_response() - process received modem response
477 * @cs: device descriptor structure.
478 *
479 * Called by asyncdata/isocdata if a block of data received from the
480 * device must be processed as a modem command response. The data is
481 * already in the cs structure.
479 */ 482 */
480void gigaset_handle_modem_response(struct cardstate *cs) 483void gigaset_handle_modem_response(struct cardstate *cs)
481{ 484{
@@ -707,6 +710,11 @@ static void disconnect(struct at_state_t **at_state_p)
707 if (bcs) { 710 if (bcs) {
708 /* B channel assigned: invoke hardware specific handler */ 711 /* B channel assigned: invoke hardware specific handler */
709 cs->ops->close_bchannel(bcs); 712 cs->ops->close_bchannel(bcs);
713 /* notify LL */
714 if (bcs->chstate & (CHS_D_UP | CHS_NOTIFY_LL)) {
715 bcs->chstate &= ~(CHS_D_UP | CHS_NOTIFY_LL);
716 gigaset_isdn_hupD(bcs);
717 }
710 } else { 718 } else {
711 /* no B channel assigned: just deallocate */ 719 /* no B channel assigned: just deallocate */
712 spin_lock_irqsave(&cs->lock, flags); 720 spin_lock_irqsave(&cs->lock, flags);
@@ -863,12 +871,12 @@ static void bchannel_down(struct bc_state *bcs)
863{ 871{
864 if (bcs->chstate & CHS_B_UP) { 872 if (bcs->chstate & CHS_B_UP) {
865 bcs->chstate &= ~CHS_B_UP; 873 bcs->chstate &= ~CHS_B_UP;
866 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BHUP); 874 gigaset_isdn_hupB(bcs);
867 } 875 }
868 876
869 if (bcs->chstate & (CHS_D_UP | CHS_NOTIFY_LL)) { 877 if (bcs->chstate & (CHS_D_UP | CHS_NOTIFY_LL)) {
870 bcs->chstate &= ~(CHS_D_UP | CHS_NOTIFY_LL); 878 bcs->chstate &= ~(CHS_D_UP | CHS_NOTIFY_LL);
871 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DHUP); 879 gigaset_isdn_hupD(bcs);
872 } 880 }
873 881
874 gigaset_free_channel(bcs); 882 gigaset_free_channel(bcs);
@@ -885,15 +893,16 @@ static void bchannel_up(struct bc_state *bcs)
885 } 893 }
886 894
887 bcs->chstate |= CHS_B_UP; 895 bcs->chstate |= CHS_B_UP;
888 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BCONN); 896 gigaset_isdn_connB(bcs);
889} 897}
890 898
891static void start_dial(struct at_state_t *at_state, void *data, unsigned seq_index) 899static void start_dial(struct at_state_t *at_state, void *data, unsigned seq_index)
892{ 900{
893 struct bc_state *bcs = at_state->bcs; 901 struct bc_state *bcs = at_state->bcs;
894 struct cardstate *cs = at_state->cs; 902 struct cardstate *cs = at_state->cs;
895 int retval; 903 char **commands = data;
896 unsigned long flags; 904 unsigned long flags;
905 int i;
897 906
898 bcs->chstate |= CHS_NOTIFY_LL; 907 bcs->chstate |= CHS_NOTIFY_LL;
899 908
@@ -904,10 +913,10 @@ static void start_dial(struct at_state_t *at_state, void *data, unsigned seq_ind
904 } 913 }
905 spin_unlock_irqrestore(&cs->lock, flags); 914 spin_unlock_irqrestore(&cs->lock, flags);
906 915
907 retval = gigaset_isdn_setup_dial(at_state, data); 916 for (i = 0; i < AT_NUM; ++i) {
908 if (retval != 0) 917 kfree(bcs->commands[i]);
909 goto error; 918 bcs->commands[i] = commands[i];
910 919 }
911 920
912 at_state->pending_commands |= PC_CID; 921 at_state->pending_commands |= PC_CID;
913 gig_dbg(DEBUG_CMD, "Scheduling PC_CID"); 922 gig_dbg(DEBUG_CMD, "Scheduling PC_CID");
@@ -915,6 +924,10 @@ static void start_dial(struct at_state_t *at_state, void *data, unsigned seq_ind
915 return; 924 return;
916 925
917error: 926error:
927 for (i = 0; i < AT_NUM; ++i) {
928 kfree(commands[i]);
929 commands[i] = NULL;
930 }
918 at_state->pending_commands |= PC_NOCID; 931 at_state->pending_commands |= PC_NOCID;
919 gig_dbg(DEBUG_CMD, "Scheduling PC_NOCID"); 932 gig_dbg(DEBUG_CMD, "Scheduling PC_NOCID");
920 cs->commands_pending = 1; 933 cs->commands_pending = 1;
@@ -924,20 +937,31 @@ error:
924static void start_accept(struct at_state_t *at_state) 937static void start_accept(struct at_state_t *at_state)
925{ 938{
926 struct cardstate *cs = at_state->cs; 939 struct cardstate *cs = at_state->cs;
927 int retval; 940 struct bc_state *bcs = at_state->bcs;
941 int i;
928 942
929 retval = gigaset_isdn_setup_accept(at_state); 943 for (i = 0; i < AT_NUM; ++i) {
944 kfree(bcs->commands[i]);
945 bcs->commands[i] = NULL;
946 }
930 947
931 if (retval == 0) { 948 bcs->commands[AT_PROTO] = kmalloc(9, GFP_ATOMIC);
932 at_state->pending_commands |= PC_ACCEPT; 949 bcs->commands[AT_ISO] = kmalloc(9, GFP_ATOMIC);
933 gig_dbg(DEBUG_CMD, "Scheduling PC_ACCEPT"); 950 if (!bcs->commands[AT_PROTO] || !bcs->commands[AT_ISO]) {
934 cs->commands_pending = 1; 951 dev_err(at_state->cs->dev, "out of memory\n");
935 } else {
936 /* error reset */ 952 /* error reset */
937 at_state->pending_commands |= PC_HUP; 953 at_state->pending_commands |= PC_HUP;
938 gig_dbg(DEBUG_CMD, "Scheduling PC_HUP"); 954 gig_dbg(DEBUG_CMD, "Scheduling PC_HUP");
939 cs->commands_pending = 1; 955 cs->commands_pending = 1;
956 return;
940 } 957 }
958
959 snprintf(bcs->commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2);
960 snprintf(bcs->commands[AT_ISO], 9, "^SISO=%u\r", bcs->channel + 1);
961
962 at_state->pending_commands |= PC_ACCEPT;
963 gig_dbg(DEBUG_CMD, "Scheduling PC_ACCEPT");
964 cs->commands_pending = 1;
941} 965}
942 966
943static void do_start(struct cardstate *cs) 967static void do_start(struct cardstate *cs)
@@ -948,7 +972,7 @@ static void do_start(struct cardstate *cs)
948 schedule_init(cs, MS_INIT); 972 schedule_init(cs, MS_INIT);
949 973
950 cs->isdn_up = 1; 974 cs->isdn_up = 1;
951 gigaset_i4l_cmd(cs, ISDN_STAT_RUN); 975 gigaset_isdn_start(cs);
952 // FIXME: not in locked mode 976 // FIXME: not in locked mode
953 // FIXME 2: only after init sequence 977 // FIXME 2: only after init sequence
954 978
@@ -966,7 +990,7 @@ static void finish_shutdown(struct cardstate *cs)
966 /* Tell the LL that the device is not available .. */ 990 /* Tell the LL that the device is not available .. */
967 if (cs->isdn_up) { 991 if (cs->isdn_up) {
968 cs->isdn_up = 0; 992 cs->isdn_up = 0;
969 gigaset_i4l_cmd(cs, ISDN_STAT_STOP); 993 gigaset_isdn_stop(cs);
970 } 994 }
971 995
972 /* The rest is done by cleanup_cs () in user mode. */ 996 /* The rest is done by cleanup_cs () in user mode. */
@@ -1267,7 +1291,7 @@ static void do_action(int action, struct cardstate *cs,
1267 break; 1291 break;
1268 } 1292 }
1269 bcs->chstate |= CHS_D_UP; 1293 bcs->chstate |= CHS_D_UP;
1270 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN); 1294 gigaset_isdn_connD(bcs);
1271 cs->ops->init_bchannel(bcs); 1295 cs->ops->init_bchannel(bcs);
1272 break; 1296 break;
1273 case ACT_DLE1: 1297 case ACT_DLE1:
@@ -1275,7 +1299,7 @@ static void do_action(int action, struct cardstate *cs,
1275 bcs = cs->bcs + cs->curchannel; 1299 bcs = cs->bcs + cs->curchannel;
1276 1300
1277 bcs->chstate |= CHS_D_UP; 1301 bcs->chstate |= CHS_D_UP;
1278 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN); 1302 gigaset_isdn_connD(bcs);
1279 cs->ops->init_bchannel(bcs); 1303 cs->ops->init_bchannel(bcs);
1280 break; 1304 break;
1281 case ACT_FAKEHUP: 1305 case ACT_FAKEHUP:
@@ -1429,11 +1453,12 @@ static void do_action(int action, struct cardstate *cs,
1429 cs->gotfwver = -1; 1453 cs->gotfwver = -1;
1430 dev_err(cs->dev, "could not read firmware version.\n"); 1454 dev_err(cs->dev, "could not read firmware version.\n");
1431 break; 1455 break;
1432#ifdef CONFIG_GIGASET_DEBUG
1433 case ACT_ERROR: 1456 case ACT_ERROR:
1434 *p_genresp = 1; 1457 gig_dbg(DEBUG_ANY, "%s: ERROR response in ConState %d",
1435 *p_resp_code = RSP_ERROR; 1458 __func__, at_state->ConState);
1459 cs->cur_at_seq = SEQ_NONE;
1436 break; 1460 break;
1461#ifdef CONFIG_GIGASET_DEBUG
1437 case ACT_TEST: 1462 case ACT_TEST:
1438 { 1463 {
1439 static int count = 3; //2; //1; 1464 static int count = 3; //2; //1;
@@ -1464,11 +1489,6 @@ static void do_action(int action, struct cardstate *cs,
1464 case ACT_ACCEPT: 1489 case ACT_ACCEPT:
1465 start_accept(at_state); 1490 start_accept(at_state);
1466 break; 1491 break;
1467 case ACT_PROTO_L2:
1468 gig_dbg(DEBUG_CMD, "set protocol to %u",
1469 (unsigned) ev->parameter);
1470 at_state->bcs->proto2 = ev->parameter;
1471 break;
1472 case ACT_HUP: 1492 case ACT_HUP:
1473 at_state->pending_commands |= PC_HUP; 1493 at_state->pending_commands |= PC_HUP;
1474 cs->commands_pending = 1; 1494 cs->commands_pending = 1;
diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
index a2f6125739e..4749ef100fd 100644
--- a/drivers/isdn/gigaset/gigaset.h
+++ b/drivers/isdn/gigaset/gigaset.h
@@ -23,7 +23,6 @@
23#include <linux/compiler.h> 23#include <linux/compiler.h>
24#include <linux/types.h> 24#include <linux/types.h>
25#include <linux/spinlock.h> 25#include <linux/spinlock.h>
26#include <linux/isdnif.h>
27#include <linux/usb.h> 26#include <linux/usb.h>
28#include <linux/skbuff.h> 27#include <linux/skbuff.h>
29#include <linux/netdevice.h> 28#include <linux/netdevice.h>
@@ -40,7 +39,6 @@
40 39
41#define MAX_REC_PARAMS 10 /* Max. number of params in response string */ 40#define MAX_REC_PARAMS 10 /* Max. number of params in response string */
42#define MAX_RESP_SIZE 512 /* Max. size of a response string */ 41#define MAX_RESP_SIZE 512 /* Max. size of a response string */
43#define HW_HDR_LEN 2 /* Header size used to store ack info */
44 42
45#define MAX_EVENTS 64 /* size of event queue */ 43#define MAX_EVENTS 64 /* size of event queue */
46 44
@@ -193,7 +191,9 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
193#define AT_PROTO 4 191#define AT_PROTO 4
194#define AT_TYPE 5 192#define AT_TYPE 5
195#define AT_HLC 6 193#define AT_HLC 6
196#define AT_NUM 7 194#define AT_CLIP 7
195/* total number */
196#define AT_NUM 8
197 197
198/* variables in struct at_state_t */ 198/* variables in struct at_state_t */
199#define VAR_ZSAU 0 199#define VAR_ZSAU 0
@@ -216,7 +216,6 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
216#define EV_START -110 216#define EV_START -110
217#define EV_STOP -111 217#define EV_STOP -111
218#define EV_IF_LOCK -112 218#define EV_IF_LOCK -112
219#define EV_PROTO_L2 -113
220#define EV_ACCEPT -114 219#define EV_ACCEPT -114
221#define EV_DIAL -115 220#define EV_DIAL -115
222#define EV_HUP -116 221#define EV_HUP -116
@@ -259,6 +258,11 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
259#define SM_LOCKED 0 258#define SM_LOCKED 0
260#define SM_ISDN 1 /* default */ 259#define SM_ISDN 1 /* default */
261 260
261/* layer 2 protocols (AT^SBPR=...) */
262#define L2_BITSYNC 0
263#define L2_HDLC 1
264#define L2_VOICE 2
265
262struct gigaset_ops; 266struct gigaset_ops;
263struct gigaset_driver; 267struct gigaset_driver;
264 268
@@ -395,7 +399,7 @@ struct bc_state {
395 399
396 unsigned chstate; /* bitmap (CHS_*) */ 400 unsigned chstate; /* bitmap (CHS_*) */
397 int ignore; 401 int ignore;
398 unsigned proto2; /* Layer 2 protocol (ISDN_PROTO_L2_*) */ 402 unsigned proto2; /* layer 2 protocol (L2_*) */
399 char *commands[AT_NUM]; /* see AT_XXXX */ 403 char *commands[AT_NUM]; /* see AT_XXXX */
400 404
401#ifdef CONFIG_GIGASET_DEBUG 405#ifdef CONFIG_GIGASET_DEBUG
@@ -410,6 +414,8 @@ struct bc_state {
410 struct usb_bc_state *usb; /* usb hardware driver (m105) */ 414 struct usb_bc_state *usb; /* usb hardware driver (m105) */
411 struct bas_bc_state *bas; /* usb hardware driver (base) */ 415 struct bas_bc_state *bas; /* usb hardware driver (base) */
412 } hw; 416 } hw;
417
418 void *ap; /* LL application structure */
413}; 419};
414 420
415struct cardstate { 421struct cardstate {
@@ -456,12 +462,13 @@ struct cardstate {
456 462
457 unsigned running; /* !=0 if events are handled */ 463 unsigned running; /* !=0 if events are handled */
458 unsigned connected; /* !=0 if hardware is connected */ 464 unsigned connected; /* !=0 if hardware is connected */
459 unsigned isdn_up; /* !=0 after ISDN_STAT_RUN */ 465 unsigned isdn_up; /* !=0 after gigaset_isdn_start() */
460 466
461 unsigned cidmode; 467 unsigned cidmode;
462 468
463 int myid; /* id for communication with LL */ 469 int myid; /* id for communication with LL */
464 isdn_if iif; 470 void *iif; /* LL interface structure */
471 unsigned short hw_hdr_len; /* headroom needed in data skbs */
465 472
466 struct reply_t *tabnocid; 473 struct reply_t *tabnocid;
467 struct reply_t *tabcid; 474 struct reply_t *tabcid;
@@ -616,7 +623,9 @@ struct gigaset_ops {
616 int (*baud_rate)(struct cardstate *cs, unsigned cflag); 623 int (*baud_rate)(struct cardstate *cs, unsigned cflag);
617 int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag); 624 int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag);
618 625
619 /* Called from i4l.c to put an skb into the send-queue. */ 626 /* Called from LL interface to put an skb into the send-queue.
627 * After sending is completed, gigaset_skb_sent() must be called
628 * with the first cs->hw_hdr_len bytes of skb->head preserved. */
620 int (*send_skb)(struct bc_state *bcs, struct sk_buff *skb); 629 int (*send_skb)(struct bc_state *bcs, struct sk_buff *skb);
621 630
622 /* Called from ev-layer.c to process a block of data 631 /* Called from ev-layer.c to process a block of data
@@ -638,8 +647,7 @@ struct gigaset_ops {
638 * Functions implemented in asyncdata.c 647 * Functions implemented in asyncdata.c
639 */ 648 */
640 649
641/* Called from i4l.c to put an skb into the send-queue. 650/* Called from LL interface to put an skb into the send queue. */
642 * After sending gigaset_skb_sent() should be called. */
643int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb); 651int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb);
644 652
645/* Called from ev-layer.c to process a block of data 653/* Called from ev-layer.c to process a block of data
@@ -650,8 +658,7 @@ void gigaset_m10x_input(struct inbuf_t *inbuf);
650 * Functions implemented in isocdata.c 658 * Functions implemented in isocdata.c
651 */ 659 */
652 660
653/* Called from i4l.c to put an skb into the send-queue. 661/* Called from LL interface to put an skb into the send queue. */
654 * After sending gigaset_skb_sent() should be called. */
655int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb); 662int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb);
656 663
657/* Called from ev-layer.c to process a block of data 664/* Called from ev-layer.c to process a block of data
@@ -674,36 +681,26 @@ void gigaset_isowbuf_init(struct isowbuf_t *iwb, unsigned char idle);
674int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size); 681int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size);
675 682
676/* =========================================================================== 683/* ===========================================================================
677 * Functions implemented in i4l.c/gigaset.h 684 * Functions implemented in LL interface
678 */ 685 */
679 686
680/* Called by gigaset_initcs() for setting up with the isdn4linux subsystem */ 687/* Called from common.c for setting up/shutting down with the ISDN subsystem */
681int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid); 688int gigaset_isdn_register(struct cardstate *cs, const char *isdnid);
689void gigaset_isdn_unregister(struct cardstate *cs);
682 690
683/* Called from xxx-gigaset.c to indicate completion of sending an skb */ 691/* Called from hardware module to indicate completion of an skb */
684void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb); 692void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
693void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb);
694void gigaset_isdn_rcv_err(struct bc_state *bcs);
685 695
686/* Called from common.c/ev-layer.c to indicate events relevant to the LL */ 696/* Called from common.c/ev-layer.c to indicate events relevant to the LL */
697void gigaset_isdn_start(struct cardstate *cs);
698void gigaset_isdn_stop(struct cardstate *cs);
687int gigaset_isdn_icall(struct at_state_t *at_state); 699int gigaset_isdn_icall(struct at_state_t *at_state);
688int gigaset_isdn_setup_accept(struct at_state_t *at_state); 700void gigaset_isdn_connD(struct bc_state *bcs);
689int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data); 701void gigaset_isdn_hupD(struct bc_state *bcs);
690 702void gigaset_isdn_connB(struct bc_state *bcs);
691void gigaset_i4l_cmd(struct cardstate *cs, int cmd); 703void gigaset_isdn_hupB(struct bc_state *bcs);
692void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd);
693
694
695static inline void gigaset_isdn_rcv_err(struct bc_state *bcs)
696{
697 isdn_ctrl response;
698
699 /* error -> LL */
700 gig_dbg(DEBUG_CMD, "sending L1ERR");
701 response.driver = bcs->cs->myid;
702 response.command = ISDN_STAT_L1ERR;
703 response.arg = bcs->channel;
704 response.parm.errcode = ISDN_STAT_L1ERR_RECV;
705 bcs->cs->iif.statcallb(&response);
706}
707 704
708/* =========================================================================== 705/* ===========================================================================
709 * Functions implemented in ev-layer.c 706 * Functions implemented in ev-layer.c
@@ -732,6 +729,7 @@ void gigaset_bcs_reinit(struct bc_state *bcs);
732void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs, 729void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
733 struct cardstate *cs, int cid); 730 struct cardstate *cs, int cid);
734int gigaset_get_channel(struct bc_state *bcs); 731int gigaset_get_channel(struct bc_state *bcs);
732struct bc_state *gigaset_get_free_channel(struct cardstate *cs);
735void gigaset_free_channel(struct bc_state *bcs); 733void gigaset_free_channel(struct bc_state *bcs);
736int gigaset_get_channels(struct cardstate *cs); 734int gigaset_get_channels(struct cardstate *cs);
737void gigaset_free_channels(struct cardstate *cs); 735void gigaset_free_channels(struct cardstate *cs);
@@ -816,35 +814,6 @@ static inline void gigaset_bchannel_up(struct bc_state *bcs)
816/* handling routines for sk_buff */ 814/* handling routines for sk_buff */
817/* ============================= */ 815/* ============================= */
818 816
819/* pass received skb to LL
820 * Warning: skb must not be accessed anymore!
821 */
822static inline void gigaset_rcv_skb(struct sk_buff *skb,
823 struct cardstate *cs,
824 struct bc_state *bcs)
825{
826 cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb);
827 bcs->trans_down++;
828}
829
830/* handle reception of corrupted skb
831 * Warning: skb must not be accessed anymore!
832 */
833static inline void gigaset_rcv_error(struct sk_buff *procskb,
834 struct cardstate *cs,
835 struct bc_state *bcs)
836{
837 if (procskb)
838 dev_kfree_skb(procskb);
839
840 if (bcs->ignore)
841 --bcs->ignore;
842 else {
843 ++bcs->corrupted;
844 gigaset_isdn_rcv_err(bcs);
845 }
846}
847
848/* append received bytes to inbuf */ 817/* append received bytes to inbuf */
849int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src, 818int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
850 unsigned numbytes); 819 unsigned numbytes);
diff --git a/drivers/isdn/gigaset/i4l.c b/drivers/isdn/gigaset/i4l.c
index 9b22f9cf2f3..aca72a06184 100644
--- a/drivers/isdn/gigaset/i4l.c
+++ b/drivers/isdn/gigaset/i4l.c
@@ -14,6 +14,9 @@
14 */ 14 */
15 15
16#include "gigaset.h" 16#include "gigaset.h"
17#include <linux/isdnif.h>
18
19#define HW_HDR_LEN 2 /* Header size used to store ack info */
17 20
18/* == Handling of I4L IO =====================================================*/ 21/* == Handling of I4L IO =====================================================*/
19 22
@@ -51,6 +54,12 @@ static int writebuf_from_LL(int driverID, int channel, int ack,
51 return -ENODEV; 54 return -ENODEV;
52 } 55 }
53 bcs = &cs->bcs[channel]; 56 bcs = &cs->bcs[channel];
57
58 /* can only handle linear sk_buffs */
59 if (skb_linearize(skb) < 0) {
60 dev_err(cs->dev, "%s: skb_linearize failed\n", __func__);
61 return -ENOMEM;
62 }
54 len = skb->len; 63 len = skb->len;
55 64
56 gig_dbg(DEBUG_LLDATA, 65 gig_dbg(DEBUG_LLDATA,
@@ -79,8 +88,17 @@ static int writebuf_from_LL(int driverID, int channel, int ack,
79 return cs->ops->send_skb(bcs, skb); 88 return cs->ops->send_skb(bcs, skb);
80} 89}
81 90
91/**
92 * gigaset_skb_sent() - acknowledge sending an skb
93 * @bcs: B channel descriptor structure.
94 * @skb: sent data.
95 *
96 * Called by hardware module {bas,ser,usb}_gigaset when the data in a
97 * skb has been successfully sent, for signalling completion to the LL.
98 */
82void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb) 99void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb)
83{ 100{
101 isdn_if *iif = bcs->cs->iif;
84 unsigned len; 102 unsigned len;
85 isdn_ctrl response; 103 isdn_ctrl response;
86 104
@@ -100,71 +118,177 @@ void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb)
100 response.command = ISDN_STAT_BSENT; 118 response.command = ISDN_STAT_BSENT;
101 response.arg = bcs->channel; 119 response.arg = bcs->channel;
102 response.parm.length = len; 120 response.parm.length = len;
103 bcs->cs->iif.statcallb(&response); 121 iif->statcallb(&response);
104 } 122 }
105} 123}
106EXPORT_SYMBOL_GPL(gigaset_skb_sent); 124EXPORT_SYMBOL_GPL(gigaset_skb_sent);
107 125
126/**
127 * gigaset_skb_rcvd() - pass received skb to LL
128 * @bcs: B channel descriptor structure.
129 * @skb: received data.
130 *
131 * Called by hardware module {bas,ser,usb}_gigaset when user data has
132 * been successfully received, for passing to the LL.
133 * Warning: skb must not be accessed anymore!
134 */
135void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
136{
137 isdn_if *iif = bcs->cs->iif;
138
139 iif->rcvcallb_skb(bcs->cs->myid, bcs->channel, skb);
140 bcs->trans_down++;
141}
142EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
143
144/**
145 * gigaset_isdn_rcv_err() - signal receive error
146 * @bcs: B channel descriptor structure.
147 *
148 * Called by hardware module {bas,ser,usb}_gigaset when a receive error
149 * has occurred, for signalling to the LL.
150 */
151void gigaset_isdn_rcv_err(struct bc_state *bcs)
152{
153 isdn_if *iif = bcs->cs->iif;
154 isdn_ctrl response;
155
156 /* if currently ignoring packets, just count down */
157 if (bcs->ignore) {
158 bcs->ignore--;
159 return;
160 }
161
162 /* update statistics */
163 bcs->corrupted++;
164
165 /* error -> LL */
166 gig_dbg(DEBUG_CMD, "sending L1ERR");
167 response.driver = bcs->cs->myid;
168 response.command = ISDN_STAT_L1ERR;
169 response.arg = bcs->channel;
170 response.parm.errcode = ISDN_STAT_L1ERR_RECV;
171 iif->statcallb(&response);
172}
173EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
174
108/* This function will be called by LL to send commands 175/* This function will be called by LL to send commands
109 * NOTE: LL ignores the returned value, for commands other than ISDN_CMD_IOCTL, 176 * NOTE: LL ignores the returned value, for commands other than ISDN_CMD_IOCTL,
110 * so don't put too much effort into it. 177 * so don't put too much effort into it.
111 */ 178 */
112static int command_from_LL(isdn_ctrl *cntrl) 179static int command_from_LL(isdn_ctrl *cntrl)
113{ 180{
114 struct cardstate *cs = gigaset_get_cs_by_id(cntrl->driver); 181 struct cardstate *cs;
115 struct bc_state *bcs; 182 struct bc_state *bcs;
116 int retval = 0; 183 int retval = 0;
117 struct setup_parm *sp; 184 char **commands;
185 int ch;
186 int i;
187 size_t l;
118 188
119 gigaset_debugdrivers(); 189 gigaset_debugdrivers();
120 190
121 if (!cs) { 191 gig_dbg(DEBUG_CMD, "driver: %d, command: %d, arg: 0x%lx",
192 cntrl->driver, cntrl->command, cntrl->arg);
193
194 cs = gigaset_get_cs_by_id(cntrl->driver);
195 if (cs == NULL) {
122 pr_err("%s: invalid driver ID (%d)\n", __func__, cntrl->driver); 196 pr_err("%s: invalid driver ID (%d)\n", __func__, cntrl->driver);
123 return -ENODEV; 197 return -ENODEV;
124 } 198 }
199 ch = cntrl->arg & 0xff;
125 200
126 switch (cntrl->command) { 201 switch (cntrl->command) {
127 case ISDN_CMD_IOCTL: 202 case ISDN_CMD_IOCTL:
128 gig_dbg(DEBUG_ANY, "ISDN_CMD_IOCTL (driver: %d, arg: %ld)",
129 cntrl->driver, cntrl->arg);
130
131 dev_warn(cs->dev, "ISDN_CMD_IOCTL not supported\n"); 203 dev_warn(cs->dev, "ISDN_CMD_IOCTL not supported\n");
132 return -EINVAL; 204 return -EINVAL;
133 205
134 case ISDN_CMD_DIAL: 206 case ISDN_CMD_DIAL:
135 gig_dbg(DEBUG_ANY, 207 gig_dbg(DEBUG_ANY,
136 "ISDN_CMD_DIAL (driver: %d, ch: %ld, " 208 "ISDN_CMD_DIAL (phone: %s, msn: %s, si1: %d, si2: %d)",
137 "phone: %s, ownmsn: %s, si1: %d, si2: %d)",
138 cntrl->driver, cntrl->arg,
139 cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn, 209 cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn,
140 cntrl->parm.setup.si1, cntrl->parm.setup.si2); 210 cntrl->parm.setup.si1, cntrl->parm.setup.si2);
141 211
142 if (cntrl->arg >= cs->channels) { 212 if (ch >= cs->channels) {
143 dev_err(cs->dev, 213 dev_err(cs->dev,
144 "ISDN_CMD_DIAL: invalid channel (%d)\n", 214 "ISDN_CMD_DIAL: invalid channel (%d)\n", ch);
145 (int) cntrl->arg);
146 return -EINVAL; 215 return -EINVAL;
147 } 216 }
148 217 bcs = cs->bcs + ch;
149 bcs = cs->bcs + cntrl->arg;
150
151 if (!gigaset_get_channel(bcs)) { 218 if (!gigaset_get_channel(bcs)) {
152 dev_err(cs->dev, "ISDN_CMD_DIAL: channel not free\n"); 219 dev_err(cs->dev, "ISDN_CMD_DIAL: channel not free\n");
153 return -EBUSY; 220 return -EBUSY;
154 } 221 }
155 222
156 sp = kmalloc(sizeof *sp, GFP_ATOMIC); 223 commands = kzalloc(AT_NUM*(sizeof *commands), GFP_ATOMIC);
157 if (!sp) { 224 if (!commands) {
158 gigaset_free_channel(bcs); 225 gigaset_free_channel(bcs);
159 dev_err(cs->dev, "ISDN_CMD_DIAL: out of memory\n"); 226 dev_err(cs->dev, "ISDN_CMD_DIAL: out of memory\n");
160 return -ENOMEM; 227 return -ENOMEM;
161 } 228 }
162 *sp = cntrl->parm.setup;
163 229
164 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, sp, 230 l = 3 + strlen(cntrl->parm.setup.phone);
231 commands[AT_DIAL] = kmalloc(l, GFP_ATOMIC);
232 if (!commands[AT_DIAL])
233 goto oom;
234 if (cntrl->parm.setup.phone[0] == '*' &&
235 cntrl->parm.setup.phone[1] == '*') {
236 /* internal call: translate ** prefix to CTP value */
237 commands[AT_TYPE] = kstrdup("^SCTP=0\r", GFP_ATOMIC);
238 if (!commands[AT_TYPE])
239 goto oom;
240 snprintf(commands[AT_DIAL], l,
241 "D%s\r", cntrl->parm.setup.phone+2);
242 } else {
243 commands[AT_TYPE] = kstrdup("^SCTP=1\r", GFP_ATOMIC);
244 if (!commands[AT_TYPE])
245 goto oom;
246 snprintf(commands[AT_DIAL], l,
247 "D%s\r", cntrl->parm.setup.phone);
248 }
249
250 l = strlen(cntrl->parm.setup.eazmsn);
251 if (l) {
252 l += 8;
253 commands[AT_MSN] = kmalloc(l, GFP_ATOMIC);
254 if (!commands[AT_MSN])
255 goto oom;
256 snprintf(commands[AT_MSN], l, "^SMSN=%s\r",
257 cntrl->parm.setup.eazmsn);
258 }
259
260 switch (cntrl->parm.setup.si1) {
261 case 1: /* audio */
262 /* BC = 9090A3: 3.1 kHz audio, A-law */
263 commands[AT_BC] = kstrdup("^SBC=9090A3\r", GFP_ATOMIC);
264 if (!commands[AT_BC])
265 goto oom;
266 break;
267 case 7: /* data */
268 default: /* hope the app knows what it is doing */
269 /* BC = 8890: unrestricted digital information */
270 commands[AT_BC] = kstrdup("^SBC=8890\r", GFP_ATOMIC);
271 if (!commands[AT_BC])
272 goto oom;
273 }
274 /* ToDo: other si1 values, inspect si2, set HLC/LLC */
275
276 commands[AT_PROTO] = kmalloc(9, GFP_ATOMIC);
277 if (!commands[AT_PROTO])
278 goto oom;
279 snprintf(commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2);
280
281 commands[AT_ISO] = kmalloc(9, GFP_ATOMIC);
282 if (!commands[AT_ISO])
283 goto oom;
284 snprintf(commands[AT_ISO], 9, "^SISO=%u\r",
285 (unsigned) bcs->channel + 1);
286
287 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands,
165 bcs->at_state.seq_index, NULL)) { 288 bcs->at_state.seq_index, NULL)) {
166 //FIXME what should we do? 289 for (i = 0; i < AT_NUM; ++i)
167 kfree(sp); 290 kfree(commands[i]);
291 kfree(commands);
168 gigaset_free_channel(bcs); 292 gigaset_free_channel(bcs);
169 return -ENOMEM; 293 return -ENOMEM;
170 } 294 }
@@ -172,93 +296,83 @@ static int command_from_LL(isdn_ctrl *cntrl)
172 gig_dbg(DEBUG_CMD, "scheduling DIAL"); 296 gig_dbg(DEBUG_CMD, "scheduling DIAL");
173 gigaset_schedule_event(cs); 297 gigaset_schedule_event(cs);
174 break; 298 break;
175 case ISDN_CMD_ACCEPTD: //FIXME 299 case ISDN_CMD_ACCEPTD:
176 gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTD"); 300 if (ch >= cs->channels) {
177
178 if (cntrl->arg >= cs->channels) {
179 dev_err(cs->dev, 301 dev_err(cs->dev,
180 "ISDN_CMD_ACCEPTD: invalid channel (%d)\n", 302 "ISDN_CMD_ACCEPTD: invalid channel (%d)\n", ch);
181 (int) cntrl->arg);
182 return -EINVAL; 303 return -EINVAL;
183 } 304 }
184 305 bcs = cs->bcs + ch;
185 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state, 306 if (!gigaset_add_event(cs, &bcs->at_state,
186 EV_ACCEPT, NULL, 0, NULL)) { 307 EV_ACCEPT, NULL, 0, NULL))
187 //FIXME what should we do?
188 return -ENOMEM; 308 return -ENOMEM;
189 }
190 309
191 gig_dbg(DEBUG_CMD, "scheduling ACCEPT"); 310 gig_dbg(DEBUG_CMD, "scheduling ACCEPT");
192 gigaset_schedule_event(cs); 311 gigaset_schedule_event(cs);
193 312
194 break; 313 break;
195 case ISDN_CMD_ACCEPTB: 314 case ISDN_CMD_ACCEPTB:
196 gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTB");
197 break; 315 break;
198 case ISDN_CMD_HANGUP: 316 case ISDN_CMD_HANGUP:
199 gig_dbg(DEBUG_ANY, "ISDN_CMD_HANGUP (ch: %d)", 317 if (ch >= cs->channels) {
200 (int) cntrl->arg);
201
202 if (cntrl->arg >= cs->channels) {
203 dev_err(cs->dev, 318 dev_err(cs->dev,
204 "ISDN_CMD_HANGUP: invalid channel (%d)\n", 319 "ISDN_CMD_HANGUP: invalid channel (%d)\n", ch);
205 (int) cntrl->arg);
206 return -EINVAL; 320 return -EINVAL;
207 } 321 }
208 322 bcs = cs->bcs + ch;
209 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state, 323 if (!gigaset_add_event(cs, &bcs->at_state,
210 EV_HUP, NULL, 0, NULL)) { 324 EV_HUP, NULL, 0, NULL))
211 //FIXME what should we do?
212 return -ENOMEM; 325 return -ENOMEM;
213 }
214 326
215 gig_dbg(DEBUG_CMD, "scheduling HUP"); 327 gig_dbg(DEBUG_CMD, "scheduling HUP");
216 gigaset_schedule_event(cs); 328 gigaset_schedule_event(cs);
217 329
218 break; 330 break;
219 case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */ //FIXME 331 case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */
220 gig_dbg(DEBUG_ANY, "ISDN_CMD_CLREAZ"); 332 dev_info(cs->dev, "ignoring ISDN_CMD_CLREAZ\n");
221 break; 333 break;
222 case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */ //FIXME 334 case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */
223 gig_dbg(DEBUG_ANY, 335 dev_info(cs->dev, "ignoring ISDN_CMD_SETEAZ (%s)\n",
224 "ISDN_CMD_SETEAZ (id: %d, ch: %ld, number: %s)", 336 cntrl->parm.num);
225 cntrl->driver, cntrl->arg, cntrl->parm.num);
226 break; 337 break;
227 case ISDN_CMD_SETL2: /* Set L2 to given protocol */ 338 case ISDN_CMD_SETL2: /* Set L2 to given protocol */
228 gig_dbg(DEBUG_ANY, "ISDN_CMD_SETL2 (ch: %ld, proto: %lx)", 339 if (ch >= cs->channels) {
229 cntrl->arg & 0xff, (cntrl->arg >> 8));
230
231 if ((cntrl->arg & 0xff) >= cs->channels) {
232 dev_err(cs->dev, 340 dev_err(cs->dev,
233 "ISDN_CMD_SETL2: invalid channel (%d)\n", 341 "ISDN_CMD_SETL2: invalid channel (%d)\n", ch);
234 (int) cntrl->arg & 0xff);
235 return -EINVAL; 342 return -EINVAL;
236 } 343 }
237 344 bcs = cs->bcs + ch;
238 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg & 0xff].at_state, 345 if (bcs->chstate & CHS_D_UP) {
239 EV_PROTO_L2, NULL, cntrl->arg >> 8, 346 dev_err(cs->dev,
240 NULL)) { 347 "ISDN_CMD_SETL2: channel active (%d)\n", ch);
241 //FIXME what should we do? 348 return -EINVAL;
242 return -ENOMEM; 349 }
350 switch (cntrl->arg >> 8) {
351 case ISDN_PROTO_L2_HDLC:
352 gig_dbg(DEBUG_CMD, "ISDN_CMD_SETL2: setting L2_HDLC");
353 bcs->proto2 = L2_HDLC;
354 break;
355 case ISDN_PROTO_L2_TRANS:
356 gig_dbg(DEBUG_CMD, "ISDN_CMD_SETL2: setting L2_VOICE");
357 bcs->proto2 = L2_VOICE;
358 break;
359 default:
360 dev_err(cs->dev,
361 "ISDN_CMD_SETL2: unsupported protocol (%lu)\n",
362 cntrl->arg >> 8);
363 return -EINVAL;
243 } 364 }
244
245 gig_dbg(DEBUG_CMD, "scheduling PROTO_L2");
246 gigaset_schedule_event(cs);
247 break; 365 break;
248 case ISDN_CMD_SETL3: /* Set L3 to given protocol */ 366 case ISDN_CMD_SETL3: /* Set L3 to given protocol */
249 gig_dbg(DEBUG_ANY, "ISDN_CMD_SETL3 (ch: %ld, proto: %lx)", 367 if (ch >= cs->channels) {
250 cntrl->arg & 0xff, (cntrl->arg >> 8));
251
252 if ((cntrl->arg & 0xff) >= cs->channels) {
253 dev_err(cs->dev, 368 dev_err(cs->dev,
254 "ISDN_CMD_SETL3: invalid channel (%d)\n", 369 "ISDN_CMD_SETL3: invalid channel (%d)\n", ch);
255 (int) cntrl->arg & 0xff);
256 return -EINVAL; 370 return -EINVAL;
257 } 371 }
258 372
259 if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) { 373 if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) {
260 dev_err(cs->dev, 374 dev_err(cs->dev,
261 "ISDN_CMD_SETL3: invalid protocol %lu\n", 375 "ISDN_CMD_SETL3: unsupported protocol (%lu)\n",
262 cntrl->arg >> 8); 376 cntrl->arg >> 8);
263 return -EINVAL; 377 return -EINVAL;
264 } 378 }
@@ -310,155 +424,50 @@ static int command_from_LL(isdn_ctrl *cntrl)
310 } 424 }
311 425
312 return retval; 426 return retval;
427
428oom:
429 dev_err(bcs->cs->dev, "out of memory\n");
430 for (i = 0; i < AT_NUM; ++i)
431 kfree(commands[i]);
432 return -ENOMEM;
313} 433}
314 434
315void gigaset_i4l_cmd(struct cardstate *cs, int cmd) 435static void gigaset_i4l_cmd(struct cardstate *cs, int cmd)
316{ 436{
437 isdn_if *iif = cs->iif;
317 isdn_ctrl command; 438 isdn_ctrl command;
318 439
319 command.driver = cs->myid; 440 command.driver = cs->myid;
320 command.command = cmd; 441 command.command = cmd;
321 command.arg = 0; 442 command.arg = 0;
322 cs->iif.statcallb(&command); 443 iif->statcallb(&command);
323} 444}
324 445
325void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd) 446static void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd)
326{ 447{
448 isdn_if *iif = bcs->cs->iif;
327 isdn_ctrl command; 449 isdn_ctrl command;
328 450
329 command.driver = bcs->cs->myid; 451 command.driver = bcs->cs->myid;
330 command.command = cmd; 452 command.command = cmd;
331 command.arg = bcs->channel; 453 command.arg = bcs->channel;
332 bcs->cs->iif.statcallb(&command); 454 iif->statcallb(&command);
333}
334
335int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data)
336{
337 struct bc_state *bcs = at_state->bcs;
338 unsigned proto;
339 const char *bc;
340 size_t length[AT_NUM];
341 size_t l;
342 int i;
343 struct setup_parm *sp = data;
344
345 switch (bcs->proto2) {
346 case ISDN_PROTO_L2_HDLC:
347 proto = 1; /* 0: Bitsynchron, 1: HDLC, 2: voice */
348 break;
349 case ISDN_PROTO_L2_TRANS:
350 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
351 break;
352 default:
353 dev_err(bcs->cs->dev, "%s: invalid L2 protocol: %u\n",
354 __func__, bcs->proto2);
355 return -EINVAL;
356 }
357
358 switch (sp->si1) {
359 case 1: /* audio */
360 bc = "9090A3"; /* 3.1 kHz audio, A-law */
361 break;
362 case 7: /* data */
363 default: /* hope the app knows what it is doing */
364 bc = "8890"; /* unrestricted digital information */
365 }
366 //FIXME add missing si1 values from 1TR6, inspect si2, set HLC/LLC
367
368 length[AT_DIAL ] = 1 + strlen(sp->phone) + 1 + 1;
369 l = strlen(sp->eazmsn);
370 length[AT_MSN ] = l ? 6 + l + 1 + 1 : 0;
371 length[AT_BC ] = 5 + strlen(bc) + 1 + 1;
372 length[AT_PROTO] = 6 + 1 + 1 + 1; /* proto: 1 character */
373 length[AT_ISO ] = 6 + 1 + 1 + 1; /* channel: 1 character */
374 length[AT_TYPE ] = 6 + 1 + 1 + 1; /* call type: 1 character */
375 length[AT_HLC ] = 0;
376
377 for (i = 0; i < AT_NUM; ++i) {
378 kfree(bcs->commands[i]);
379 bcs->commands[i] = NULL;
380 if (length[i] &&
381 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) {
382 dev_err(bcs->cs->dev, "out of memory\n");
383 return -ENOMEM;
384 }
385 }
386
387 /* type = 1: extern, 0: intern, 2: recall, 3: door, 4: centrex */
388 if (sp->phone[0] == '*' && sp->phone[1] == '*') {
389 /* internal call: translate ** prefix to CTP value */
390 snprintf(bcs->commands[AT_DIAL], length[AT_DIAL],
391 "D%s\r", sp->phone+2);
392 strncpy(bcs->commands[AT_TYPE], "^SCTP=0\r", length[AT_TYPE]);
393 } else {
394 snprintf(bcs->commands[AT_DIAL], length[AT_DIAL],
395 "D%s\r", sp->phone);
396 strncpy(bcs->commands[AT_TYPE], "^SCTP=1\r", length[AT_TYPE]);
397 }
398
399 if (bcs->commands[AT_MSN])
400 snprintf(bcs->commands[AT_MSN], length[AT_MSN],
401 "^SMSN=%s\r", sp->eazmsn);
402 snprintf(bcs->commands[AT_BC ], length[AT_BC ],
403 "^SBC=%s\r", bc);
404 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO],
405 "^SBPR=%u\r", proto);
406 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ],
407 "^SISO=%u\r", (unsigned)bcs->channel + 1);
408
409 return 0;
410}
411
412int gigaset_isdn_setup_accept(struct at_state_t *at_state)
413{
414 unsigned proto;
415 size_t length[AT_NUM];
416 int i;
417 struct bc_state *bcs = at_state->bcs;
418
419 switch (bcs->proto2) {
420 case ISDN_PROTO_L2_HDLC:
421 proto = 1; /* 0: Bitsynchron, 1: HDLC, 2: voice */
422 break;
423 case ISDN_PROTO_L2_TRANS:
424 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
425 break;
426 default:
427 dev_err(at_state->cs->dev, "%s: invalid protocol: %u\n",
428 __func__, bcs->proto2);
429 return -EINVAL;
430 }
431
432 length[AT_DIAL ] = 0;
433 length[AT_MSN ] = 0;
434 length[AT_BC ] = 0;
435 length[AT_PROTO] = 6 + 1 + 1 + 1; /* proto: 1 character */
436 length[AT_ISO ] = 6 + 1 + 1 + 1; /* channel: 1 character */
437 length[AT_TYPE ] = 0;
438 length[AT_HLC ] = 0;
439
440 for (i = 0; i < AT_NUM; ++i) {
441 kfree(bcs->commands[i]);
442 bcs->commands[i] = NULL;
443 if (length[i] &&
444 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) {
445 dev_err(at_state->cs->dev, "out of memory\n");
446 return -ENOMEM;
447 }
448 }
449
450 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO],
451 "^SBPR=%u\r", proto);
452 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ],
453 "^SISO=%u\r", (unsigned) bcs->channel + 1);
454
455 return 0;
456} 455}
457 456
457/**
458 * gigaset_isdn_icall() - signal incoming call
459 * @at_state: connection state structure.
460 *
461 * Called by main module to notify the LL that an incoming call has been
462 * received. @at_state contains the parameters of the call.
463 *
464 * Return value: call disposition (ICALL_*)
465 */
458int gigaset_isdn_icall(struct at_state_t *at_state) 466int gigaset_isdn_icall(struct at_state_t *at_state)
459{ 467{
460 struct cardstate *cs = at_state->cs; 468 struct cardstate *cs = at_state->cs;
461 struct bc_state *bcs = at_state->bcs; 469 struct bc_state *bcs = at_state->bcs;
470 isdn_if *iif = cs->iif;
462 isdn_ctrl response; 471 isdn_ctrl response;
463 int retval; 472 int retval;
464 473
@@ -508,7 +517,7 @@ int gigaset_isdn_icall(struct at_state_t *at_state)
508 response.arg = bcs->channel; //FIXME 517 response.arg = bcs->channel; //FIXME
509 } 518 }
510 response.driver = cs->myid; 519 response.driver = cs->myid;
511 retval = cs->iif.statcallb(&response); 520 retval = iif->statcallb(&response);
512 gig_dbg(DEBUG_CMD, "Response: %d", retval); 521 gig_dbg(DEBUG_CMD, "Response: %d", retval);
513 switch (retval) { 522 switch (retval) {
514 case 0: /* no takers */ 523 case 0: /* no takers */
@@ -537,16 +546,109 @@ int gigaset_isdn_icall(struct at_state_t *at_state)
537 } 546 }
538} 547}
539 548
540/* Set Callback function pointer */ 549/**
541int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid) 550 * gigaset_isdn_connD() - signal D channel connect
551 * @bcs: B channel descriptor structure.
552 *
553 * Called by main module to notify the LL that the D channel connection has
554 * been established.
555 */
556void gigaset_isdn_connD(struct bc_state *bcs)
557{
558 gig_dbg(DEBUG_CMD, "sending DCONN");
559 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN);
560}
561
562/**
563 * gigaset_isdn_hupD() - signal D channel hangup
564 * @bcs: B channel descriptor structure.
565 *
566 * Called by main module to notify the LL that the D channel connection has
567 * been shut down.
568 */
569void gigaset_isdn_hupD(struct bc_state *bcs)
570{
571 gig_dbg(DEBUG_CMD, "sending DHUP");
572 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DHUP);
573}
574
575/**
576 * gigaset_isdn_connB() - signal B channel connect
577 * @bcs: B channel descriptor structure.
578 *
579 * Called by main module to notify the LL that the B channel connection has
580 * been established.
581 */
582void gigaset_isdn_connB(struct bc_state *bcs)
583{
584 gig_dbg(DEBUG_CMD, "sending BCONN");
585 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BCONN);
586}
587
588/**
589 * gigaset_isdn_hupB() - signal B channel hangup
590 * @bcs: B channel descriptor structure.
591 *
592 * Called by main module to notify the LL that the B channel connection has
593 * been shut down.
594 */
595void gigaset_isdn_hupB(struct bc_state *bcs)
596{
597 gig_dbg(DEBUG_CMD, "sending BHUP");
598 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BHUP);
599}
600
601/**
602 * gigaset_isdn_start() - signal device availability
603 * @cs: device descriptor structure.
604 *
605 * Called by main module to notify the LL that the device is available for
606 * use.
607 */
608void gigaset_isdn_start(struct cardstate *cs)
609{
610 gig_dbg(DEBUG_CMD, "sending RUN");
611 gigaset_i4l_cmd(cs, ISDN_STAT_RUN);
612}
613
614/**
615 * gigaset_isdn_stop() - signal device unavailability
616 * @cs: device descriptor structure.
617 *
618 * Called by main module to notify the LL that the device is no longer
619 * available for use.
620 */
621void gigaset_isdn_stop(struct cardstate *cs)
622{
623 gig_dbg(DEBUG_CMD, "sending STOP");
624 gigaset_i4l_cmd(cs, ISDN_STAT_STOP);
625}
626
627/**
628 * gigaset_isdn_register() - register to LL
629 * @cs: device descriptor structure.
630 * @isdnid: device name.
631 *
632 * Called by main module to register the device with the LL.
633 *
634 * Return value: 1 for success, 0 for failure
635 */
636int gigaset_isdn_register(struct cardstate *cs, const char *isdnid)
542{ 637{
543 isdn_if *iif = &cs->iif; 638 isdn_if *iif;
544 639
545 gig_dbg(DEBUG_ANY, "Register driver capabilities to LL"); 640 pr_info("ISDN4Linux interface\n");
641
642 iif = kmalloc(sizeof *iif, GFP_KERNEL);
643 if (!iif) {
644 pr_err("out of memory\n");
645 return 0;
646 }
546 647
547 if (snprintf(iif->id, sizeof iif->id, "%s_%u", isdnid, cs->minor_index) 648 if (snprintf(iif->id, sizeof iif->id, "%s_%u", isdnid, cs->minor_index)
548 >= sizeof iif->id) { 649 >= sizeof iif->id) {
549 pr_err("ID too long: %s\n", isdnid); 650 pr_err("ID too long: %s\n", isdnid);
651 kfree(iif);
550 return 0; 652 return 0;
551 } 653 }
552 654
@@ -570,9 +672,26 @@ int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid)
570 672
571 if (!register_isdn(iif)) { 673 if (!register_isdn(iif)) {
572 pr_err("register_isdn failed\n"); 674 pr_err("register_isdn failed\n");
675 kfree(iif);
573 return 0; 676 return 0;
574 } 677 }
575 678
679 cs->iif = iif;
576 cs->myid = iif->channels; /* Set my device id */ 680 cs->myid = iif->channels; /* Set my device id */
681 cs->hw_hdr_len = HW_HDR_LEN;
577 return 1; 682 return 1;
578} 683}
684
685/**
686 * gigaset_isdn_unregister() - unregister from LL
687 * @cs: device descriptor structure.
688 *
689 * Called by main module to unregister the device from the LL.
690 */
691void gigaset_isdn_unregister(struct cardstate *cs)
692{
693 gig_dbg(DEBUG_CMD, "sending UNLOAD");
694 gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD);
695 kfree(cs->iif);
696 cs->iif = NULL;
697}
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
index f33ac27de64..6a8e1384e7b 100644
--- a/drivers/isdn/gigaset/interface.c
+++ b/drivers/isdn/gigaset/interface.c
@@ -616,6 +616,15 @@ void gigaset_if_free(struct cardstate *cs)
616 tty_unregister_device(drv->tty, cs->minor_index); 616 tty_unregister_device(drv->tty, cs->minor_index);
617} 617}
618 618
619/**
620 * gigaset_if_receive() - pass a received block of data to the tty device
621 * @cs: device descriptor structure.
622 * @buffer: received data.
623 * @len: number of bytes received.
624 *
625 * Called by asyncdata/isocdata if a block of data received from the
626 * device must be sent to userspace through the ttyG* device.
627 */
619void gigaset_if_receive(struct cardstate *cs, 628void gigaset_if_receive(struct cardstate *cs,
620 unsigned char *buffer, size_t len) 629 unsigned char *buffer, size_t len)
621{ 630{
diff --git a/drivers/isdn/gigaset/isocdata.c b/drivers/isdn/gigaset/isocdata.c
index bed38fcc432..7dabfd35874 100644
--- a/drivers/isdn/gigaset/isocdata.c
+++ b/drivers/isdn/gigaset/isocdata.c
@@ -429,7 +429,7 @@ static inline int hdlc_buildframe(struct isowbuf_t *iwb,
429 return -EAGAIN; 429 return -EAGAIN;
430 } 430 }
431 431
432 dump_bytes(DEBUG_STREAM, "snd data", in, count); 432 dump_bytes(DEBUG_STREAM_DUMP, "snd data", in, count);
433 433
434 /* bitstuff and checksum input data */ 434 /* bitstuff and checksum input data */
435 fcs = PPP_INITFCS; 435 fcs = PPP_INITFCS;
@@ -448,7 +448,6 @@ static inline int hdlc_buildframe(struct isowbuf_t *iwb,
448 /* put closing flag and repeat byte for flag idle */ 448 /* put closing flag and repeat byte for flag idle */
449 isowbuf_putflag(iwb); 449 isowbuf_putflag(iwb);
450 end = isowbuf_donewrite(iwb); 450 end = isowbuf_donewrite(iwb);
451 dump_bytes(DEBUG_STREAM_DUMP, "isowbuf", iwb->data, end + 1);
452 return end; 451 return end;
453} 452}
454 453
@@ -482,6 +481,8 @@ static inline int trans_buildframe(struct isowbuf_t *iwb,
482 } 481 }
483 482
484 gig_dbg(DEBUG_STREAM, "put %d bytes", count); 483 gig_dbg(DEBUG_STREAM, "put %d bytes", count);
484 dump_bytes(DEBUG_STREAM_DUMP, "snd data", in, count);
485
485 write = iwb->write; 486 write = iwb->write;
486 do { 487 do {
487 c = bitrev8(*in++); 488 c = bitrev8(*in++);
@@ -499,7 +500,7 @@ int gigaset_isoc_buildframe(struct bc_state *bcs, unsigned char *in, int len)
499 int result; 500 int result;
500 501
501 switch (bcs->proto2) { 502 switch (bcs->proto2) {
502 case ISDN_PROTO_L2_HDLC: 503 case L2_HDLC:
503 result = hdlc_buildframe(bcs->hw.bas->isooutbuf, in, len); 504 result = hdlc_buildframe(bcs->hw.bas->isooutbuf, in, len);
504 gig_dbg(DEBUG_ISO, "%s: %d bytes HDLC -> %d", 505 gig_dbg(DEBUG_ISO, "%s: %d bytes HDLC -> %d",
505 __func__, len, result); 506 __func__, len, result);
@@ -541,8 +542,9 @@ static inline void hdlc_flush(struct bc_state *bcs)
541 if (likely(bcs->skb != NULL)) 542 if (likely(bcs->skb != NULL))
542 skb_trim(bcs->skb, 0); 543 skb_trim(bcs->skb, 0);
543 else if (!bcs->ignore) { 544 else if (!bcs->ignore) {
544 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 545 bcs->skb = dev_alloc_skb(SBUFSIZE + bcs->cs->hw_hdr_len);
545 skb_reserve(bcs->skb, HW_HDR_LEN); 546 if (bcs->skb)
547 skb_reserve(bcs->skb, bcs->cs->hw_hdr_len);
546 else 548 else
547 dev_err(bcs->cs->dev, "could not allocate skb\n"); 549 dev_err(bcs->cs->dev, "could not allocate skb\n");
548 } 550 }
@@ -556,7 +558,9 @@ static inline void hdlc_flush(struct bc_state *bcs)
556 */ 558 */
557static inline void hdlc_done(struct bc_state *bcs) 559static inline void hdlc_done(struct bc_state *bcs)
558{ 560{
561 struct cardstate *cs = bcs->cs;
559 struct sk_buff *procskb; 562 struct sk_buff *procskb;
563 unsigned int len;
560 564
561 if (unlikely(bcs->ignore)) { 565 if (unlikely(bcs->ignore)) {
562 bcs->ignore--; 566 bcs->ignore--;
@@ -567,32 +571,33 @@ static inline void hdlc_done(struct bc_state *bcs)
567 if ((procskb = bcs->skb) == NULL) { 571 if ((procskb = bcs->skb) == NULL) {
568 /* previous error */ 572 /* previous error */
569 gig_dbg(DEBUG_ISO, "%s: skb=NULL", __func__); 573 gig_dbg(DEBUG_ISO, "%s: skb=NULL", __func__);
570 gigaset_rcv_error(NULL, bcs->cs, bcs); 574 gigaset_isdn_rcv_err(bcs);
571 } else if (procskb->len < 2) { 575 } else if (procskb->len < 2) {
572 dev_notice(bcs->cs->dev, "received short frame (%d octets)\n", 576 dev_notice(cs->dev, "received short frame (%d octets)\n",
573 procskb->len); 577 procskb->len);
574 bcs->hw.bas->runts++; 578 bcs->hw.bas->runts++;
575 gigaset_rcv_error(procskb, bcs->cs, bcs); 579 dev_kfree_skb(procskb);
580 gigaset_isdn_rcv_err(bcs);
576 } else if (bcs->fcs != PPP_GOODFCS) { 581 } else if (bcs->fcs != PPP_GOODFCS) {
577 dev_notice(bcs->cs->dev, "frame check error (0x%04x)\n", 582 dev_notice(cs->dev, "frame check error (0x%04x)\n", bcs->fcs);
578 bcs->fcs);
579 bcs->hw.bas->fcserrs++; 583 bcs->hw.bas->fcserrs++;
580 gigaset_rcv_error(procskb, bcs->cs, bcs); 584 dev_kfree_skb(procskb);
585 gigaset_isdn_rcv_err(bcs);
581 } else { 586 } else {
582 procskb->len -= 2; /* subtract FCS */ 587 len = procskb->len;
583 procskb->tail -= 2; 588 __skb_trim(procskb, len -= 2); /* subtract FCS */
584 gig_dbg(DEBUG_ISO, "%s: good frame (%d octets)", 589 gig_dbg(DEBUG_ISO, "%s: good frame (%d octets)", __func__, len);
585 __func__, procskb->len); 590 dump_bytes(DEBUG_STREAM_DUMP,
586 dump_bytes(DEBUG_STREAM, 591 "rcv data", procskb->data, len);
587 "rcv data", procskb->data, procskb->len); 592 bcs->hw.bas->goodbytes += len;
588 bcs->hw.bas->goodbytes += procskb->len; 593 gigaset_skb_rcvd(bcs, procskb);
589 gigaset_rcv_skb(procskb, bcs->cs, bcs);
590 } 594 }
591 595
592 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 596 bcs->skb = dev_alloc_skb(SBUFSIZE + cs->hw_hdr_len);
593 skb_reserve(bcs->skb, HW_HDR_LEN); 597 if (bcs->skb)
598 skb_reserve(bcs->skb, cs->hw_hdr_len);
594 else 599 else
595 dev_err(bcs->cs->dev, "could not allocate skb\n"); 600 dev_err(cs->dev, "could not allocate skb\n");
596 bcs->fcs = PPP_INITFCS; 601 bcs->fcs = PPP_INITFCS;
597} 602}
598 603
@@ -609,12 +614,8 @@ static inline void hdlc_frag(struct bc_state *bcs, unsigned inbits)
609 614
610 dev_notice(bcs->cs->dev, "received partial byte (%d bits)\n", inbits); 615 dev_notice(bcs->cs->dev, "received partial byte (%d bits)\n", inbits);
611 bcs->hw.bas->alignerrs++; 616 bcs->hw.bas->alignerrs++;
612 gigaset_rcv_error(bcs->skb, bcs->cs, bcs); 617 gigaset_isdn_rcv_err(bcs);
613 618 __skb_trim(bcs->skb, 0);
614 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
615 skb_reserve(bcs->skb, HW_HDR_LEN);
616 else
617 dev_err(bcs->cs->dev, "could not allocate skb\n");
618 bcs->fcs = PPP_INITFCS; 619 bcs->fcs = PPP_INITFCS;
619} 620}
620 621
@@ -647,8 +648,8 @@ static const unsigned char bitcounts[256] = {
647/* hdlc_unpack 648/* hdlc_unpack
648 * perform HDLC frame processing (bit unstuffing, flag detection, FCS calculation) 649 * perform HDLC frame processing (bit unstuffing, flag detection, FCS calculation)
649 * on a sequence of received data bytes (8 bits each, LSB first) 650 * on a sequence of received data bytes (8 bits each, LSB first)
650 * pass on successfully received, complete frames as SKBs via gigaset_rcv_skb 651 * pass on successfully received, complete frames as SKBs via gigaset_skb_rcvd
651 * notify of errors via gigaset_rcv_error 652 * notify of errors via gigaset_isdn_rcv_err
652 * tally frames, errors etc. in BC structure counters 653 * tally frames, errors etc. in BC structure counters
653 * parameters: 654 * parameters:
654 * src received data 655 * src received data
@@ -840,7 +841,7 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
840} 841}
841 842
842/* trans_receive 843/* trans_receive
843 * pass on received USB frame transparently as SKB via gigaset_rcv_skb 844 * pass on received USB frame transparently as SKB via gigaset_skb_rcvd
844 * invert bytes 845 * invert bytes
845 * tally frames, errors etc. in BC structure counters 846 * tally frames, errors etc. in BC structure counters
846 * parameters: 847 * parameters:
@@ -851,6 +852,7 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
851static inline void trans_receive(unsigned char *src, unsigned count, 852static inline void trans_receive(unsigned char *src, unsigned count,
852 struct bc_state *bcs) 853 struct bc_state *bcs)
853{ 854{
855 struct cardstate *cs = bcs->cs;
854 struct sk_buff *skb; 856 struct sk_buff *skb;
855 int dobytes; 857 int dobytes;
856 unsigned char *dst; 858 unsigned char *dst;
@@ -861,12 +863,12 @@ static inline void trans_receive(unsigned char *src, unsigned count,
861 return; 863 return;
862 } 864 }
863 if (unlikely((skb = bcs->skb) == NULL)) { 865 if (unlikely((skb = bcs->skb) == NULL)) {
864 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN); 866 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + cs->hw_hdr_len);
865 if (!skb) { 867 if (!skb) {
866 dev_err(bcs->cs->dev, "could not allocate skb\n"); 868 dev_err(cs->dev, "could not allocate skb\n");
867 return; 869 return;
868 } 870 }
869 skb_reserve(skb, HW_HDR_LEN); 871 skb_reserve(skb, cs->hw_hdr_len);
870 } 872 }
871 bcs->hw.bas->goodbytes += skb->len; 873 bcs->hw.bas->goodbytes += skb->len;
872 dobytes = TRANSBUFSIZE - skb->len; 874 dobytes = TRANSBUFSIZE - skb->len;
@@ -878,14 +880,16 @@ static inline void trans_receive(unsigned char *src, unsigned count,
878 dobytes--; 880 dobytes--;
879 } 881 }
880 if (dobytes == 0) { 882 if (dobytes == 0) {
881 gigaset_rcv_skb(skb, bcs->cs, bcs); 883 dump_bytes(DEBUG_STREAM_DUMP,
882 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN); 884 "rcv data", skb->data, skb->len);
885 gigaset_skb_rcvd(bcs, skb);
886 bcs->skb = skb =
887 dev_alloc_skb(SBUFSIZE + cs->hw_hdr_len);
883 if (!skb) { 888 if (!skb) {
884 dev_err(bcs->cs->dev, 889 dev_err(cs->dev, "could not allocate skb\n");
885 "could not allocate skb\n");
886 return; 890 return;
887 } 891 }
888 skb_reserve(bcs->skb, HW_HDR_LEN); 892 skb_reserve(skb, cs->hw_hdr_len);
889 dobytes = TRANSBUFSIZE; 893 dobytes = TRANSBUFSIZE;
890 } 894 }
891 } 895 }
@@ -894,7 +898,7 @@ static inline void trans_receive(unsigned char *src, unsigned count,
894void gigaset_isoc_receive(unsigned char *src, unsigned count, struct bc_state *bcs) 898void gigaset_isoc_receive(unsigned char *src, unsigned count, struct bc_state *bcs)
895{ 899{
896 switch (bcs->proto2) { 900 switch (bcs->proto2) {
897 case ISDN_PROTO_L2_HDLC: 901 case L2_HDLC:
898 hdlc_unpack(src, count, bcs); 902 hdlc_unpack(src, count, bcs);
899 break; 903 break;
900 default: /* assume transparent */ 904 default: /* assume transparent */
@@ -973,16 +977,19 @@ void gigaset_isoc_input(struct inbuf_t *inbuf)
973 977
974/* == data output ========================================================== */ 978/* == data output ========================================================== */
975 979
976/* gigaset_send_skb 980/**
977 * called by common.c to queue an skb for sending 981 * gigaset_isoc_send_skb() - queue an skb for sending
978 * and start transmission if necessary 982 * @bcs: B channel descriptor structure.
979 * parameters: 983 * @skb: data to send.
980 * B Channel control structure 984 *
981 * skb 985 * Called by LL to queue an skb for sending, and start transmission if
982 * return value: 986 * necessary.
983 * number of bytes accepted for sending 987 * Once the payload data has been transmitted completely, gigaset_skb_sent()
984 * (skb->len if ok, 0 if out of buffer space) 988 * will be called with the first cs->hw_hdr_len bytes of skb->head preserved.
985 * or error code (< 0, eg. -EINVAL) 989 *
990 * Return value:
991 * number of bytes accepted for sending (skb->len) if ok,
992 * error code < 0 (eg. -ENODEV) on error
986 */ 993 */
987int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb) 994int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb)
988{ 995{
diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c
index feb0fa45b66..28182ed8dea 100644
--- a/drivers/isdn/mISDN/socket.c
+++ b/drivers/isdn/mISDN/socket.c
@@ -808,8 +808,7 @@ mISDN_sock_create(struct net *net, struct socket *sock, int proto)
808 return err; 808 return err;
809} 809}
810 810
811static struct 811static const struct net_proto_family mISDN_sock_family_ops = {
812net_proto_family mISDN_sock_family_ops = {
813 .owner = THIS_MODULE, 812 .owner = THIS_MODULE,
814 .family = PF_ISDN, 813 .family = PF_ISDN,
815 .create = mISDN_sock_create, 814 .create = mISDN_sock_create,