📄 ie.c
字号:
qi->connected_nr = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_CONNECT_PN; p[1] = l; if (present >= 0) { p[2] = 0x00 + (type<<4) + plan; p[3] = 0x80 + (present<<5) + screen; if (number) if (number[0]) strncpy((char *)p+4, (char *)number, strlen((char *)number)); } else { p[2] = 0x80 + (type<<4) + plan; if (number) if (number[0]) strncpy((char *)p+3, (char *)number, strlen((char *)number)); }}void dec_ie_connected_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len, int nt, struct misdn_bchannel *bc){ *type = -1; *plan = -1; *present = -1; *screen = -1; *number = '\0'; if (!nt) { p = NULL; if (qi->connected_nr) p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->connected_nr + 1; } if (!p) return; if (p[0] < 1) { printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]); return; } *type = (p[1]&0x70) >> 4; *plan = p[1] & 0xf; if (!(p[1] & 0x80)) { if (p[0] < 2) { printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]); return; } *present = (p[2]&0x60) >> 5; *screen = p[2] & 0x3; strnncpy(number, p+3, p[0]-2, number_len); } else { strnncpy(number, p+2, p[0]-1, number_len); } if (MISDN_IE_DEBG) printf(" type=%d plan=%d present=%d screen=%d number='%s'\n", *type, *plan, *present, *screen, number);}/* IE_CAUSE */void enc_ie_cause(unsigned char **ntmode, msg_t *msg, int location, int cause, int nt, struct misdn_bchannel *bc){ unsigned char *p; Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); int l; if (location<0 || location>7) { printf("%s: ERROR: location(%d) is out of range.\n", __FUNCTION__, location); return; } if (cause<0 || cause>127) { printf("%s: ERROR: cause(%d) is out of range.\n", __FUNCTION__, cause); return; } if (MISDN_IE_DEBG) printf(" location=%d cause=%d\n", location, cause); l = 2; p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->cause = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_CAUSE; p[1] = l; p[2] = 0x80 + location; p[3] = 0x80 + cause;}void enc_ie_cause_standalone(unsigned char **ntmode, msg_t *msg, int location, int cause, int nt, struct misdn_bchannel *bc){ unsigned char *p = msg_put(msg, 4); Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); if (ntmode) *ntmode = p+1; else qi->cause = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_CAUSE; p[1] = 2; p[2] = 0x80 + location; p[3] = 0x80 + cause;}void dec_ie_cause(unsigned char *p, Q931_info_t *qi, int *location, int *cause, int nt, struct misdn_bchannel *bc){ *location = -1; *cause = -1; if (!nt) { p = NULL; if (qi->cause) p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->cause + 1; } if (!p) return; if (p[0] < 2) { printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]); return; } *location = p[1] & 0x0f; *cause = p[2] & 0x7f; if (MISDN_IE_DEBG) printf(" location=%d cause=%d\n", *location, *cause);}/* IE_CHANNEL_ID */void enc_ie_channel_id(unsigned char **ntmode, msg_t *msg, int exclusive, int channel, int nt, struct misdn_bchannel *bc){ unsigned char *p; Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); int l; struct misdn_stack *stack=get_stack_by_bc(bc); int pri = stack->pri; if (exclusive<0 || exclusive>1) { printf("%s: ERROR: exclusive(%d) is out of range.\n", __FUNCTION__, exclusive); return; } if ((channel<0 || channel>0xff) || (!pri && (channel>2 && channel<0xff)) || (pri && (channel>31 && channel<0xff)) || (pri && channel==16)) { printf("%s: ERROR: channel(%d) is out of range.\n", __FUNCTION__, channel); return; } /* if (MISDN_IE_DEBG) printf(" exclusive=%d channel=%d\n", exclusive, channel); */ if (!pri) { /* BRI */ l = 1; p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->channel_id = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_CHANNEL_ID; p[1] = l; if (channel == 0xff) channel = 3; p[2] = 0x80 + (exclusive<<3) + channel; /* printf(" exclusive=%d channel=%d\n", exclusive, channel); */ } else { /* PRI */ if (channel == 0) /* no channel */ return; /* IE not present *//* if (MISDN_IE_DEBG) printf("channel = %d\n", channel); */ if (channel == 0xff) /* any channel */ { l = 1; p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->channel_id = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_CHANNEL_ID; p[1] = l; p[2] = 0x80 + 0x20 + 0x03;/* if (MISDN_IE_DEBG) printf("%02x\n", p[2]); */ return; /* end */ } l = 3; p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->channel_id = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_CHANNEL_ID; p[1] = l; p[2] = 0x80 + 0x20 + (exclusive<<3) + 0x01; p[3] = 0x80 + 3; /* CCITT, Number, B-type */ p[4] = 0x80 + channel;/* if (MISDN_IE_DEBG) printf("%02x %02x %02x\n", p[2], p[3], p[4]); */ }}void dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive, int *channel, int nt, struct misdn_bchannel *bc){ struct misdn_stack *stack=get_stack_by_bc(bc); int pri =stack->pri; *exclusive = -1; *channel = -1; if (!nt) { p = NULL; if (qi->channel_id) p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->channel_id + 1; } if (!p) return; if (p[0] < 1) { printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]); return; } if (p[1] & 0x40) { printf("%s: ERROR: refering to channels of other interfaces is not supported.\n", __FUNCTION__); return; } if (p[1] & 0x04) { printf("%s: ERROR: using d-channel is not supported.\n", __FUNCTION__); return; } *exclusive = (p[1]&0x08) >> 3; if (!pri) { /* BRI */ if (p[1] & 0x20) { printf("%s: ERROR: extended channel ID with non PRI interface.\n", __FUNCTION__); return; } *channel = p[1] & 0x03; if (*channel == 3) *channel = 0xff; } else { /* PRI */ if (p[0] < 1) { printf("%s: ERROR: IE too short for PRI (%d).\n", __FUNCTION__, p[0]); return; } if (!(p[1] & 0x20)) { printf("%s: ERROR: basic channel ID with PRI interface.\n", __FUNCTION__); return; } if ((p[1]&0x03) == 0x00) { /* no channel */ *channel = 0; return; } if ((p[1]&0x03) == 0x03) { /* any channel */ *channel = 0xff; return; } if (p[0] < 3) { printf("%s: ERROR: IE too short for PRI with channel(%d).\n", __FUNCTION__, p[0]); return; } if (p[2] & 0x10) { printf("%s: ERROR: channel map not supported.\n", __FUNCTION__); return; } *channel = p[3] & 0x7f; if ( (*channel<1) | (*channel==16) | (*channel>31)) { printf("%s: ERROR: PRI interface channel out of range (%d).\n", __FUNCTION__, *channel); return; }/* if (MISDN_IE_DEBG) printf("%02x %02x %02x\n", p[1], p[2], p[3]); */ } if (MISDN_IE_DEBG) printf(" exclusive=%d channel=%d\n", *exclusive, *channel);}/* IE_DATE */void enc_ie_date(unsigned char **ntmode, msg_t *msg, time_t ti, int nt, struct misdn_bchannel *bc){ unsigned char *p; Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); int l; struct tm *tm; tm = localtime(&ti); if (!tm) { printf("%s: ERROR: gettimeofday() returned NULL.\n", __FUNCTION__); return; } if (MISDN_IE_DEBG) printf(" year=%d month=%d day=%d hour=%d minute=%d\n", tm->tm_year%100, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min); l = 5; p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->date = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_DATE; p[1] = l; p[2] = tm->tm_year % 100; p[3] = tm->tm_mon + 1; p[4] = tm->tm_mday; p[5] = tm->tm_hour; p[6] = tm->tm_min;}/* IE_DISPLAY */void enc_ie_display(unsigned char **ntmode, msg_t *msg, unsigned char *display, int nt, struct misdn_bchannel *bc){ unsigned char *p; Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); int l; if (!display[0]) { printf("%s: ERROR: display text not given.\n", __FUNCTION__); return; } if (strlen((char *)display) > 80) { printf("%s: WARNING: display text too long (max 80 chars), cutting.\n", __FUNCTION__); display[80] = '\0'; } /* if (MISDN_IE_DEBG) printf(" display='%s' (len=%d)\n", display, strlen((char *)display)); */ l = strlen((char *)display); p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->display = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_DISPLAY; p[1] = l; strncpy((char *)p+2, (char *)display, strlen((char *)display));}void dec_ie_display(unsigned char *p, Q931_info_t *qi, unsigned char *display, int display_len, int nt, struct misdn_bchannel *bc){ *display = '\0'; if (!nt) { p = NULL; if (qi->display) p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->display + 1; } if (!p) return; if (p[0] < 1) { printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]); return; } strnncpy(display, p+1, p[0], display_len); if (MISDN_IE_DEBG) printf(" display='%s'\n", display);}/* IE_KEYPAD */void enc_ie_keypad(unsigned char **ntmode, msg_t *msg, unsigned char *keypad, int nt, struct misdn_bchannel *bc){ unsigned char *p; Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); int l; if (!keypad[0]) { printf("%s: ERROR: keypad info not given.\n", __FUNCTION__); return; } if (MISDN_IE_DEBG) printf(" keypad='%s'\n", keypad); l = strlen((char *)keypad); p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->keypad = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_KEYPAD; p[1] = l; strncpy((char *)p+2, (char *)keypad, strlen((char *)keypad));}void dec_ie_keypad(unsigned char *p, Q931_info_t *qi, unsigned char *keypad, int keypad_len, int nt, struct misdn_bchannel *bc){ *keypad = '\0'; if (!nt) { p = NULL; if (qi->keypad) p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->keypad + 1; } if (!p) return; if (p[0] < 1) { printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]); return; } strnncpy(keypad, p+1, p[0], keypad_len); if (MISDN_IE_DEBG) printf(" keypad='%s'\n", keypad);}/* IE_NOTIFY */void enc_ie_notify(unsigned char **ntmode, msg_t *msg, int notify, int nt, struct misdn_bchannel *bc){ unsigned char *p; Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); int l; if (notify<0 || notify>0x7f) { printf("%s: ERROR: notify(%d) is out of range.\n", __FUNCTION__, notify); return; } if (MISDN_IE_DEBG) printf(" notify=%d\n", notify); l = 1; p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->notify = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_NOTIFY; p[1] = l; p[2] = 0x80 + notify;}void dec_ie_notify(unsigned char *p, Q931_info_t *qi, int *notify, int nt, struct misdn_bchannel *bc){ *notify = -1; if (!nt) { p = NULL; if (qi->notify) p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->notify + 1; } if (!p) return; if (p[0] < 1) { printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]); return; } *notify = p[1] & 0x7f; if (MISDN_IE_DEBG) printf(" notify=%d\n", *notify);}/* IE_PROGRESS */void enc_ie_progress(unsigned char **ntmode, msg_t *msg, int coding, int location, int progress, int nt, struct misdn_bchannel *bc){ unsigned char *p; Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); int l; if (coding<0 || coding>0x03) { printf("%s: ERROR: coding(%d) is out of range.\n", __FUNCTION__, coding); return; } if (location<0 || location>0x0f) { printf("%s: ERROR: location(%d) is out of range.\n", __FUNCTION__, location); return; } if (progress<0 || progress>0x7f) { printf("%s: ERROR: progress(%d) is out of range.\n", __FUNCTION__, progress); return; } if (MISDN_IE_DEBG) printf(" coding=%d location=%d progress=%d\n", coding, location, progress); l = 2; p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->progress = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_PROGRESS; p[1] = l; p[2] = 0x80 + (coding<<5) + location; p[3] = 0x80 + progress;}void dec_ie_progress(unsigned char *p, Q931_info_t *qi, int *coding, int *location, int *progress, int nt, struct misdn_bchannel *bc){ *coding = -1; *location = -1; //*progress = -1; *progress = 0; if (!nt) { p = NULL; if (qi->progress) p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->progress + 1; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -