1 /* $Id: kcapi.c,v 1.1.2.8 2004/03/26 19:57:20 armin Exp $
3 * Kernel CAPI 2.0 Module
5 * Copyright 1999 by Carsten Paeth <calle@calle.de>
6 * Copyright 2002 by Kai Germaschewski <kai@germaschewski.name>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
16 #include <linux/module.h>
18 #include <linux/interrupt.h>
19 #include <linux/ioport.h>
20 #include <linux/proc_fs.h>
21 #include <linux/sched.h>
22 #include <linux/seq_file.h>
23 #include <linux/skbuff.h>
24 #include <linux/workqueue.h>
25 #include <linux/capi.h>
26 #include <linux/kernelcapi.h>
27 #include <linux/init.h>
28 #include <linux/moduleparam.h>
29 #include <linux/delay.h>
30 #include <asm/uaccess.h>
31 #include <linux/isdn/capicmd.h>
32 #include <linux/isdn/capiutil.h>
34 #include <linux/b1lli.h>
36 #include <linux/mutex.h>
38 static char *revision
= "$Revision: 1.1.2.8 $";
40 /* ------------------------------------------------------------- */
42 static int showcapimsgs
= 0;
44 MODULE_DESCRIPTION("CAPI4Linux: kernel CAPI layer");
45 MODULE_AUTHOR("Carsten Paeth");
46 MODULE_LICENSE("GPL");
47 module_param(showcapimsgs
, uint
, 0);
49 /* ------------------------------------------------------------- */
51 struct capi_notifier
{
52 struct work_struct work
;
59 /* ------------------------------------------------------------- */
61 static struct capi_version driver_version
= {2, 0, 1, 1<<4};
62 static char driver_serial
[CAPI_SERIAL_LEN
] = "0004711";
63 static char capi_manufakturer
[64] = "AVM Berlin";
65 #define NCCI2CTRL(ncci) (((ncci) >> 24) & 0x7f)
67 LIST_HEAD(capi_drivers
);
68 DEFINE_RWLOCK(capi_drivers_list_lock
);
70 static DEFINE_RWLOCK(application_lock
);
71 static DEFINE_MUTEX(controller_mutex
);
73 struct capi20_appl
*capi_applications
[CAPI_MAXAPPL
];
74 struct capi_ctr
*capi_cards
[CAPI_MAXCONTR
];
78 /* -------- controller ref counting -------------------------------------- */
80 static inline struct capi_ctr
*
81 capi_ctr_get(struct capi_ctr
*card
)
83 if (!try_module_get(card
->owner
))
89 capi_ctr_put(struct capi_ctr
*card
)
91 module_put(card
->owner
);
94 /* ------------------------------------------------------------- */
96 static inline struct capi_ctr
*get_capi_ctr_by_nr(u16 contr
)
98 if (contr
- 1 >= CAPI_MAXCONTR
)
101 return capi_cards
[contr
- 1];
104 static inline struct capi20_appl
*get_capi_appl_by_nr(u16 applid
)
106 if (applid
- 1 >= CAPI_MAXAPPL
)
109 return capi_applications
[applid
- 1];
112 /* -------- util functions ------------------------------------ */
114 static inline int capi_cmd_valid(u8 cmd
)
119 case CAPI_CONNECT_ACTIVE
:
120 case CAPI_CONNECT_B3_ACTIVE
:
121 case CAPI_CONNECT_B3
:
122 case CAPI_CONNECT_B3_T90_ACTIVE
:
124 case CAPI_DISCONNECT_B3
:
125 case CAPI_DISCONNECT
:
129 case CAPI_MANUFACTURER
:
131 case CAPI_SELECT_B_PROTOCOL
:
137 static inline int capi_subcmd_valid(u8 subcmd
)
149 /* ------------------------------------------------------------ */
151 static void register_appl(struct capi_ctr
*card
, u16 applid
, capi_register_params
*rparam
)
153 card
= capi_ctr_get(card
);
156 card
->register_appl(card
, applid
, rparam
);
158 printk(KERN_WARNING
"%s: cannot get card resources\n", __func__
);
162 static void release_appl(struct capi_ctr
*card
, u16 applid
)
164 DBG("applid %#x", applid
);
166 card
->release_appl(card
, applid
);
170 /* -------- KCI_CONTRUP --------------------------------------- */
172 static void notify_up(u32 contr
)
174 struct capi_ctr
*card
= get_capi_ctr_by_nr(contr
);
175 struct capi20_appl
*ap
;
178 if (showcapimsgs
& 1) {
179 printk(KERN_DEBUG
"kcapi: notify up contr %d\n", contr
);
182 printk(KERN_WARNING
"%s: invalid contr %d\n", __func__
, contr
);
185 for (applid
= 1; applid
<= CAPI_MAXAPPL
; applid
++) {
186 ap
= get_capi_appl_by_nr(applid
);
187 if (!ap
|| ap
->release_in_progress
) continue;
188 register_appl(card
, applid
, &ap
->rparam
);
189 if (ap
->callback
&& !ap
->release_in_progress
)
190 ap
->callback(KCI_CONTRUP
, contr
, &card
->profile
);
194 /* -------- KCI_CONTRDOWN ------------------------------------- */
196 static void notify_down(u32 contr
)
198 struct capi20_appl
*ap
;
201 if (showcapimsgs
& 1) {
202 printk(KERN_DEBUG
"kcapi: notify down contr %d\n", contr
);
205 for (applid
= 1; applid
<= CAPI_MAXAPPL
; applid
++) {
206 ap
= get_capi_appl_by_nr(applid
);
207 if (ap
&& ap
->callback
&& !ap
->release_in_progress
)
208 ap
->callback(KCI_CONTRDOWN
, contr
, NULL
);
212 static void notify_handler(struct work_struct
*work
)
214 struct capi_notifier
*np
=
215 container_of(work
, struct capi_notifier
, work
);
219 notify_up(np
->controller
);
222 notify_down(np
->controller
);
230 * The notifier will result in adding/deleteing of devices. Devices can
231 * only removed in user process, not in bh.
233 static int notify_push(unsigned int cmd
, u32 controller
, u16 applid
, u32 ncci
)
235 struct capi_notifier
*np
= kmalloc(sizeof(*np
), GFP_ATOMIC
);
240 INIT_WORK(&np
->work
, notify_handler
);
242 np
->controller
= controller
;
246 schedule_work(&np
->work
);
251 /* -------- Receiver ------------------------------------------ */
253 static void recv_handler(struct work_struct
*work
)
256 struct capi20_appl
*ap
=
257 container_of(work
, struct capi20_appl
, recv_work
);
259 if ((!ap
) || (ap
->release_in_progress
))
262 mutex_lock(&ap
->recv_mtx
);
263 while ((skb
= skb_dequeue(&ap
->recv_queue
))) {
264 if (CAPIMSG_CMD(skb
->data
) == CAPI_DATA_B3_IND
)
269 ap
->recv_message(ap
, skb
);
271 mutex_unlock(&ap
->recv_mtx
);
275 * capi_ctr_handle_message() - handle incoming CAPI message
276 * @card: controller descriptor structure.
277 * @appl: application ID.
280 * Called by hardware driver to pass a CAPI message to the application.
283 void capi_ctr_handle_message(struct capi_ctr
* card
, u16 appl
, struct sk_buff
*skb
)
285 struct capi20_appl
*ap
;
291 if (card
->cardstate
!= CARD_RUNNING
) {
292 cdb
= capi_message2str(skb
->data
);
294 printk(KERN_INFO
"kcapi: controller [%03d] not active, got: %s",
295 card
->cnr
, cdb
->buf
);
298 printk(KERN_INFO
"kcapi: controller [%03d] not active, cannot trace\n",
303 cmd
= CAPIMSG_COMMAND(skb
->data
);
304 subcmd
= CAPIMSG_SUBCOMMAND(skb
->data
);
305 if (cmd
== CAPI_DATA_B3
&& subcmd
== CAPI_IND
) {
306 card
->nrecvdatapkt
++;
307 if (card
->traceflag
> 2) showctl
|= 2;
310 if (card
->traceflag
) showctl
|= 2;
312 showctl
|= (card
->traceflag
& 1);
315 printk(KERN_DEBUG
"kcapi: got [%03d] id#%d %s len=%u\n",
316 card
->cnr
, CAPIMSG_APPID(skb
->data
),
317 capi_cmd2str(cmd
, subcmd
),
318 CAPIMSG_LEN(skb
->data
));
320 cdb
= capi_message2str(skb
->data
);
322 printk(KERN_DEBUG
"kcapi: got [%03d] %s\n",
323 card
->cnr
, cdb
->buf
);
326 printk(KERN_DEBUG
"kcapi: got [%03d] id#%d %s len=%u, cannot trace\n",
327 card
->cnr
, CAPIMSG_APPID(skb
->data
),
328 capi_cmd2str(cmd
, subcmd
),
329 CAPIMSG_LEN(skb
->data
));
334 read_lock_irqsave(&application_lock
, flags
);
335 ap
= get_capi_appl_by_nr(CAPIMSG_APPID(skb
->data
));
336 if ((!ap
) || (ap
->release_in_progress
)) {
337 read_unlock_irqrestore(&application_lock
, flags
);
338 cdb
= capi_message2str(skb
->data
);
340 printk(KERN_ERR
"kcapi: handle_message: applid %d state released (%s)\n",
341 CAPIMSG_APPID(skb
->data
), cdb
->buf
);
344 printk(KERN_ERR
"kcapi: handle_message: applid %d state released (%s) cannot trace\n",
345 CAPIMSG_APPID(skb
->data
),
346 capi_cmd2str(cmd
, subcmd
));
349 skb_queue_tail(&ap
->recv_queue
, skb
);
350 schedule_work(&ap
->recv_work
);
351 read_unlock_irqrestore(&application_lock
, flags
);
359 EXPORT_SYMBOL(capi_ctr_handle_message
);
362 * capi_ctr_ready() - signal CAPI controller ready
363 * @card: controller descriptor structure.
365 * Called by hardware driver to signal that the controller is up and running.
368 void capi_ctr_ready(struct capi_ctr
* card
)
370 card
->cardstate
= CARD_RUNNING
;
372 printk(KERN_NOTICE
"kcapi: card [%03d] \"%s\" ready.\n",
373 card
->cnr
, card
->name
);
375 notify_push(KCI_CONTRUP
, card
->cnr
, 0, 0);
378 EXPORT_SYMBOL(capi_ctr_ready
);
381 * capi_ctr_down() - signal CAPI controller not ready
382 * @card: controller descriptor structure.
384 * Called by hardware driver to signal that the controller is down and
385 * unavailable for use.
388 void capi_ctr_down(struct capi_ctr
* card
)
394 if (card
->cardstate
== CARD_DETECTED
)
397 card
->cardstate
= CARD_DETECTED
;
399 memset(card
->manu
, 0, sizeof(card
->manu
));
400 memset(&card
->version
, 0, sizeof(card
->version
));
401 memset(&card
->profile
, 0, sizeof(card
->profile
));
402 memset(card
->serial
, 0, sizeof(card
->serial
));
404 for (appl
= 1; appl
<= CAPI_MAXAPPL
; appl
++) {
405 struct capi20_appl
*ap
= get_capi_appl_by_nr(appl
);
406 if (!ap
|| ap
->release_in_progress
)
412 printk(KERN_NOTICE
"kcapi: card [%03d] down.\n", card
->cnr
);
414 notify_push(KCI_CONTRDOWN
, card
->cnr
, 0, 0);
417 EXPORT_SYMBOL(capi_ctr_down
);
420 * capi_ctr_suspend_output() - suspend controller
421 * @card: controller descriptor structure.
423 * Called by hardware driver to stop data flow.
426 void capi_ctr_suspend_output(struct capi_ctr
*card
)
428 if (!card
->blocked
) {
429 printk(KERN_DEBUG
"kcapi: card [%03d] suspend\n", card
->cnr
);
434 EXPORT_SYMBOL(capi_ctr_suspend_output
);
437 * capi_ctr_resume_output() - resume controller
438 * @card: controller descriptor structure.
440 * Called by hardware driver to resume data flow.
443 void capi_ctr_resume_output(struct capi_ctr
*card
)
446 printk(KERN_DEBUG
"kcapi: card [%03d] resume\n", card
->cnr
);
451 EXPORT_SYMBOL(capi_ctr_resume_output
);
453 /* ------------------------------------------------------------- */
456 * attach_capi_ctr() - register CAPI controller
457 * @card: controller descriptor structure.
459 * Called by hardware driver to register a controller with the CAPI subsystem.
460 * Return value: 0 on success, error code < 0 on error
464 attach_capi_ctr(struct capi_ctr
*card
)
468 mutex_lock(&controller_mutex
);
470 for (i
= 0; i
< CAPI_MAXCONTR
; i
++) {
471 if (capi_cards
[i
] == NULL
)
474 if (i
== CAPI_MAXCONTR
) {
475 mutex_unlock(&controller_mutex
);
476 printk(KERN_ERR
"kcapi: out of controller slots\n");
479 capi_cards
[i
] = card
;
481 mutex_unlock(&controller_mutex
);
483 card
->nrecvctlpkt
= 0;
484 card
->nrecvdatapkt
= 0;
485 card
->nsentctlpkt
= 0;
486 card
->nsentdatapkt
= 0;
488 card
->cardstate
= CARD_DETECTED
;
490 card
->traceflag
= showcapimsgs
;
492 sprintf(card
->procfn
, "capi/controllers/%d", card
->cnr
);
493 card
->procent
= create_proc_entry(card
->procfn
, 0, NULL
);
495 card
->procent
->read_proc
=
496 (int (*)(char *,char **,off_t
,int,int *,void *))
498 card
->procent
->data
= card
;
502 printk(KERN_NOTICE
"kcapi: Controller [%03d]: %s attached\n",
503 card
->cnr
, card
->name
);
507 EXPORT_SYMBOL(attach_capi_ctr
);
510 * detach_capi_ctr() - unregister CAPI controller
511 * @card: controller descriptor structure.
513 * Called by hardware driver to remove the registration of a controller
514 * with the CAPI subsystem.
515 * Return value: 0 on success, error code < 0 on error
518 int detach_capi_ctr(struct capi_ctr
*card
)
520 if (card
->cardstate
!= CARD_DETECTED
)
526 remove_proc_entry(card
->procfn
, NULL
);
527 card
->procent
= NULL
;
529 capi_cards
[card
->cnr
- 1] = NULL
;
530 printk(KERN_NOTICE
"kcapi: Controller [%03d]: %s unregistered\n",
531 card
->cnr
, card
->name
);
536 EXPORT_SYMBOL(detach_capi_ctr
);
539 * register_capi_driver() - register CAPI driver
540 * @driver: driver descriptor structure.
542 * Called by hardware driver to register itself with the CAPI subsystem.
545 void register_capi_driver(struct capi_driver
*driver
)
549 write_lock_irqsave(&capi_drivers_list_lock
, flags
);
550 list_add_tail(&driver
->list
, &capi_drivers
);
551 write_unlock_irqrestore(&capi_drivers_list_lock
, flags
);
554 EXPORT_SYMBOL(register_capi_driver
);
557 * unregister_capi_driver() - unregister CAPI driver
558 * @driver: driver descriptor structure.
560 * Called by hardware driver to unregister itself from the CAPI subsystem.
563 void unregister_capi_driver(struct capi_driver
*driver
)
567 write_lock_irqsave(&capi_drivers_list_lock
, flags
);
568 list_del(&driver
->list
);
569 write_unlock_irqrestore(&capi_drivers_list_lock
, flags
);
572 EXPORT_SYMBOL(unregister_capi_driver
);
574 /* ------------------------------------------------------------- */
575 /* -------- CAPI2.0 Interface ---------------------------------- */
576 /* ------------------------------------------------------------- */
579 * capi20_isinstalled() - CAPI 2.0 operation CAPI_INSTALLED
581 * Return value: CAPI result code (CAPI_NOERROR if at least one ISDN controller
582 * is ready for use, CAPI_REGNOTINSTALLED otherwise)
585 u16
capi20_isinstalled(void)
588 for (i
= 0; i
< CAPI_MAXCONTR
; i
++) {
589 if (capi_cards
[i
] && capi_cards
[i
]->cardstate
== CARD_RUNNING
)
592 return CAPI_REGNOTINSTALLED
;
595 EXPORT_SYMBOL(capi20_isinstalled
);
598 * capi20_register() - CAPI 2.0 operation CAPI_REGISTER
599 * @ap: CAPI application descriptor structure.
601 * Register an application's presence with CAPI.
602 * A unique application ID is assigned and stored in @ap->applid.
603 * After this function returns successfully, the message receive
604 * callback function @ap->recv_message() may be called at any time
605 * until capi20_release() has been called for the same @ap.
606 * Return value: CAPI result code
609 u16
capi20_register(struct capi20_appl
*ap
)
617 if (ap
->rparam
.datablklen
< 128)
618 return CAPI_LOGBLKSIZETOSMALL
;
620 write_lock_irqsave(&application_lock
, flags
);
622 for (applid
= 1; applid
<= CAPI_MAXAPPL
; applid
++) {
623 if (capi_applications
[applid
- 1] == NULL
)
626 if (applid
> CAPI_MAXAPPL
) {
627 write_unlock_irqrestore(&application_lock
, flags
);
628 return CAPI_TOOMANYAPPLS
;
632 capi_applications
[applid
- 1] = ap
;
635 ap
->nrecvdatapkt
= 0;
637 ap
->nsentdatapkt
= 0;
639 mutex_init(&ap
->recv_mtx
);
640 skb_queue_head_init(&ap
->recv_queue
);
641 INIT_WORK(&ap
->recv_work
, recv_handler
);
642 ap
->release_in_progress
= 0;
644 write_unlock_irqrestore(&application_lock
, flags
);
646 mutex_lock(&controller_mutex
);
647 for (i
= 0; i
< CAPI_MAXCONTR
; i
++) {
648 if (!capi_cards
[i
] || capi_cards
[i
]->cardstate
!= CARD_RUNNING
)
650 register_appl(capi_cards
[i
], applid
, &ap
->rparam
);
652 mutex_unlock(&controller_mutex
);
654 if (showcapimsgs
& 1) {
655 printk(KERN_DEBUG
"kcapi: appl %d up\n", applid
);
661 EXPORT_SYMBOL(capi20_register
);
664 * capi20_release() - CAPI 2.0 operation CAPI_RELEASE
665 * @ap: CAPI application descriptor structure.
667 * Terminate an application's registration with CAPI.
668 * After this function returns successfully, the message receive
669 * callback function @ap->recv_message() will no longer be called.
670 * Return value: CAPI result code
673 u16
capi20_release(struct capi20_appl
*ap
)
678 DBG("applid %#x", ap
->applid
);
680 write_lock_irqsave(&application_lock
, flags
);
681 ap
->release_in_progress
= 1;
682 capi_applications
[ap
->applid
- 1] = NULL
;
683 write_unlock_irqrestore(&application_lock
, flags
);
685 mutex_lock(&controller_mutex
);
686 for (i
= 0; i
< CAPI_MAXCONTR
; i
++) {
687 if (!capi_cards
[i
] || capi_cards
[i
]->cardstate
!= CARD_RUNNING
)
689 release_appl(capi_cards
[i
], ap
->applid
);
691 mutex_unlock(&controller_mutex
);
693 flush_scheduled_work();
694 skb_queue_purge(&ap
->recv_queue
);
696 if (showcapimsgs
& 1) {
697 printk(KERN_DEBUG
"kcapi: appl %d down\n", ap
->applid
);
703 EXPORT_SYMBOL(capi20_release
);
706 * capi20_put_message() - CAPI 2.0 operation CAPI_PUT_MESSAGE
707 * @ap: CAPI application descriptor structure.
708 * @skb: CAPI message.
710 * Transfer a single message to CAPI.
711 * Return value: CAPI result code
714 u16
capi20_put_message(struct capi20_appl
*ap
, struct sk_buff
*skb
)
716 struct capi_ctr
*card
;
720 DBG("applid %#x", ap
->applid
);
723 return CAPI_REGNOTINSTALLED
;
724 if ((ap
->applid
== 0) || ap
->release_in_progress
)
725 return CAPI_ILLAPPNR
;
727 || !capi_cmd_valid(CAPIMSG_COMMAND(skb
->data
))
728 || !capi_subcmd_valid(CAPIMSG_SUBCOMMAND(skb
->data
)))
729 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL
;
730 card
= get_capi_ctr_by_nr(CAPIMSG_CONTROLLER(skb
->data
));
731 if (!card
|| card
->cardstate
!= CARD_RUNNING
) {
732 card
= get_capi_ctr_by_nr(1); // XXX why?
733 if (!card
|| card
->cardstate
!= CARD_RUNNING
)
734 return CAPI_REGNOTINSTALLED
;
737 return CAPI_SENDQUEUEFULL
;
739 cmd
= CAPIMSG_COMMAND(skb
->data
);
740 subcmd
= CAPIMSG_SUBCOMMAND(skb
->data
);
742 if (cmd
== CAPI_DATA_B3
&& subcmd
== CAPI_REQ
) {
743 card
->nsentdatapkt
++;
745 if (card
->traceflag
> 2) showctl
|= 2;
749 if (card
->traceflag
) showctl
|= 2;
751 showctl
|= (card
->traceflag
& 1);
754 printk(KERN_DEBUG
"kcapi: put [%03d] id#%d %s len=%u\n",
755 CAPIMSG_CONTROLLER(skb
->data
),
756 CAPIMSG_APPID(skb
->data
),
757 capi_cmd2str(cmd
, subcmd
),
758 CAPIMSG_LEN(skb
->data
));
760 _cdebbuf
*cdb
= capi_message2str(skb
->data
);
762 printk(KERN_DEBUG
"kcapi: put [%03d] %s\n",
763 CAPIMSG_CONTROLLER(skb
->data
),
767 printk(KERN_DEBUG
"kcapi: put [%03d] id#%d %s len=%u cannot trace\n",
768 CAPIMSG_CONTROLLER(skb
->data
),
769 CAPIMSG_APPID(skb
->data
),
770 capi_cmd2str(cmd
, subcmd
),
771 CAPIMSG_LEN(skb
->data
));
774 return card
->send_message(card
, skb
);
777 EXPORT_SYMBOL(capi20_put_message
);
780 * capi20_get_manufacturer() - CAPI 2.0 operation CAPI_GET_MANUFACTURER
781 * @contr: controller number.
782 * @buf: result buffer (64 bytes).
784 * Retrieve information about the manufacturer of the specified ISDN controller
785 * or (for @contr == 0) the driver itself.
786 * Return value: CAPI result code
789 u16
capi20_get_manufacturer(u32 contr
, u8
*buf
)
791 struct capi_ctr
*card
;
794 strlcpy(buf
, capi_manufakturer
, CAPI_MANUFACTURER_LEN
);
797 card
= get_capi_ctr_by_nr(contr
);
798 if (!card
|| card
->cardstate
!= CARD_RUNNING
)
799 return CAPI_REGNOTINSTALLED
;
800 strlcpy(buf
, card
->manu
, CAPI_MANUFACTURER_LEN
);
804 EXPORT_SYMBOL(capi20_get_manufacturer
);
807 * capi20_get_version() - CAPI 2.0 operation CAPI_GET_VERSION
808 * @contr: controller number.
809 * @verp: result structure.
811 * Retrieve version information for the specified ISDN controller
812 * or (for @contr == 0) the driver itself.
813 * Return value: CAPI result code
816 u16
capi20_get_version(u32 contr
, struct capi_version
*verp
)
818 struct capi_ctr
*card
;
821 *verp
= driver_version
;
824 card
= get_capi_ctr_by_nr(contr
);
825 if (!card
|| card
->cardstate
!= CARD_RUNNING
)
826 return CAPI_REGNOTINSTALLED
;
828 memcpy((void *) verp
, &card
->version
, sizeof(capi_version
));
832 EXPORT_SYMBOL(capi20_get_version
);
835 * capi20_get_serial() - CAPI 2.0 operation CAPI_GET_SERIAL_NUMBER
836 * @contr: controller number.
837 * @serial: result buffer (8 bytes).
839 * Retrieve the serial number of the specified ISDN controller
840 * or (for @contr == 0) the driver itself.
841 * Return value: CAPI result code
844 u16
capi20_get_serial(u32 contr
, u8
*serial
)
846 struct capi_ctr
*card
;
849 strlcpy(serial
, driver_serial
, CAPI_SERIAL_LEN
);
852 card
= get_capi_ctr_by_nr(contr
);
853 if (!card
|| card
->cardstate
!= CARD_RUNNING
)
854 return CAPI_REGNOTINSTALLED
;
856 strlcpy((void *) serial
, card
->serial
, CAPI_SERIAL_LEN
);
860 EXPORT_SYMBOL(capi20_get_serial
);
863 * capi20_get_profile() - CAPI 2.0 operation CAPI_GET_PROFILE
864 * @contr: controller number.
865 * @profp: result structure.
867 * Retrieve capability information for the specified ISDN controller
868 * or (for @contr == 0) the number of installed controllers.
869 * Return value: CAPI result code
872 u16
capi20_get_profile(u32 contr
, struct capi_profile
*profp
)
874 struct capi_ctr
*card
;
877 profp
->ncontroller
= ncards
;
880 card
= get_capi_ctr_by_nr(contr
);
881 if (!card
|| card
->cardstate
!= CARD_RUNNING
)
882 return CAPI_REGNOTINSTALLED
;
884 memcpy((void *) profp
, &card
->profile
,
885 sizeof(struct capi_profile
));
889 EXPORT_SYMBOL(capi20_get_profile
);
892 static int old_capi_manufacturer(unsigned int cmd
, void __user
*data
)
894 avmb1_loadandconfigdef ldef
;
895 avmb1_extcarddef cdef
;
897 capicardparams cparams
;
898 struct capi_ctr
*card
;
899 struct capi_driver
*driver
= NULL
;
907 case AVMB1_ADDCARD_WITH_TYPE
:
908 if (cmd
== AVMB1_ADDCARD
) {
909 if ((retval
= copy_from_user(&cdef
, data
,
910 sizeof(avmb1_carddef
))))
912 cdef
.cardtype
= AVM_CARDTYPE_B1
;
914 if ((retval
= copy_from_user(&cdef
, data
,
915 sizeof(avmb1_extcarddef
))))
918 cparams
.port
= cdef
.port
;
919 cparams
.irq
= cdef
.irq
;
920 cparams
.cardnr
= cdef
.cardnr
;
922 read_lock_irqsave(&capi_drivers_list_lock
, flags
);
923 switch (cdef
.cardtype
) {
924 case AVM_CARDTYPE_B1
:
925 list_for_each(l
, &capi_drivers
) {
926 driver
= list_entry(l
, struct capi_driver
, list
);
927 if (strcmp(driver
->name
, "b1isa") == 0)
931 case AVM_CARDTYPE_T1
:
932 list_for_each(l
, &capi_drivers
) {
933 driver
= list_entry(l
, struct capi_driver
, list
);
934 if (strcmp(driver
->name
, "t1isa") == 0)
943 read_unlock_irqrestore(&capi_drivers_list_lock
, flags
);
944 printk(KERN_ERR
"kcapi: driver not loaded.\n");
947 if (!driver
->add_card
) {
948 read_unlock_irqrestore(&capi_drivers_list_lock
, flags
);
949 printk(KERN_ERR
"kcapi: driver has no add card function.\n");
953 retval
= driver
->add_card(driver
, &cparams
);
954 read_unlock_irqrestore(&capi_drivers_list_lock
, flags
);
958 case AVMB1_LOAD_AND_CONFIG
:
960 if (cmd
== AVMB1_LOAD
) {
961 if (copy_from_user(&ldef
, data
,
962 sizeof(avmb1_loaddef
)))
964 ldef
.t4config
.len
= 0;
965 ldef
.t4config
.data
= NULL
;
967 if (copy_from_user(&ldef
, data
,
968 sizeof(avmb1_loadandconfigdef
)))
971 card
= get_capi_ctr_by_nr(ldef
.contr
);
974 card
= capi_ctr_get(card
);
977 if (card
->load_firmware
== NULL
) {
978 printk(KERN_DEBUG
"kcapi: load: no load function\n");
983 if (ldef
.t4file
.len
<= 0) {
984 printk(KERN_DEBUG
"kcapi: load: invalid parameter: length of t4file is %d ?\n", ldef
.t4file
.len
);
988 if (ldef
.t4file
.data
== NULL
) {
989 printk(KERN_DEBUG
"kcapi: load: invalid parameter: dataptr is 0\n");
994 ldata
.firmware
.user
= 1;
995 ldata
.firmware
.data
= ldef
.t4file
.data
;
996 ldata
.firmware
.len
= ldef
.t4file
.len
;
997 ldata
.configuration
.user
= 1;
998 ldata
.configuration
.data
= ldef
.t4config
.data
;
999 ldata
.configuration
.len
= ldef
.t4config
.len
;
1001 if (card
->cardstate
!= CARD_DETECTED
) {
1002 printk(KERN_INFO
"kcapi: load: contr=%d not in detect state\n", ldef
.contr
);
1006 card
->cardstate
= CARD_LOADING
;
1008 retval
= card
->load_firmware(card
, &ldata
);
1011 card
->cardstate
= CARD_DETECTED
;
1016 while (card
->cardstate
!= CARD_RUNNING
) {
1018 msleep_interruptible(100); /* 0.1 sec */
1020 if (signal_pending(current
)) {
1028 case AVMB1_RESETCARD
:
1029 if (copy_from_user(&rdef
, data
, sizeof(avmb1_resetdef
)))
1031 card
= get_capi_ctr_by_nr(rdef
.contr
);
1035 if (card
->cardstate
== CARD_DETECTED
)
1038 card
->reset_ctr(card
);
1040 while (card
->cardstate
> CARD_DETECTED
) {
1042 msleep_interruptible(100); /* 0.1 sec */
1044 if (signal_pending(current
))
1055 * capi20_manufacturer() - CAPI 2.0 operation CAPI_MANUFACTURER
1059 * Perform manufacturer specific command.
1060 * Return value: CAPI result code
1063 int capi20_manufacturer(unsigned int cmd
, void __user
*data
)
1065 struct capi_ctr
*card
;
1070 case AVMB1_LOAD_AND_CONFIG
:
1071 case AVMB1_RESETCARD
:
1072 case AVMB1_GET_CARDINFO
:
1073 case AVMB1_REMOVECARD
:
1074 return old_capi_manufacturer(cmd
, data
);
1076 case KCAPI_CMD_TRACE
:
1080 if (copy_from_user(&fdef
, data
, sizeof(kcapi_flagdef
)))
1083 card
= get_capi_ctr_by_nr(fdef
.contr
);
1087 card
->traceflag
= fdef
.flag
;
1088 printk(KERN_INFO
"kcapi: contr [%03d] set trace=%d\n",
1089 card
->cnr
, card
->traceflag
);
1092 case KCAPI_CMD_ADDCARD
:
1094 struct list_head
*l
;
1095 struct capi_driver
*driver
= NULL
;
1096 capicardparams cparams
;
1100 if ((retval
= copy_from_user(&cdef
, data
, sizeof(cdef
))))
1103 cparams
.port
= cdef
.port
;
1104 cparams
.irq
= cdef
.irq
;
1105 cparams
.membase
= cdef
.membase
;
1106 cparams
.cardnr
= cdef
.cardnr
;
1107 cparams
.cardtype
= 0;
1108 cdef
.driver
[sizeof(cdef
.driver
)-1] = 0;
1110 list_for_each(l
, &capi_drivers
) {
1111 driver
= list_entry(l
, struct capi_driver
, list
);
1112 if (strcmp(driver
->name
, cdef
.driver
) == 0)
1115 if (driver
== NULL
) {
1116 printk(KERN_ERR
"kcapi: driver \"%s\" not loaded.\n",
1121 if (!driver
->add_card
) {
1122 printk(KERN_ERR
"kcapi: driver \"%s\" has no add card function.\n", cdef
.driver
);
1126 return driver
->add_card(driver
, &cparams
);
1130 printk(KERN_ERR
"kcapi: manufacturer command %d unknown.\n",
1138 EXPORT_SYMBOL(capi20_manufacturer
);
1140 /* temporary hack */
1143 * capi20_set_callback() - set CAPI application notification callback function
1144 * @ap: CAPI application descriptor structure.
1145 * @callback: callback function (NULL to remove).
1147 * If not NULL, the callback function will be called to notify the
1148 * application of the addition or removal of a controller.
1149 * The first argument (cmd) will tell whether the controller was added
1150 * (KCI_CONTRUP) or removed (KCI_CONTRDOWN).
1151 * The second argument (contr) will be the controller number.
1152 * For cmd==KCI_CONTRUP the third argument (data) will be a pointer to the
1153 * new controller's capability profile structure.
1156 void capi20_set_callback(struct capi20_appl
*ap
,
1157 void (*callback
) (unsigned int cmd
, __u32 contr
, void *data
))
1159 ap
->callback
= callback
;
1162 EXPORT_SYMBOL(capi20_set_callback
);
1164 /* ------------------------------------------------------------- */
1165 /* -------- Init & Cleanup ------------------------------------- */
1166 /* ------------------------------------------------------------- */
1169 * init / exit functions
1172 static int __init
kcapi_init(void)
1178 ret
= cdebug_init();
1183 if ((p
= strchr(revision
, ':')) != NULL
&& p
[1]) {
1184 strlcpy(rev
, p
+ 2, sizeof(rev
));
1185 if ((p
= strchr(rev
, '$')) != NULL
&& p
> rev
)
1190 printk(KERN_NOTICE
"CAPI Subsystem Rev %s\n", rev
);
1195 static void __exit
kcapi_exit(void)
1199 /* make sure all notifiers are finished */
1200 flush_scheduled_work();
1204 module_init(kcapi_init
);
1205 module_exit(kcapi_exit
);