22 #define DBG_MINIMUM (DL_LOG + DL_FTL + DL_ERR)
23 #define DBG_DEFAULT (DBG_MINIMUM + DL_XLOG + DL_REG)
45 static dword notify_handle;
46 static void DIRequest(
ENTITY *
e);
55 static char *diva_procinfo(
struct capi_ctr *);
65 static void no_printf(
unsigned char *, ...);
67 static void xlog(
char *
x, ...)
69 #ifndef DIVA_NO_DEBUGLIB
96 static void stop_dbg(
void)
99 memset(&MAdapter, 0,
sizeof(MAdapter));
106 static void no_printf(
unsigned char *x, ...)
116 byte MappedController = 0;
117 byte ctrl = Controller & 0x7f;
120 if (ctrl == ControllerMap[i]) {
121 MappedController = (
byte) i;
125 if (i > max_adapter) {
126 ControllerMap[0] =
ctrl;
127 MappedController = 0;
129 return (MappedController | (Controller & 0x80));
138 byte ctrl = MappedController & 0x7f;
141 Controller = ControllerMap[
ctrl];
146 return (Controller | (MappedController & 0x80));
152 static int find_free_id(
void)
176 if (ControllerMap[card->
Id] == controller) {
191 DBG_PRV1((
"%d:xbuf_used(%d)", appl->
Id, ref + 1))
192 return (
void *)(
long)ref;
240 DBG_PRV1((
"sendf(a=%d,cmd=%x,format=%s)",
241 appl->
Id, command, (
byte *) format))
243 PUT_WORD(&msg.
header.appl_id, appl->
Id);
244 PUT_WORD(&msg.
header.command, command);
245 if ((
byte) (command >> 8) == 0x82)
247 PUT_WORD(&msg.
header.number, Number);
249 PUT_DWORD(&msg.
header.controller, Id);
250 write = (
byte *)&msg;
254 for (i = 0; format[
i]; i++) {
258 *(
byte *) write = (
byte) (tmp & 0xff);
264 PUT_WORD(write, (tmp & 0xffff));
270 PUT_DWORD(write, tmp);
277 length +=
string[0] + 1;
278 for (j = 0; j <=
string[0]; j++)
279 *write++ =
string[j];
285 PUT_WORD(&msg.
header.length, length);
293 (
void **) &write))) {
294 DBG_ERR((
"sendf: alloc_message_buffer failed, incoming msg dropped."))
304 memcpy(write + length, (
void *)(
long)data, dlength);
307 #ifndef DIVA_NO_DEBUGLIB
311 xlog(
"\x00\x02", &msg, 0x81, length);
315 xlog(
"\x00\x02", &msg, 0x81, length);
319 xlog(
"\x00\x02", &msg, 0x81, length);
320 for (i = 0; i < dlength; i += 256) {
322 ((dlength - i) < 256) ? (dlength - i) : 256))
333 if (!(card = find_card_by_ctrl(write[8] & 0x7f))) {
334 DBG_ERR((
"sendf - controller %d not found, incoming msg dropped",
346 static void clean_adapter(
int id,
struct list_head *free_mem_q)
363 for (i = 0; i <
k; i++) {
383 while ((max_adapter != 0) && !adapter[max_adapter - 1].
request)
404 diva_os_enter_spin_lock(&api_lock, &old_irql,
"remove card");
413 diva_os_leave_spin_lock(&api_lock, &old_irql,
"remove card");
426 diva_os_enter_spin_lock(&api_lock, &old_irql,
"remove card");
428 clean_adapter(card->
Id - 1, &free_mem_q);
429 DBG_TRC((
"DelAdapterMap (%d) -> (%d)",
430 ControllerMap[card->
Id], card->
Id))
431 ControllerMap[card->Id] = 0;
432 DBG_TRC(("adapter remove, max_adapter=%d",
434 diva_os_leave_spin_lock(&api_lock, &old_irql, "remove card");
437 diva_os_free(0, card);
443 diva_os_free(0, link);
450 static void divacapi_remove_cards(
void)
458 diva_os_enter_spin_lock(&api_lock, &old_irql,
"remove cards");
461 diva_os_leave_spin_lock(&api_lock, &old_irql,
"remove cards");
463 divacapi_remove_card(&d);
466 diva_os_leave_spin_lock(&api_lock, &old_irql,
"remove cards");
472 static void sync_callback(
ENTITY *
e)
478 diva_os_enter_spin_lock(&api_lock, &old_irql, "sync_callback");
480 diva_os_leave_spin_lock(&api_lock, &old_irql, "sync_callback");
500 DBG_ERR((
"diva_add_card: failed to allocate card struct."))
505 sync_req.GetName.
Req = 0;
509 ctrl = &card->capi_ctrl;
510 strcpy(ctrl->name, card->name);
519 DBG_ERR((
"diva_add_card: failed to attach controller."))
520 diva_os_free(0, card);
524 diva_os_enter_spin_lock(&api_lock, &old_irql, "find
id");
525 card->Id = find_free_id();
526 diva_os_leave_spin_lock(&api_lock, &old_irql, "find
id");
529 ctrl->
version.majorversion = 2;
530 ctrl->
version.minorversion = 0;
533 sync_req.GetSerial.Req = 0;
535 sync_req.GetSerial.serial = 0;
537 if ((i = ((sync_req.GetSerial.serial & 0xff000000) >> 24))) {
539 sync_req.GetSerial.serial & 0x00ffffff, i + 1);
541 sprintf(serial,
"%ld", sync_req.GetSerial.serial);
544 strlcpy(ctrl->serial, serial,
sizeof(ctrl->serial));
546 a = &adapter[card->Id - 1];
549 ControllerMap[card->Id] = (
byte) (ctrl->cnr);
551 DBG_TRC((
"AddAdapterMap (%d) -> (%d)", ctrl->cnr, card->Id))
553 sync_req.xdi_capi_prms.Req = 0;
555 sync_req.xdi_capi_prms.
info.structure_length =
558 a->flag_dynamic_l1_down =
559 sync_req.xdi_capi_prms.
info.flag_dynamic_l1_down;
560 a->group_optimization_enabled =
561 sync_req.xdi_capi_prms.
info.group_optimization_enabled;
563 a->max_plci = card->d.
channels + 30;
564 a->max_listen = (card->d.channels > 2) ? 8 : 2;
568 DBG_ERR((
"diva_add_card: failed alloc plci struct."))
574 for (k = 0; k < a->max_plci; k++) {
575 a->Id = (
byte) card->Id;
576 a->plci[k].Sig.callback = sync_callback;
577 a->plci[k].Sig.XNum = 1;
578 a->plci[k].Sig.X = a->plci[k].XData;
579 a->plci[k].Sig.user[0] = (
word) (card->Id - 1);
580 a->plci[
k].Sig.user[1] = (
word) k;
581 a->plci[
k].NL.callback = sync_callback;
582 a->plci[
k].NL.XNum = 1;
583 a->plci[
k].NL.X = a->plci[
k].XData;
584 a->plci[
k].NL.user[0] = (
word) ((card->Id - 1) | 0x8000);
585 a->plci[
k].NL.user[1] = (
word) k;
586 a->plci[
k].adapter =
a;
589 a->profile.Number = card->Id;
590 a->profile.Channels = card->d.channels;
591 if (card->d.features &
DI_FAX3) {
592 a->profile.Global_Options = 0x71;
594 a->profile.Global_Options |= 0x6;
596 a->profile.Global_Options |= 0x8;
598 a->profile.Global_Options |= 0x80;
599 #if IMPLEMENT_ECHO_CANCELLER
600 a->profile.Global_Options |= 0x100;
602 a->profile.B1_Protocols = 0xdf;
603 a->profile.B2_Protocols = 0x1fdb;
604 a->profile.B3_Protocols = 0xb7;
607 a->profile.Global_Options = 0x71;
609 a->profile.Global_Options |= 0x2;
610 a->profile.B1_Protocols = 0x43;
611 a->profile.B2_Protocols = 0x1f0f;
612 a->profile.B3_Protocols = 0x07;
613 a->manufacturer_features = 0;
616 a->li_pri = (a->profile.Channels > 2);
619 for (i = 0; &adapter[
i] !=
a; i++) {
624 new_li_config_table =
625 (
LI_CONFIG *) diva_os_malloc(0, ((k *
sizeof(
LI_CONFIG) + 3) & ~3) + (2 *
k) * ((k + 3) & ~3));
626 if (new_li_config_table ==
NULL) {
627 DBG_ERR((
"diva_add_card: failed alloc li_config table."))
633 diva_os_enter_spin_lock(&api_lock, &old_irql, "
add card");
636 for (i = 0; i < k; i++) {
637 if ((i >= a->li_base) && (i < a->li_base + a->li_channels))
642 ((
byte *) new_li_config_table) + (((k *
sizeof(
LI_CONFIG) + 3) & ~3) + (2 * i) * ((k + 3) & ~3));
644 ((
byte *) new_li_config_table) + (((k *
sizeof(
LI_CONFIG) + 3) & ~3) + (2 * i + 1) * ((k + 3) & ~3));
645 if ((i >= a->li_base) && (i < a->li_base + a->li_channels)) {
647 memset(&new_li_config_table[i].flag_table[0], 0, k);
648 memset(&new_li_config_table[i].coef_table[0], 0, k);
650 if (a->li_base != 0) {
651 memcpy(&new_li_config_table[i].flag_table[0],
654 memcpy(&new_li_config_table[i].coef_table[0],
658 memset(&new_li_config_table[i].flag_table[a->li_base], 0, a->li_channels);
659 memset(&new_li_config_table[i].coef_table[a->li_base], 0, a->li_channels);
660 if (a->li_base + a->li_channels < k) {
661 memcpy(&new_li_config_table[i].flag_table[a->li_base +
664 k - (a->li_base + a->li_channels));
665 memcpy(&new_li_config_table[i].coef_table[a->li_base +
668 k - (a->li_base + a->li_channels));
678 for (i = card->Id; i < max_adapter; i++) {
680 adapter[
i].
li_base += a->li_channels;
683 if (a == &adapter[max_adapter])
686 list_add(&(card->list), &cards);
689 diva_os_leave_spin_lock(&api_lock, &old_irql,
"add card");
692 diva_os_free(0, mem_to_free);
697 if (a->automatic_law > 3)
703 PUT_WORD(&ctrl->profile.nbchannel, card->d.channels);
704 ctrl->profile.goptions = a->profile.Global_Options;
705 ctrl->profile.support1 = a->profile.B1_Protocols;
706 ctrl->profile.support2 = a->profile.B2_Protocols;
707 ctrl->profile.support3 = a->profile.B3_Protocols;
709 ctrl->profile.manu[0] = a->man_profile.private_options;
710 ctrl->profile.manu[1] = a->man_profile.rtp_primary_payloads;
711 ctrl->profile.manu[2] = a->man_profile.rtp_additional_payloads;
712 ctrl->profile.manu[3] = 0;
713 ctrl->profile.manu[4] = 0;
717 DBG_TRC((
"adapter added, max_adapter=%d", max_adapter));
724 static void diva_register_appl(
struct capi_ctr *ctrl,
__u16 appl,
731 void *DataNCCI, *DataFlags, *ReceiveBuffer, *xbuffer_used;
732 void **xbuffer_ptr, **xbuffer_internal;
734 unsigned int mem_len;
739 DBG_ERR((
"CAPI_REGISTER - in irq context !"))
743 DBG_TRC(("application register Id=%d", appl))
746 DBG_ERR((
"CAPI_REGISTER - appl.Id exceeds MAX_APPL"))
751 nconn = ctrl->
profile.nbchannel * -nconn;
754 nconn = ctrl->
profile.nbchannel;
757 DBG_LOG((" MaxLogicalConnections = %d(%d)", nconn, rp->level3cnt))
758 DBG_LOG((" MaxBDataBuffers = %d", rp->datablkcnt))
759 DBG_LOG((" MaxBDataLength = %d", rp->datablklen))
763 rp->datablklen < 80 ||
764 rp->datablklen > 2150 || rp->datablkcnt > 255) {
765 DBG_ERR((
"CAPI_REGISTER - invalid parameters"))
769 if (application[appl - 1].Id == appl) {
770 DBG_LOG((
"CAPI_REGISTER - appl already registered"))
776 bnum = nconn * rp->datablkcnt;
780 mem_len += bnum *
sizeof(word);
781 mem_len += bnum * rp->datablklen;
783 mem_len += xnum *
sizeof(
void *);
784 mem_len += xnum *
sizeof(
void *);
785 mem_len += xnum * rp->datablklen;
788 if (!(p = diva_os_malloc(0, mem_len))) {
789 DBG_ERR((
"CAPI_REGISTER - memory allocation failed"))
794 DataNCCI = (
void *)p;
796 DataFlags = (
void *)p;
798 ReceiveBuffer = (
void *)p;
799 p += bnum * rp->datablklen;
800 xbuffer_used = (
void *)p;
802 xbuffer_ptr = (
void **)p;
803 p += xnum *
sizeof(
void *);
804 xbuffer_internal = (
void **)p;
805 p += xnum *
sizeof(
void *);
806 for (i = 0; i < xnum; i++) {
807 xbuffer_ptr[
i] = (
void *)p;
812 diva_os_enter_spin_lock(&api_lock, &old_irql,
"register_appl");
814 this = &application[appl - 1];
823 this->queue_size = 1000;
825 this->MaxNCCI = (
byte) nconn;
827 this->MaxBuffer = bnum;
830 this->DataNCCI = DataNCCI;
831 this->DataFlags = DataFlags;
832 this->ReceiveBuffer = ReceiveBuffer;
833 this->xbuffer_used = xbuffer_used;
834 this->xbuffer_ptr = xbuffer_ptr;
835 this->xbuffer_internal = xbuffer_internal;
836 for (i = 0; i < xnum; i++) {
837 this->xbuffer_ptr[
i] = xbuffer_ptr[
i];
841 diva_os_leave_spin_lock(&api_lock, &old_irql,
"register_appl");
848 static void diva_release_appl(
struct capi_ctr *ctrl,
__u16 appl)
851 APPL *
this = &application[appl - 1];
852 void *mem_to_free =
NULL;
854 DBG_TRC((
"application %d(%d) cleanup", this->Id, appl))
857 DBG_ERR((
"CAPI_RELEASE - in irq context !"))
861 diva_os_enter_spin_lock(&api_lock, &old_irql, "
release_appl");
864 mem_to_free = this->DataNCCI;
865 this->DataNCCI =
NULL;
868 diva_os_leave_spin_lock(&api_lock, &old_irql,
"release_appl");
871 diva_os_free(0, mem_to_free);
878 static u16 diva_send_message(
struct capi_ctr *ctrl,
885 APPL *
this = &application[GET_WORD(&msg->
header.appl_id) - 1];
888 word clength = GET_WORD(&msg->
header.length);
893 DBG_ERR((
"CAPI_SEND_MSG - in irq context !"))
898 if (card->remove_in_progress) {
899 DBG_ERR((
"CAPI_SEND_MSG - remove in progress!"))
900 return CAPI_REGOSRESOURCEERR;
903 diva_os_enter_spin_lock(&api_lock, &old_irql, "
send message");
906 diva_os_leave_spin_lock(&api_lock, &old_irql,
"send message");
911 msg->
header.controller = ControllerMap[card->
Id]
912 | (msg->
header.controller & 0x80);
916 xlog(
"\x00\x02", msg, 0x80, clength);
920 #ifndef DIVA_NO_DEBUGLIB
922 xlog(
"\x00\x02", msg, 0x80, clength);
927 #ifndef DIVA_NO_DEBUGLIB
929 xlog(
"\x00\x02", msg, 0x80, clength);
938 (length - clength)) {
939 DBG_ERR((
"Write - invalid message size"))
944 for (i = 0; i < (MAX_DATA_B3 * this->MaxNCCI)
945 && this->xbuffer_used[i]; i++);
946 if (i == (MAX_DATA_B3 * this->MaxNCCI)) {
947 DBG_ERR((
"Write - too many data pending"))
953 this->xbuffer_internal[i] =
NULL;
954 memcpy(this->xbuffer_ptr[i], &((
__u8 *) msg)[clength],
955 GET_WORD(&msg->
info.data_b3_req.Data_Length));
957 #ifndef DIVA_NO_DEBUGLIB
964 DBG_BLK((((
char *) this->xbuffer_ptr[i]) + j,
977 mapped_msg->
header.length = clength;
979 mapped_msg->
header.number = GET_WORD(&msg->
header.number);
981 ret =
api_put(
this, mapped_msg);
986 DBG_ERR((
"Write - bad message"))
987 retval = CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
991 retval = CAPI_SENDQUEUEFULL;
1000 diva_os_leave_spin_lock(&api_lock, &old_irql, "
send message");
1010 static
void DIRequest(
ENTITY *e)
1012 DIVA_CAPI_ADAPTER *a = &(adapter[(
byte) e->user[0]]);
1013 diva_card *os_card = (diva_card *) a->
os_card;
1025 static void didd_callback(
void *
context, DESCRIPTOR *adapter,
int removal)
1028 DBG_ERR((
"Notification about IDI_DADAPTER change ! Oops."));
1034 memcpy(&MAdapter, adapter,
sizeof(MAdapter));
1038 }
else if ((adapter->
type > 0) && (adapter->
type < 16)) {
1040 divacapi_remove_card(adapter);
1042 diva_add_card(adapter);
1051 static int divacapi_connect_didd(
void)
1062 memcpy(&MAdapter, &DIDD_Table[x],
sizeof(DAdapter));
1071 memcpy(&DAdapter, &DIDD_Table[x],
sizeof(DAdapter));
1075 req.
didd_notify.info.callback = (
void *)didd_callback;
1084 else if ((DIDD_Table[x].
type > 0) && (DIDD_Table[x].
type < 16)) {
1085 diva_add_card(&DIDD_Table[x]);
1099 static void divacapi_disconnect_didd(
void)
1123 static int __init init_main_structs(
void)
1126 DBG_ERR((
"init: failed alloc mapped_msg."))
1130 if (!(adapter = diva_os_malloc(0,
sizeof(DIVA_CAPI_ADAPTER) * MAX_DESCRIPTORS))) {
1131 DBG_ERR((
"init: failed alloc adapter struct."))
1132 diva_os_free(0, mapped_msg);
1135 memset(adapter, 0,
sizeof(DIVA_CAPI_ADAPTER) * MAX_DESCRIPTORS);
1137 if (!(application = diva_os_malloc(0,
sizeof(
APPL) * MAX_APPL))) {
1138 DBG_ERR((
"init: failed alloc application struct."))
1139 diva_os_free(0, mapped_msg);
1140 diva_os_free(0, adapter);
1151 static
void remove_main_structs(
void)
1154 diva_os_free(0, application);
1156 diva_os_free(0, adapter);
1158 diva_os_free(0, mapped_msg);
1164 static void do_api_remove_start(
void)
1167 int ret = 1,
count = 100;
1170 diva_os_enter_spin_lock(&api_lock, &old_irql,
"api remove start");
1172 diva_os_leave_spin_lock(&api_lock, &old_irql,
"api remove start");
1175 }
while (ret &&
count--);
1178 DBG_ERR((
"could not remove signaling ID's"))
1186 diva_os_initialize_spin_lock(&api_lock,
"capifunc");
1187 memset(ControllerMap, 0, MAX_DESCRIPTORS + 1);
1191 if (!init_main_structs()) {
1192 DBG_ERR((
"init: failed to init main structs."))
1197 if (!divacapi_connect_didd()) {
1198 DBG_ERR((
"init: failed to connect to DIDD."))
1199 do_api_remove_start();
1200 divacapi_remove_cards();
1201 remove_main_structs();
1214 do_api_remove_start();
1215 divacapi_disconnect_didd();
1216 divacapi_remove_cards();
1217 remove_main_structs();