unsigned char mISDN_rand[256];
int mISDN_rand_count = 0;
-unsigned long mt_assign_pid = ~0;
+unsigned int mt_assign_pid = ~0;
int mISDNsocket = -1;
p_m_timeout = 0;
p_m_timer = 0;
p_m_remote_ref = 0; /* channel shall be exported to given remote */
- p_m_remote_id = 0; /* channel shall be exported to given remote */
+ p_m_remote_id = 0; /* remote admin socket */
SCPY(p_m_pipeline, mISDNport->ifport->interface->pipeline);
/* audio */
*/
static struct isdn_message {
char *name;
- unsigned long value;
+ unsigned int value;
} isdn_message[] = {
{"PH_ACTIVATE", L1_ACTIVATE_REQ},
{"PH_DEACTIVATE", L1_DEACTIVATE_REQ},
" INDICATION",
" RESPONSE",
};
-void l1l2l3_trace_header(struct mISDNport *mISDNport, class PmISDN *port, unsigned long msg, int direction)
+void l1l2l3_trace_header(struct mISDNport *mISDNport, class PmISDN *port, unsigned int msg, int direction)
{
int i;
char msgtext[64] = "<<UNKNOWN MESSAGE>>";
/*
* send control information to the channel (dsp-module)
*/
-void ph_control(struct mISDNport *mISDNport, class PmISDN *isdnport, unsigned long sock, unsigned long c1, unsigned long c2, char *trace_name, int trace_value)
+void ph_control(struct mISDNport *mISDNport, class PmISDN *isdnport, int sock, unsigned int c1, unsigned int c2, char *trace_name, int trace_value)
{
unsigned char buffer[MISDN_HEADER_LEN+sizeof(int)+sizeof(int)];
struct mISDNhead *ctrl = (struct mISDNhead *)buffer;
- unsigned long *d = (unsigned long *)(buffer+MISDN_HEADER_LEN);
+ unsigned int *d = (unsigned int *)(buffer+MISDN_HEADER_LEN);
int ret;
if (sock < 0)
end_trace();
}
-void ph_control_block(struct mISDNport *mISDNport, class PmISDN *isdnport, int sock, unsigned long c1, void *c2, int c2_len, char *trace_name, int trace_value)
+void ph_control_block(struct mISDNport *mISDNport, class PmISDN *isdnport, int sock, unsigned int c1, void *c2, int c2_len, char *trace_name, int trace_value)
{
unsigned char buffer[MISDN_HEADER_LEN+sizeof(int)+c2_len];
struct mISDNhead *ctrl = (struct mISDNhead *)buffer;
- unsigned long *d = (unsigned long *)(buffer+MISDN_HEADER_LEN);
+ unsigned int *d = (unsigned int *)(buffer+MISDN_HEADER_LEN);
int ret;
if (sock < 0)
static int _bchannel_create(struct mISDNport *mISDNport, int i)
{
int ret;
- unsigned long on = 1;
+ unsigned int on = 1;
struct sockaddr_mISDN addr;
if (mISDNport->b_socket[i] > -1)
class PmISDN *b_port = mISDNport->b_port[i];
int state = mISDNport->b_state[i];
double timer = mISDNport->b_timer[i];
- unsigned long p_m_remote_ref = 0;
- unsigned long p_m_remote_id = 0;
+ unsigned int p_m_remote_ref = 0;
+ unsigned int p_m_remote_id = 0;
int p_m_tx_gain = 0;
int p_m_rx_gain = 0;
char *p_m_pipeline = NULL;
unsigned char *p_m_crypt_key = NULL;
int p_m_crypt_key_len = 0;
int p_m_crypt_key_type = 0;
- unsigned long portid = (mISDNport->portnum<<8) + i+1+(i>=15);
+ unsigned int portid = (mISDNport->portnum<<8) + i+1+(i>=15);
if (b_port)
{
if (p_m_remote_ref)
{
/* export bchannel */
- message_bchannel_to_join(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, portid, p_m_tx_gain, p_m_rx_gain, p_m_pipeline, p_m_crypt_key, p_m_crypt_key_len, p_m_crypt_key_type);
+ message_bchannel_to_remote(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, portid, p_m_tx_gain, p_m_rx_gain, p_m_pipeline, p_m_crypt_key, p_m_crypt_key_len, p_m_crypt_key_type);
chan_trace_header(mISDNport, b_port, "MESSAGE_BCHANNEL (to remote application)", DIRECTION_NONE);
add_trace("type", NULL, "assign");
add_trace("channel", NULL, "%d.%d", portid>>8, portid&0xff);
/* in case, the bchannel is exported right after seize_bchannel */
/* export bchannel */
/* p_m_remote_id is set, when this event happens. */
- message_bchannel_to_join(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, portid, p_m_tx_gain, p_m_rx_gain, p_m_pipeline, p_m_crypt_key, p_m_crypt_key_len, p_m_crypt_key_type);
+ message_bchannel_to_remote(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, portid, p_m_tx_gain, p_m_rx_gain, p_m_pipeline, p_m_crypt_key, p_m_crypt_key_len, p_m_crypt_key_type);
chan_trace_header(mISDNport, b_port, "MESSAGE_BCHANNEL (to remote application)", DIRECTION_NONE);
add_trace("type", NULL, "assign");
add_trace("channel", NULL, "%d.%d", portid>>8, portid&0xff);
case B_STATE_REMOTE:
/* bchannel is exported, so we re-import */
- message_bchannel_to_join(mISDNport->b_remote_id[i], 0, BCHANNEL_REMOVE, portid, 0,0,0,0,0,0);
+ message_bchannel_to_remote(mISDNport->b_remote_id[i], 0, BCHANNEL_REMOVE, portid, 0,0,0,0,0,0);
chan_trace_header(mISDNport, b_port, "MESSAGE_BCHANNEL (to remote application)", DIRECTION_NONE);
add_trace("type", NULL, "remove");
add_trace("channel", NULL, "%d.%d", portid>>8, portid&0xff);
* OR bchannel is not used anymore
* OR bchannel has been exported to an obsolete ref,
* so reimport, to later export to new remote */
- message_bchannel_to_join(mISDNport->b_remote_id[i], 0, BCHANNEL_REMOVE, portid, 0,0,0,0,0,0);
+ message_bchannel_to_remote(mISDNport->b_remote_id[i], 0, BCHANNEL_REMOVE, portid, 0,0,0,0,0,0);
chan_trace_header(mISDNport, b_port, "MESSAGE_BCHANNEL (to remote application)", DIRECTION_NONE);
add_trace("type", NULL, "remove");
add_trace("channel", NULL, "%d.%d", portid>>8, portid&0xff);
case B_STATE_REMOTE:
/* bchannel is exported, so we re-import */
- message_bchannel_to_join(mISDNport->b_remote_id[i], 0, BCHANNEL_REMOVE, portid, 0,0,0,0,0,0);
+ message_bchannel_to_remote(mISDNport->b_remote_id[i], 0, BCHANNEL_REMOVE, portid, 0,0,0,0,0,0);
chan_trace_header(mISDNport, b_port, "MESSAGE_BCHANNEL (to remote application)", DIRECTION_NONE);
add_trace("type", NULL, "remove");
add_trace("channel", NULL, "%d.%d", portid>>8, portid&0xff);
/* bchannel is now deactivate, but is requied by Port class, so we reactivate / export */
if (p_m_remote_ref)
{
- message_bchannel_to_join(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, portid, p_m_tx_gain, p_m_rx_gain, p_m_pipeline, p_m_crypt_key, p_m_crypt_key_len, p_m_crypt_key_type);
+ message_bchannel_to_remote(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, portid, p_m_tx_gain, p_m_rx_gain, p_m_pipeline, p_m_crypt_key, p_m_crypt_key_len, p_m_crypt_key_type);
chan_trace_header(mISDNport, b_port, "MESSAGE_BCHANNEL (to remote application)", DIRECTION_NONE);
add_trace("type", NULL, "assign");
add_trace("channel", NULL, "%d.%d", portid>>8, portid&0xff);
/* bchannel is now imported, but is requied by Port class, so we reactivate / export */
if (p_m_remote_ref)
{
- message_bchannel_to_join(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, portid, p_m_tx_gain, p_m_rx_gain, p_m_pipeline, p_m_crypt_key, p_m_crypt_key_len, p_m_crypt_key_type);
+ message_bchannel_to_remote(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, portid, p_m_tx_gain, p_m_rx_gain, p_m_pipeline, p_m_crypt_key, p_m_crypt_key_len, p_m_crypt_key_type);
chan_trace_header(mISDNport, b_port, "MESSAGE_BCHANNEL (to remote application)", DIRECTION_NONE);
add_trace("type", NULL, "assign");
add_trace("channel", NULL, "%d.%d", portid>>8, portid&0xff);
}
/* process bchannel export/import message from join */
-void message_bchannel_from_join(class JoinRemote *joinremote, int type, unsigned long handle)
+void message_bchannel_from_remote(class JoinRemote *joinremote, int type, unsigned int handle)
{
class Endpoint *epoint;
class Port *port;
break;
case BCHANNEL_RELEASE:
- /* find the port object for the join object ref */
- if (!(epoint = find_epoint_id(joinremote->j_epoint_id)))
- {
- PDEBUG(DEBUG_BCHANNEL, "join %d has no endpoint (anymore)\n", joinremote->j_serial);
- return;
- }
- if (!epoint->ep_portlist)
- {
- PDEBUG(DEBUG_BCHANNEL, "join %d has no port (anymore in portlist)\n", joinremote->j_serial);
- return;
- }
- if (epoint->ep_portlist->next)
- {
- PERROR("join %d has enpoint %d with more than one port. this shall not happen to remote joins.\n", joinremote->j_serial, epoint->ep_serial);
- }
- if (!(port = find_port_id(epoint->ep_portlist->port_id)))
- {
- PDEBUG(DEBUG_BCHANNEL, "join %d has no port (anymore as object)\n", joinremote->j_serial);
- return;
- }
- if ((port->p_type&PORT_CLASS_MASK) != PORT_CLASS_mISDN)
- {
- PERROR("join %d has port %d not of mISDN type. This shall not happen.\n", joinremote->j_serial, port->p_serial);
- }
- isdnport = (class PmISDN *)port;
-
- /* release */
- if (!isdnport->p_m_remote_id)
- {
- PERROR("join %d recevied bchannel release from remote, but channel is already released.\n", joinremote->j_serial);
- break;
- }
- mISDNport = isdnport->p_m_mISDNport;
- i = isdnport->p_m_b_index;
- chan_trace_header(mISDNport, isdnport, "MESSAGE_BCHANNEL (from remote application)", DIRECTION_NONE);
- add_trace("type", NULL, "export request");
- end_trace();
- isdnport->p_m_remote_ref = 0;
- isdnport->p_m_remote_id = 0;
- if (mISDNport && i>=0)
- {
- bchannel_event(mISDNport, i, B_EVENT_IMPORTREQUEST);
- }
- break;
-
case BCHANNEL_ASSIGN_ACK:
case BCHANNEL_REMOVE_ACK:
/* find mISDNport for stack ID */
ii = mISDNport->b_num;
while(i < ii)
{
- if ((unsigned long)(mISDNport->portnum<<8)+i+1+(i>=15) == handle)
+ if ((unsigned int)(mISDNport->portnum<<8)+i+1+(i>=15) == handle)
break;
i++;
}
PERROR("received assign/remove ack for bchannel's handle=%x, but handle does not exist in any mISDNport structure.\n", handle);
break;
}
- /* mISDNport may now be set or NULL */
- /* set */
- chan_trace_header(mISDNport, mISDNport->b_port[i], "MESSAGE_BCHANNEL (from remote application)", DIRECTION_NONE);
- add_trace("type", NULL, (type==BCHANNEL_ASSIGN_ACK)?"assign_ack":"remove_ack");
- end_trace();
- if (mISDNport && i>=0)
+ if (type!=BCHANNEL_RELEASE)
+ {
+ /* ack */
+ chan_trace_header(mISDNport, mISDNport->b_port[i], "MESSAGE_BCHANNEL (from remote application)", DIRECTION_NONE);
+ add_trace("type", NULL, (type==BCHANNEL_ASSIGN_ACK)?"assign_ack":"remove_ack");
+ end_trace();
bchannel_event(mISDNport, i, (type==BCHANNEL_ASSIGN_ACK)?B_EVENT_EXPORTED:B_EVENT_IMPORTED);
+ } else
+ {
+ /* release */
+ isdnport = mISDNport->b_port[i];
+ chan_trace_header(mISDNport, isdnport, "MESSAGE_BCHANNEL (from remote application)", DIRECTION_NONE);
+ add_trace("type", NULL, "import request");
+ end_trace();
+ if (isdnport)
+ {
+ isdnport->p_m_remote_ref = 0;
+ isdnport->p_m_remote_id = 0;
+ }
+ bchannel_event(mISDNport, i, B_EVENT_IMPORTREQUEST);
+ }
break;
default:
PERROR("received wrong bchannel message type %d from remote\n", type);
*/
void PmISDN::bchannel_receive(struct mISDNhead *hh, unsigned char *data, int len)
{
- unsigned long cont = *((unsigned long *)data);
+ unsigned int cont = *((unsigned int *)data);
unsigned char *data_temp;
- unsigned long length_temp;
+ unsigned int length_temp;
struct lcr_msg *message;
unsigned char *p;
int l;
/* MESSAGE_mISDNSIGNAL */
//extern struct lcr_msg *dddebug;
-void PmISDN::message_mISDNsignal(unsigned long epoint_id, int message_id, union parameter *param)
+void PmISDN::message_mISDNsignal(unsigned int epoint_id, int message_id, union parameter *param)
{
switch(param->mISDNsignal.message)
{
}
/* MESSAGE_CRYPT */
-void PmISDN::message_crypt(unsigned long epoint_id, int message_id, union parameter *param)
+void PmISDN::message_crypt(unsigned int epoint_id, int message_id, union parameter *param)
{
struct lcr_msg *message;
/*
* endpoint sends messages to the port
*/
-int PmISDN::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
+int PmISDN::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
{
if (Port::message_epoint(epoint_id, message_id, param))
return(1);
break;
case MT_L2RELEASE:
- l1l2l3_trace_header(mISDNport, NULL, L2_RELEASE_IND, DIRECTION_IN);
- add_trace("tei", NULL, "%d", l3m->pid);
- end_trace();
+ if (!mISDNport->l2establish)
+ {
+ l1l2l3_trace_header(mISDNport, NULL, L2_RELEASE_IND, DIRECTION_IN);
+ add_trace("tei", NULL, "%d", l3m->pid);
+ end_trace();
+ }
if ((!mISDNport->ntmode || mISDNport->ptp) && l3m->pid < 127)
{
mISDNport->l2link = 0;
- if (mISDNport->l2hold)
+ if (!mISDNport->l2establish && mISDNport->l2hold)
{
+ PDEBUG(DEBUG_ISDN, "set timer and establish.\n");
time(&mISDNport->l2establish);
- PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
+ mISDNport->ml3->to_layer3(mISDNport->ml3, MT_L2ESTABLISH, 0, NULL);
}
}
break;
PDEBUG(DEBUG_ISDN, "the L2 establish timer expired, we try to establish the link portnum=%d.\n", mISDNport->portnum);
mISDNport->ml3->to_layer3(mISDNport->ml3, MT_L2ESTABLISH, 0, NULL);
- l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_REQ, DIRECTION_OUT);
- add_trace("tei", NULL, "%d", 0);
- end_trace();
time(&mISDNport->l2establish);
return(1);
}
while(*mISDNportp)
mISDNportp = &((*mISDNportp)->next);
mISDNport = (struct mISDNport *)MALLOC(sizeof(struct mISDNport));
+ mISDNport->l1link = -1;
pmemuse++;
*mISDNportp = mISDNport;
/*
- * global function to show all available isdn ports
- */
-void mISDN_port_info(void)
-{
- int ret;
- int i, ii;
- int useable, nt, te, pri, bri, pots;
- struct mISDN_devinfo devinfo;
- int sock;
-
- /* open mISDN */
- sock = socket(PF_ISDN, SOCK_RAW, ISDN_P_BASE);
- if (sock < 0)
- {
- fprintf(stderr, "Cannot open mISDN due to %s. (Does your Kernel support socket based mISDN?)\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
-
- /* get number of stacks */
- i = 1;
- ret = ioctl(sock, IMGETCOUNT, &ii);
- if (ret < 0)
- {
- fprintf(stderr, "Cannot get number of mISDN devices. (ioctl IMGETCOUNT failed ret=%d)\n", ret);
- goto done;
- }
- printf("\n");
- if (ii <= 0)
- {
- printf("Found no card. Please be sure to load card drivers.\n");
- goto done;
- }
-
- /* loop the number of cards and get their info */
- while(i <= ii)
- {
- nt = te = bri = pri = pots = 0;
- useable = 0;
-
- devinfo.id = i - 1;
- ret = ioctl(sock, IMGETDEVINFO, &devinfo);
- if (ret < 0)
- {
- fprintf(stderr, "Cannot get device information for port %d. (ioctl IMGETDEVINFO failed ret=%d)\n", i, ret);
- break;
- }
-
- /* output the port info */
- printf("Port %2d name='%s': ", i, devinfo.name);
- if (devinfo.Dprotocols & (1 << ISDN_P_TE_S0))
- {
- bri = 1;
- te = 1;
- }
- if (devinfo.Dprotocols & (1 << ISDN_P_NT_S0))
- {
- bri = 1;
- nt = 1;
- }
- if (devinfo.Dprotocols & (1 << ISDN_P_TE_E1))
- {
- pri = 1;
- te = 1;
- }
- if (devinfo.Dprotocols & (1 << ISDN_P_NT_E1))
- {
- pri = 1;
- nt = 1;
- }
-#ifdef ISDN_P_FXS
- if (devinfo.Dprotocols & (1 << ISDN_P_FXS))
- {
- pots = 1;
- te = 1;
- }
-#endif
-#ifdef ISDN_P_FXO
- if (devinfo.Dprotocols & (1 << ISDN_P_FXO))
- {
- pots = 1;
- nt = 1;
- }
-#endif
- if ((te || nt) && (bri || pri || pots))
- useable = 1;
-
- if (te && nt && bri)
- printf("TE/NT-mode BRI S/T (for phone lines & phones)");
- if (te && !nt && bri)
- printf("TE-mode BRI S/T (for phone lines)");
- if (nt && !te && bri)
- printf("NT-mode BRI S/T (for phones)");
- if (te && nt && pri)
- printf("TE/NT-mode PRI E1 (for phone lines & E1 devices)");
- if (te && !nt && pri)
- printf("TE-mode PRI E1 (for phone lines)");
- if (nt && !te && pri)
- printf("NT-mode PRI E1 (for E1 devices)");
- if (te && nt && pots)
- printf("FXS/FXO POTS (for analog lines & phones)");
- if (te && !nt && pots)
- printf("FXS POTS (for analog lines)");
- if (nt && !te && pots)
- printf("FXO POTS (for analog phones)");
- if (pots)
- {
- useable = 0;
- printf("\n -> Analog interfaces are not supported.");
- } else
- if (!useable)
- {
- printf("unsupported interface protocol bits 0x%016x", devinfo.Dprotocols);
- }
- printf("\n");
-
- printf(" - %d B-channels\n", devinfo.nrbchan);
-
- if (!useable)
- printf(" * Port NOT useable for LCR\n");
-
- printf("--------\n");
-
- i++;
- }
- printf("\n");
-
-done:
- close(sock);
-}
-
-
-/*
* enque data from upper buffer
*/
void PmISDN::txfromup(unsigned char *data, int length)