1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef GIGASET_H
17#define GIGASET_H
18
19#include <linux/kernel.h>
20#include <linux/compiler.h>
21#include <linux/types.h>
22#include <linux/spinlock.h>
23#include <linux/isdnif.h>
24#include <linux/usb.h>
25#include <linux/skbuff.h>
26#include <linux/netdevice.h>
27#include <linux/ppp_defs.h>
28#include <linux/timer.h>
29#include <linux/interrupt.h>
30#include <linux/tty.h>
31#include <linux/tty_driver.h>
32#include <linux/list.h>
33#include <asm/atomic.h>
34
35#define GIG_VERSION {0,5,0,0}
36#define GIG_COMPAT {0,4,0,0}
37
38#define MAX_REC_PARAMS 10
39#define MAX_RESP_SIZE 512
40#define HW_HDR_LEN 2
41
42#define MAX_EVENTS 64
43
44#define RBUFSIZE 8192
45#define SBUFSIZE 4096
46
47#define TRANSBUFSIZE 768
48#define MAX_BUF_SIZE (SBUFSIZE - 2)
49
50
51#define GIG_MAJOR 0
52
53#define GIG_MAYINITONDIAL
54#define GIG_RETRYCID
55#define GIG_X75
56
57#define GIG_TICK 100
58
59
60#define INIT_TIMEOUT 1
61
62
63#define RING_TIMEOUT 3
64#define BAS_TIMEOUT 20
65#define ATRDY_TIMEOUT 3
66
67#define BAS_RETRY 3
68
69#define MAXACT 3
70
71extern int gigaset_debuglevel;
72
73
74enum debuglevel {
75 DEBUG_INTR = 0x00008,
76 DEBUG_CMD = 0x00020,
77 DEBUG_STREAM = 0x00040,
78 DEBUG_STREAM_DUMP = 0x00080,
79 DEBUG_LLDATA = 0x00100,
80 DEBUG_DRIVER = 0x00400,
81 DEBUG_HDLC = 0x00800,
82 DEBUG_WRITE = 0x01000,
83 DEBUG_TRANSCMD = 0x02000,
84 DEBUG_MCMD = 0x04000,
85 DEBUG_INIT = 0x08000,
86
87 DEBUG_SUSPEND = 0x10000,
88 DEBUG_OUTPUT = 0x20000,
89 DEBUG_ISO = 0x40000,
90 DEBUG_IF = 0x80000,
91 DEBUG_USBREQ = 0x100000,
92
93 DEBUG_LOCKCMD = 0x200000,
94
95
96 DEBUG_ANY = 0x3fffff,
97
98};
99
100
101
102
103
104
105
106#undef err
107#undef info
108#undef warn
109
110#define err(format, arg...) printk(KERN_ERR KBUILD_MODNAME ": " \
111 format "\n" , ## arg)
112#define info(format, arg...) printk(KERN_INFO KBUILD_MODNAME ": " \
113 format "\n" , ## arg)
114#define warn(format, arg...) printk(KERN_WARNING KBUILD_MODNAME ": " \
115 format "\n" , ## arg)
116
117#ifdef CONFIG_GIGASET_DEBUG
118
119#define gig_dbg(level, format, arg...) \
120 do { \
121 if (unlikely(((enum debuglevel)gigaset_debuglevel) & (level))) \
122 printk(KERN_DEBUG KBUILD_MODNAME ": " format "\n", \
123 ## arg); \
124 } while (0)
125#define DEBUG_DEFAULT (DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ)
126
127#else
128
129#define gig_dbg(level, format, arg...) do {} while (0)
130#define DEBUG_DEFAULT 0
131
132#endif
133
134void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
135 size_t len, const unsigned char *buf);
136
137
138#define ZSAU_NONE 0
139#define ZSAU_DISCONNECT_IND 4
140#define ZSAU_OUTGOING_CALL_PROCEEDING 1
141#define ZSAU_PROCEEDING 1
142#define ZSAU_CALL_DELIVERED 2
143#define ZSAU_ACTIVE 3
144#define ZSAU_NULL 5
145#define ZSAU_DISCONNECT_REQ 6
146#define ZSAU_UNKNOWN -1
147
148
149#define OUT_VENDOR_REQ (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT)
150#define IN_VENDOR_REQ (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT)
151
152
153#define HD_B1_FLOW_CONTROL 0x80
154#define HD_B2_FLOW_CONTROL 0x81
155#define HD_RECEIVEATDATA_ACK (0x35)
156
157#define HD_READY_SEND_ATDATA (0x36)
158#define HD_OPEN_ATCHANNEL_ACK (0x37)
159#define HD_CLOSE_ATCHANNEL_ACK (0x38)
160#define HD_DEVICE_INIT_OK (0x11)
161#define HD_OPEN_B1CHANNEL_ACK (0x51)
162#define HD_OPEN_B2CHANNEL_ACK (0x52)
163#define HD_CLOSE_B1CHANNEL_ACK (0x53)
164#define HD_CLOSE_B2CHANNEL_ACK (0x54)
165
166#define HD_SUSPEND_END (0x61)
167
168#define HD_RESET_INTERRUPT_PIPE_ACK (0xFF)
169
170
171#define HD_OPEN_B1CHANNEL (0x23)
172#define HD_CLOSE_B1CHANNEL (0x24)
173#define HD_OPEN_B2CHANNEL (0x25)
174#define HD_CLOSE_B2CHANNEL (0x26)
175#define HD_RESET_INTERRUPT_PIPE (0x27)
176#define HD_DEVICE_INIT_ACK (0x34)
177#define HD_WRITE_ATMESSAGE (0x12)
178#define HD_READ_ATMESSAGE (0x13)
179#define HD_OPEN_ATCHANNEL (0x28)
180#define HD_CLOSE_ATCHANNEL (0x29)
181
182
183#define BAS_CHANNELS 2
184
185
186#define BAS_FRAMETIME 1
187#define BAS_NUMFRAMES 8
188#define BAS_MAXFRAME 16
189#define BAS_NORMFRAME 8
190#define BAS_HIGHFRAME 10
191#define BAS_LOWFRAME 5
192#define BAS_CORRFRAMES 4
193
194#define BAS_INBUFSIZE (BAS_MAXFRAME * BAS_NUMFRAMES)
195
196#define BAS_OUTBUFSIZE 4096
197#define BAS_OUTBUFPAD BAS_MAXFRAME
198
199#define BAS_INURBS 3
200#define BAS_OUTURBS 3
201
202
203#define AT_ISO 0
204#define AT_DIAL 1
205#define AT_MSN 2
206#define AT_BC 3
207#define AT_PROTO 4
208#define AT_TYPE 5
209#define AT_HLC 6
210#define AT_NUM 7
211
212
213#define VAR_ZSAU 0
214#define VAR_ZDLE 1
215#define VAR_ZVLS 2
216#define VAR_ZCTP 3
217#define VAR_NUM 4
218
219#define STR_NMBR 0
220#define STR_ZCPN 1
221#define STR_ZCON 2
222#define STR_ZBC 3
223#define STR_ZHLC 4
224#define STR_NUM 5
225
226#define EV_TIMEOUT -105
227#define EV_IF_VER -106
228#define EV_PROC_CIDMODE -107
229#define EV_SHUTDOWN -108
230#define EV_START -110
231#define EV_STOP -111
232#define EV_IF_LOCK -112
233#define EV_PROTO_L2 -113
234#define EV_ACCEPT -114
235#define EV_DIAL -115
236#define EV_HUP -116
237#define EV_BC_OPEN -117
238#define EV_BC_CLOSED -118
239
240
241#define INS_command 0x0001
242#define INS_DLE_char 0x0002
243#define INS_byte_stuff 0x0004
244#define INS_have_data 0x0008
245#define INS_skip_frame 0x0010
246#define INS_DLE_command 0x0020
247#define INS_flag_hunt 0x0040
248
249
250#define CHS_D_UP 0x01
251#define CHS_B_UP 0x02
252#define CHS_NOTIFY_LL 0x04
253
254#define ICALL_REJECT 0
255#define ICALL_ACCEPT 1
256#define ICALL_IGNORE 2
257
258
259#define MS_UNINITIALIZED 0
260#define MS_INIT 1
261#define MS_LOCKED 2
262#define MS_SHUTDOWN 3
263#define MS_RECOVER 4
264#define MS_READY 5
265
266
267#define M_UNKNOWN 0
268#define M_CONFIG 1
269#define M_UNIMODEM 2
270#define M_CID 3
271
272
273#define SM_LOCKED 0
274#define SM_ISDN 1
275
276struct gigaset_ops;
277struct gigaset_driver;
278
279struct usb_cardstate;
280struct ser_cardstate;
281struct bas_cardstate;
282
283struct bc_state;
284struct usb_bc_state;
285struct ser_bc_state;
286struct bas_bc_state;
287
288struct reply_t {
289 int resp_code;
290 int min_ConState;
291 int max_ConState;
292 int parameter;
293 int new_ConState;
294 int timeout;
295 int action[MAXACT];
296 char *command;
297};
298
299extern struct reply_t gigaset_tab_cid_m10x[];
300extern struct reply_t gigaset_tab_nocid_m10x[];
301
302struct inbuf_t {
303 unsigned char *rcvbuf;
304 struct bc_state *bcs;
305 struct cardstate *cs;
306 int inputstate;
307 int head, tail;
308 unsigned char data[RBUFSIZE];
309};
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328struct isowbuf_t {
329 int read;
330 int nextread;
331 int write;
332 atomic_t writesem;
333 int wbits;
334 unsigned char data[BAS_OUTBUFSIZE + BAS_OUTBUFPAD];
335 unsigned char idle;
336};
337
338
339
340
341
342
343
344
345
346struct isow_urbctx_t {
347 struct urb *urb;
348 struct bc_state *bcs;
349 int limit;
350 int status;
351};
352
353
354
355
356
357struct at_state_t {
358 struct list_head list;
359 int waiting;
360 int getstring;
361 unsigned timer_index;
362 unsigned long timer_expires;
363 int timer_active;
364 unsigned int ConState;
365 struct reply_t *replystruct;
366 int cid;
367 int int_var[VAR_NUM];
368 char *str_var[STR_NUM];
369 unsigned pending_commands;
370 unsigned seq_index;
371
372 struct cardstate *cs;
373 struct bc_state *bcs;
374};
375
376struct resp_type_t {
377 unsigned char *response;
378 int resp_code;
379 int type;
380};
381
382struct event_t {
383 int type;
384 void *ptr, *arg;
385 int parameter;
386 int cid;
387 struct at_state_t *at_state;
388};
389
390
391struct bc_state {
392 struct sk_buff *tx_skb;
393 struct sk_buff_head squeue;
394
395
396 int corrupted;
397 int trans_down;
398 int trans_up;
399
400 struct at_state_t at_state;
401 unsigned long rcvbytes;
402
403 __u16 fcs;
404 struct sk_buff *skb;
405 int inputstate;
406
407 int channel;
408
409 struct cardstate *cs;
410
411 unsigned chstate;
412 int ignore;
413 unsigned proto2;
414 char *commands[AT_NUM];
415
416#ifdef CONFIG_GIGASET_DEBUG
417 int emptycount;
418#endif
419 int busy;
420 int use_count;
421
422
423 union {
424 struct ser_bc_state *ser;
425 struct usb_bc_state *usb;
426 struct bas_bc_state *bas;
427 } hw;
428};
429
430struct cardstate {
431 struct gigaset_driver *driver;
432 unsigned minor_index;
433 struct device *dev;
434 struct device *tty_dev;
435 unsigned flags;
436
437 const struct gigaset_ops *ops;
438
439
440 wait_queue_head_t waitqueue;
441 int waiting;
442 int mode;
443 int mstate;
444
445 int cmd_result;
446
447 int channels;
448 struct bc_state *bcs;
449
450 int onechannel;
451
452
453 spinlock_t lock;
454 struct at_state_t at_state;
455 struct list_head temp_at_states;
456
457
458 struct inbuf_t *inbuf;
459
460 struct cmdbuf_t *cmdbuf, *lastcmdbuf;
461 spinlock_t cmdlock;
462 unsigned curlen, cmdbytes;
463
464 unsigned open_count;
465 struct tty_struct *tty;
466 struct tasklet_struct if_wake_tasklet;
467 unsigned control_state;
468
469 unsigned fwver[4];
470 int gotfwver;
471
472 unsigned running;
473 unsigned connected;
474 unsigned isdn_up;
475
476 unsigned cidmode;
477
478 int myid;
479 isdn_if iif;
480
481 struct reply_t *tabnocid;
482 struct reply_t *tabcid;
483 int cs_init;
484 int ignoreframes;
485
486 struct mutex mutex;
487
488
489
490
491
492 struct timer_list timer;
493 int retry_count;
494 int dle;
495
496 int cur_at_seq;
497
498 int curchannel;
499
500 int commands_pending;
501
502 struct tasklet_struct event_tasklet;
503
504
505
506
507
508
509
510
511 struct tasklet_struct write_tasklet;
512
513
514
515
516 struct event_t events[MAX_EVENTS];
517 unsigned ev_tail, ev_head;
518 spinlock_t ev_lock;
519
520
521 unsigned char respdata[MAX_RESP_SIZE];
522 unsigned cbytes;
523
524
525 union {
526 struct usb_cardstate *usb;
527 struct ser_cardstate *ser;
528 struct bas_cardstate *bas;
529 } hw;
530};
531
532struct gigaset_driver {
533 struct list_head list;
534 spinlock_t lock;
535 struct tty_driver *tty;
536 unsigned have_tty;
537 unsigned minor;
538 unsigned minors;
539 struct cardstate *cs;
540 int blocked;
541
542 const struct gigaset_ops *ops;
543 struct module *owner;
544};
545
546struct cmdbuf_t {
547 struct cmdbuf_t *next, *prev;
548 int len, offset;
549 struct tasklet_struct *wake_tasklet;
550 unsigned char buf[0];
551};
552
553struct bas_bc_state {
554
555 int running;
556 atomic_t corrbytes;
557 spinlock_t isooutlock;
558 struct isow_urbctx_t isoouturbs[BAS_OUTURBS];
559 struct isow_urbctx_t *isooutdone, *isooutfree, *isooutovfl;
560 struct isowbuf_t *isooutbuf;
561 unsigned numsub;
562
563 struct tasklet_struct sent_tasklet;
564
565
566 spinlock_t isoinlock;
567 struct urb *isoinurbs[BAS_INURBS];
568 unsigned char isoinbuf[BAS_INBUFSIZE * BAS_INURBS];
569 struct urb *isoindone;
570 int isoinstatus;
571 int loststatus;
572 unsigned isoinlost;
573
574
575 unsigned seqlen;
576
577 unsigned inbyte, inbits;
578
579 unsigned goodbytes;
580 unsigned alignerrs;
581 unsigned fcserrs;
582 unsigned frameerrs;
583 unsigned giants;
584 unsigned runts;
585 unsigned aborts;
586 unsigned shared0s;
587 unsigned stolen0s;
588
589 struct tasklet_struct rcvd_tasklet;
590};
591
592struct gigaset_ops {
593
594
595 int (*write_cmd)(struct cardstate *cs,
596 const unsigned char *buf, int len,
597 struct tasklet_struct *wake_tasklet);
598
599
600 int (*write_room)(struct cardstate *cs);
601 int (*chars_in_buffer)(struct cardstate *cs);
602 int (*brkchars)(struct cardstate *cs, const unsigned char buf[6]);
603
604
605
606 int (*init_bchannel)(struct bc_state *bcs);
607
608
609
610 int (*close_bchannel)(struct bc_state *bcs);
611
612
613 int (*initbcshw)(struct bc_state *bcs);
614
615
616 int (*freebcshw)(struct bc_state *bcs);
617
618
619 void (*reinitbcshw)(struct bc_state *bcs);
620
621
622 int (*initcshw)(struct cardstate *cs);
623
624
625 void (*freecshw)(struct cardstate *cs);
626
627
628
629 int (*set_modem_ctrl)(struct cardstate *cs, unsigned old_state,
630 unsigned new_state);
631 int (*baud_rate)(struct cardstate *cs, unsigned cflag);
632 int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag);
633
634
635 int (*send_skb)(struct bc_state *bcs, struct sk_buff *skb);
636
637
638
639 void (*handle_input)(struct inbuf_t *inbuf);
640
641};
642
643
644
645
646
647
648
649
650#define DLE_FLAG 0x10
651
652
653
654
655
656
657
658int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb);
659
660
661
662void gigaset_m10x_input(struct inbuf_t *inbuf);
663
664
665
666
667
668
669
670int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb);
671
672
673
674void gigaset_isoc_input(struct inbuf_t *inbuf);
675
676
677
678void gigaset_isoc_receive(unsigned char *src, unsigned count,
679 struct bc_state *bcs);
680
681
682
683int gigaset_isoc_buildframe(struct bc_state *bcs, unsigned char *in, int len);
684
685
686void gigaset_isowbuf_init(struct isowbuf_t *iwb, unsigned char idle);
687
688
689int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size);
690
691
692
693
694
695
696int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid);
697
698
699void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
700
701
702int gigaset_isdn_icall(struct at_state_t *at_state);
703int gigaset_isdn_setup_accept(struct at_state_t *at_state);
704int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data);
705
706void gigaset_i4l_cmd(struct cardstate *cs, int cmd);
707void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd);
708
709
710static inline void gigaset_isdn_rcv_err(struct bc_state *bcs)
711{
712 isdn_ctrl response;
713
714
715 gig_dbg(DEBUG_CMD, "sending L1ERR");
716 response.driver = bcs->cs->myid;
717 response.command = ISDN_STAT_L1ERR;
718 response.arg = bcs->channel;
719 response.parm.errcode = ISDN_STAT_L1ERR_RECV;
720 bcs->cs->iif.statcallb(&response);
721}
722
723
724
725
726
727
728void gigaset_handle_event(unsigned long data);
729
730
731
732void gigaset_handle_modem_response(struct cardstate *cs);
733
734
735
736
737
738
739void gigaset_init_dev_sysfs(struct cardstate *cs);
740void gigaset_free_dev_sysfs(struct cardstate *cs);
741
742
743
744
745
746void gigaset_bcs_reinit(struct bc_state *bcs);
747void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
748 struct cardstate *cs, int cid);
749int gigaset_get_channel(struct bc_state *bcs);
750void gigaset_free_channel(struct bc_state *bcs);
751int gigaset_get_channels(struct cardstate *cs);
752void gigaset_free_channels(struct cardstate *cs);
753void gigaset_block_channels(struct cardstate *cs);
754
755
756struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
757 const char *procname,
758 const char *devname,
759 const struct gigaset_ops *ops,
760 struct module *owner);
761
762
763void gigaset_freedriver(struct gigaset_driver *drv);
764void gigaset_debugdrivers(void);
765struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty);
766struct cardstate *gigaset_get_cs_by_id(int id);
767void gigaset_blockdriver(struct gigaset_driver *drv);
768
769
770
771struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
772 int onechannel, int ignoreframes,
773 int cidmode, const char *modulename);
774
775
776void gigaset_freecs(struct cardstate *cs);
777
778
779int gigaset_start(struct cardstate *cs);
780
781
782void gigaset_stop(struct cardstate *cs);
783
784
785int gigaset_shutdown(struct cardstate *cs);
786
787
788void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
789
790
791
792
793
794struct event_t *gigaset_add_event(struct cardstate *cs,
795 struct at_state_t *at_state, int type,
796 void *ptr, int parameter, void *arg);
797
798
799int gigaset_enterconfigmode(struct cardstate *cs);
800
801
802static inline void gigaset_schedule_event(struct cardstate *cs)
803{
804 unsigned long flags;
805 spin_lock_irqsave(&cs->lock, flags);
806 if (cs->running)
807 tasklet_schedule(&cs->event_tasklet);
808 spin_unlock_irqrestore(&cs->lock, flags);
809}
810
811
812
813static inline void gigaset_bchannel_down(struct bc_state *bcs)
814{
815 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL);
816
817 gig_dbg(DEBUG_CMD, "scheduling BC_CLOSED");
818 gigaset_schedule_event(bcs->cs);
819}
820
821
822
823static inline void gigaset_bchannel_up(struct bc_state *bcs)
824{
825 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL);
826
827 gig_dbg(DEBUG_CMD, "scheduling BC_OPEN");
828 gigaset_schedule_event(bcs->cs);
829}
830
831
832
833
834
835
836
837static inline void gigaset_rcv_skb(struct sk_buff *skb,
838 struct cardstate *cs,
839 struct bc_state *bcs)
840{
841 cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb);
842 bcs->trans_down++;
843}
844
845
846
847
848static inline void gigaset_rcv_error(struct sk_buff *procskb,
849 struct cardstate *cs,
850 struct bc_state *bcs)
851{
852 if (procskb)
853 dev_kfree_skb(procskb);
854
855 if (bcs->ignore)
856 --bcs->ignore;
857 else {
858 ++bcs->corrupted;
859 gigaset_isdn_rcv_err(bcs);
860 }
861}
862
863
864int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
865 unsigned numbytes);
866
867
868
869
870
871
872void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
873 const char *devname);
874
875void gigaset_if_freedriver(struct gigaset_driver *drv);
876
877void gigaset_if_init(struct cardstate *cs);
878
879void gigaset_if_free(struct cardstate *cs);
880
881void gigaset_if_receive(struct cardstate *cs,
882 unsigned char *buffer, size_t len);
883
884#endif
885