diff --git a/libpri.h b/libpri.h index 795678e..51805e7 100755 --- a/libpri.h +++ b/libpri.h @@ -526,8 +526,8 @@ extern int pri_mwi_deactivate(struct pri *pri, q931_call *c, char *caller, int c int pri_channel_bridge(q931_call *call1, q931_call *call2); /* Override message and error stuff */ -extern void pri_set_message(void (*__pri_error)(char *)); -extern void pri_set_error(void (*__pri_error)(char *)); +extern void pri_set_message(void (*__pri_error)(struct pri *pri, char *)); +extern void pri_set_error(void (*__pri_error)(struct pri *pri, char *)); /* Set overlap mode */ #define PRI_SET_OVERLAPDIAL diff --git a/pri.c b/pri.c index c8baa26..6c37c56 100755 --- a/pri.c +++ b/pri.c @@ -158,7 +158,7 @@ static int __pri_read(struct pri *pri, void *buf, int buflen) int res = read(pri->fd, buf, buflen); if (res < 0) { if (errno != EAGAIN) - pri_error("Read on %d failed: %s\n", pri->fd, strerror(errno)); + pri_error(pri, "Read on %d failed: %s\n", pri->fd, strerror(errno)); return 0; } return res; @@ -169,7 +169,7 @@ static int __pri_write(struct pri *pri, void *buf, int buflen) int res = write(pri->fd, buf, buflen); if (res < 0) { if (errno != EAGAIN) - pri_error("Write to %d failed: %s\n", pri->fd, strerror(errno)); + pri_error(pri, "Write to %d failed: %s\n", pri->fd, strerror(errno)); return 0; } return res; @@ -536,26 +536,26 @@ void pri_dump_event(struct pri *pri, pri_event *e) { if (!pri || !e) return; - pri_message("Event type: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e); + pri_message(pri, "Event type: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e); switch(e->gen.e) { case PRI_EVENT_DCHAN_UP: case PRI_EVENT_DCHAN_DOWN: break; case PRI_EVENT_CONFIG_ERR: - pri_message("Error: %s", e->err.err); + pri_message(pri, "Error: %s", e->err.err); break; case PRI_EVENT_RESTART: - pri_message("Restart on channel %d\n", e->restart.channel); + pri_message(pri, "Restart on channel %d\n", e->restart.channel); case PRI_EVENT_RING: - pri_message("Calling number: %s (%s, %s)\n", e->ring.callingnum, pri_plan2str(e->ring.callingplan), pri_pres2str(e->ring.callingpres)); - pri_message("Called number: %s (%s)\n", e->ring.callednum, pri_plan2str(e->ring.calledplan)); - pri_message("Channel: %d (%s) Reference number: %d\n", e->ring.channel, e->ring.flexible ? "Flexible" : "Not Flexible", e->ring.cref); + pri_message(pri, "Calling number: %s (%s, %s)\n", e->ring.callingnum, pri_plan2str(e->ring.callingplan), pri_pres2str(e->ring.callingpres)); + pri_message(pri, "Called number: %s (%s)\n", e->ring.callednum, pri_plan2str(e->ring.calledplan)); + pri_message(pri, "Channel: %d (%s) Reference number: %d\n", e->ring.channel, e->ring.flexible ? "Flexible" : "Not Flexible", e->ring.cref); break; case PRI_EVENT_HANGUP: - pri_message("Hangup, reference number: %d, reason: %s\n", e->hangup.cref, pri_cause2str(e->hangup.cause)); + pri_message(pri, "Hangup, reference number: %d, reason: %s\n", e->hangup.cref, pri_cause2str(e->hangup.cause)); break; default: - pri_message("Don't know how to dump events of type %d\n", e->gen.e); + pri_message(pri, "Don't know how to dump events of type %d\n", e->gen.e); } } @@ -593,7 +593,7 @@ int pri_mwi_activate(struct pri *pri, q931_call *c, char *caller, int callerplan req.calledplan = calledplan; if (mwi_message_send(pri, c, &req, 1) < 0) { - pri_message("Unable to send MWI activate message\n"); + pri_message(pri, "Unable to send MWI activate message\n"); return -1; } /* Do more stuff when we figure out that the CISC stuff works */ @@ -618,7 +618,7 @@ int pri_mwi_deactivate(struct pri *pri, q931_call *c, char *caller, int callerpl req.calledplan = calledplan; if(mwi_message_send(pri, c, &req, 0) < 0) { - pri_message("Unable to send MWI deactivate message\n"); + pri_message(pri, "Unable to send MWI deactivate message\n"); return -1; } @@ -655,20 +655,20 @@ int pri_call(struct pri *pri, q931_call *c, int transmode, int channel, int excl return q931_setup(pri, c, &req); } -static void (*__pri_error)(char *stuff); -static void (*__pri_message)(char *stuff); +static void (*__pri_error)(struct pri *pri, char *stuff); +static void (*__pri_message)(struct pri *pri, char *stuff); -void pri_set_message(void (*func)(char *stuff)) +void pri_set_message(void (*func)(struct pri *pri, char *stuff)) { __pri_message = func; } -void pri_set_error(void (*func)(char *stuff)) +void pri_set_error(void (*func)(struct pri *pri, char *stuff)) { __pri_error = func; } -void pri_message(char *fmt, ...) +void pri_message(struct pri *pri, char *fmt, ...) { char tmp[1024]; va_list ap; @@ -676,12 +676,12 @@ void pri_message(char *fmt, ...) vsnprintf(tmp, sizeof(tmp), fmt, ap); va_end(ap); if (__pri_message) - __pri_message(tmp); + __pri_message(pri, tmp); else fputs(tmp, stdout); } -void pri_error(char *fmt, ...) +void pri_error(struct pri *pri, char *fmt, ...) { char tmp[1024]; va_list ap; @@ -689,7 +689,7 @@ void pri_error(char *fmt, ...) vsnprintf(tmp, sizeof(tmp), fmt, ap); va_end(ap); if (__pri_error) - __pri_error(tmp); + __pri_error(pri, tmp); else fputs(tmp, stderr); } diff --git a/pri_facility.c b/pri_facility.c index 80da309..6a2a609 100755 --- a/pri_facility.c +++ b/pri_facility.c @@ -33,7 +33,7 @@ struct addressingdataelements_presentednumberunscreened { int pres; }; -static void dump_apdu(unsigned char *c, int len) +static void dump_apdu(struct pri *pri, unsigned char *c, int len) { #define MAX_APDU_LENGTH 255 int i; @@ -53,7 +53,7 @@ static void dump_apdu(unsigned char *c, int len) snprintf((char *)(message+strlen(message)), sizeof(message)-strlen(message)-1, "%c", c[i]); } snprintf((char *)(message+strlen(message)), sizeof(message)-strlen(message)-1, "]\n"); - pri_message(message); + pri_message(pri, message); } int redirectingreason_from_q931(struct pri *pri, int redirectingreason) @@ -72,7 +72,7 @@ int redirectingreason_from_q931(struct pri *pri, int redirectingreason) case PRI_REDIR_DEFLECTION: case PRI_REDIR_DTE_OUT_OF_ORDER: case PRI_REDIR_FORWARDED_BY_DTE: - pri_message("!! Don't know how to convert Q.931 redirection reason %d to Q.SIG\n", redirectingreason); + pri_message(pri, "!! Don't know how to convert Q.931 redirection reason %d to Q.SIG\n", redirectingreason); /* Fall through */ default: return QSIG_DIVERT_REASON_UNKNOWN; @@ -91,7 +91,7 @@ int redirectingreason_from_q931(struct pri *pri, int redirectingreason) return Q952_DIVERT_REASON_CFU; case PRI_REDIR_DTE_OUT_OF_ORDER: case PRI_REDIR_FORWARDED_BY_DTE: - pri_message("!! Don't know how to convert Q.931 redirection reason %d to Q.952\n", redirectingreason); + pri_message(pri, "!! Don't know how to convert Q.931 redirection reason %d to Q.952\n", redirectingreason); /* Fall through */ default: return Q952_DIVERT_REASON_UNKNOWN; @@ -113,7 +113,7 @@ static int redirectingreason_for_q931(struct pri *pri, int redirectingreason) case QSIG_DIVERT_REASON_CFNR: return PRI_REDIR_FORWARD_ON_NO_REPLY; default: - pri_message("!! Unknown Q.SIG diversion reason %d\n", redirectingreason); + pri_message(pri, "!! Unknown Q.SIG diversion reason %d\n", redirectingreason); return PRI_REDIR_UNKNOWN; } default: @@ -129,10 +129,10 @@ static int redirectingreason_for_q931(struct pri *pri, int redirectingreason) case Q952_DIVERT_REASON_CD: return PRI_REDIR_DEFLECTION; case Q952_DIVERT_REASON_IMMEDIATE: - pri_message("!! Dont' know how to convert Q.952 diversion reason IMMEDIATE to PRI analog\n"); + pri_message(pri, "!! Dont' know how to convert Q.952 diversion reason IMMEDIATE to PRI analog\n"); return PRI_REDIR_UNKNOWN; /* ??? */ default: - pri_message("!! Unknown Q.952 diversion reason %d\n", redirectingreason); + pri_message(pri, "!! Unknown Q.952 diversion reason %d\n", redirectingreason); return PRI_REDIR_UNKNOWN; } } @@ -153,7 +153,7 @@ int typeofnumber_from_q931(struct pri *pri, int ton) return Q932_TON_ABBREVIATED; case PRI_TON_RESERVED: default: - pri_message("!! Unsupported Q.931 TypeOfNumber value (%d)\n", ton); + pri_message(pri, "!! Unsupported Q.931 TypeOfNumber value (%d)\n", ton); /* fall through */ case PRI_TON_UNKNOWN: return Q932_TON_UNKNOWN; @@ -176,7 +176,7 @@ static int typeofnumber_for_q931(struct pri *pri, int ton) case Q932_TON_ABBREVIATED: return PRI_TON_ABBREVIATED; default: - pri_message("!! Invalid Q.932 TypeOfNumber %d\n", ton); + pri_message(pri, "!! Invalid Q.932 TypeOfNumber %d\n", ton); return PRI_TON_UNKNOWN; } } @@ -230,7 +230,7 @@ static int rose_number_digits_decode(struct pri *pri, q931_call *call, unsigned GET_COMPONENT(comp, i, vdata, len); CHECK_COMPONENT(comp, ASN1_NUMERICSTRING, "Don't know what to do with PublicPartyNumber ROSE component type 0x%x\n"); if(comp->len > 20 && comp->len != ASN1_LEN_INDEF) { - pri_message("!! Oversized NumberDigits component (%d)\n", comp->len); + pri_message(pri, "!! Oversized NumberDigits component (%d)\n", comp->len); return -1; } if (comp->len == ASN1_LEN_INDEF) { @@ -303,14 +303,14 @@ static int rose_address_decode(struct pri *pri, q931_call *call, unsigned char * value->npi = PRI_NPI_E163_E164; break; case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_2): /* [2] nsapEncodedNumber */ - pri_message("!! NsapEncodedNumber isn't handled\n"); + pri_message(pri, "!! NsapEncodedNumber isn't handled\n"); return -1; case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_3): /* [3] dataPartyNumber */ if(rose_number_digits_decode(pri, call, comp->data, comp->len, value)) return -1; value->npi = PRI_NPI_X121 /* ??? */; value->ton = PRI_TON_UNKNOWN /* ??? */; - pri_message("!! dataPartyNumber isn't handled\n"); + pri_message(pri, "!! dataPartyNumber isn't handled\n"); return -1; case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_4): /* [4] telexPartyNumber */ res = rose_number_digits_decode(pri, call, comp->data, comp->len, value); @@ -318,10 +318,10 @@ static int rose_address_decode(struct pri *pri, q931_call *call, unsigned char * return -1; value->npi = PRI_NPI_F69 /* ??? */; value->ton = PRI_TON_UNKNOWN /* ??? */; - pri_message("!! telexPartyNumber isn't handled\n"); + pri_message(pri, "!! telexPartyNumber isn't handled\n"); return -1; case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_5): /* [5] priavePartyNumber */ - pri_message("!! privatePartyNumber isn't handled\n"); + pri_message(pri, "!! privatePartyNumber isn't handled\n"); value->npi = PRI_NPI_PRIVATE; return -1; case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_8): /* [8] nationalStandardPartyNumber */ @@ -332,12 +332,12 @@ static int rose_address_decode(struct pri *pri, q931_call *call, unsigned char * value->ton = PRI_TON_NATIONAL; break; default: - pri_message("!! Unknown Party number component received 0x%X\n", comp->type); + pri_message(pri, "!! Unknown Party number component received 0x%X\n", comp->type); return -1; } NEXT_COMPONENT(comp, i); if(i < len) - pri_message("!! not all information is handled from Address component\n"); + pri_message(pri, "!! not all information is handled from Address component\n"); return res; } while (0); @@ -365,14 +365,14 @@ static int rose_presented_number_unscreened_decode(struct pri *pri, q931_call *c return rose_address_decode(pri, call, comp->data, comp->len, value) + 2; case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1): /* [1] IMPLICIT presentationRestricted */ if (comp->len != 0) { /* must be NULL */ - pri_error("!! Invalid PresentationRestricted component received (len != 0)\n"); + pri_error(pri, "!! Invalid PresentationRestricted component received (len != 0)\n"); return -1; } value->pres = PRES_PROHIB_USER_NUMBER_NOT_SCREENED; return 2; case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2): /* [2] IMPLICIT numberNotAvailableDueToInterworking */ if (comp->len != 0) { /* must be NULL */ - pri_error("!! Invalid NumberNotAvailableDueToInterworking component received (len != 0)\n"); + pri_error(pri, "!! Invalid NumberNotAvailableDueToInterworking component received (len != 0)\n"); return -1; } value->pres = PRES_NUMBER_NOT_AVAILABLE; @@ -381,7 +381,7 @@ static int rose_presented_number_unscreened_decode(struct pri *pri, q931_call *c value->pres = PRES_PROHIB_USER_NUMBER_NOT_SCREENED; return rose_address_decode(pri, call, comp->data, comp->len, value) + 2; default: - pri_message("Invalid PresentedNumberUnscreened component 0x%X\n", comp->type); + pri_message(pri, "Invalid PresentedNumberUnscreened component 0x%X\n", comp->type); } return -1; } @@ -418,7 +418,7 @@ static int rose_diverting_leg_information2_decode(struct pri *pri, q931_call *ca diversion_reason = redirectingreason_for_q931(pri, diversion_reason); if(pri->debug & PRI_DEBUG_APDU) - pri_message(" Redirection reason: %d, total diversions: %d\n", diversion_reason, diversion_counter); + pri_message(pri, " Redirection reason: %d, total diversions: %d\n", diversion_reason, diversion_counter); for(; i < len; NEXT_COMPONENT(comp, i)) { GET_COMPONENT(comp, i, vdata, len); @@ -426,7 +426,7 @@ static int rose_diverting_leg_information2_decode(struct pri *pri, q931_call *ca case ASN1_TAG_0: call->origredirectingreason = redirectingreason_for_q931(pri, comp->data[0]); if (pri->debug & PRI_DEBUG_APDU) - pri_message(" Received reason for original redirection %d\n", call->origredirectingreason); + pri_message(pri, " Received reason for original redirection %d\n", call->origredirectingreason); break; case ASN1_TAG_1: /* divertingnr: presentednumberunscreened */ res = rose_presented_number_unscreened_decode(pri, call, comp->data, comp->len, &divertingnr); @@ -435,8 +435,8 @@ static int rose_diverting_leg_information2_decode(struct pri *pri, q931_call *ca if (res < 0) return -1; if (pri->debug & PRI_DEBUG_APDU) { - pri_message(" Received divertingNr '%s'\n", divertingnr.partyaddress); - pri_message(" ton = %d, pres = %d, npi = %d\n", divertingnr.ton, divertingnr.pres, divertingnr.npi); + pri_message(pri, " Received divertingNr '%s'\n", divertingnr.partyaddress); + pri_message(pri, " ton = %d, pres = %d, npi = %d\n", divertingnr.ton, divertingnr.pres, divertingnr.npi); } break; case ASN1_TAG_2: /* originalCalledNr: PresentedNumberUnscreened */ @@ -445,22 +445,22 @@ static int rose_diverting_leg_information2_decode(struct pri *pri, q931_call *ca return -1; comp->len = res; if (pri->debug & PRI_DEBUG_APDU) { - pri_message(" Received originalcallednr '%s'\n", originalcallednr.partyaddress); - pri_message(" ton = %d, pres = %d, npi = %d\n", originalcallednr.ton, originalcallednr.pres, originalcallednr.npi); + pri_message(pri, " Received originalcallednr '%s'\n", originalcallednr.partyaddress); + pri_message(pri, " ton = %d, pres = %d, npi = %d\n", originalcallednr.ton, originalcallednr.pres, originalcallednr.npi); } break; case ASN1_TAG_3: comp->len = asn1_name_decode(comp->data, comp->len, redirectingname, sizeof(redirectingname)); if (pri->debug & PRI_DEBUG_APDU) - pri_message(" Received RedirectingName '%s'\n", redirectingname); + pri_message(pri, " Received RedirectingName '%s'\n", redirectingname); break; case ASN1_TAG_4: comp->len = asn1_name_decode(comp->data, comp->len, origcalledname, sizeof(origcalledname)); if (pri->debug & PRI_DEBUG_APDU) - pri_message(" Received Originally Called Name '%s'\n", origcalledname); + pri_message(pri, " Received Originally Called Name '%s'\n", origcalledname); break; default: - pri_message("!! Invalid DivertingLegInformation2 component received 0x%X\n", comp->type); + pri_message(pri, "!! Invalid DivertingLegInformation2 component received 0x%X\n", comp->type); return -1; } } @@ -570,7 +570,7 @@ static int rose_diverting_leg_information2_encode(struct pri *pri, q931_call *ca ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1), buffer, i); break; default: - pri_message("!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres); + pri_message(pri, "!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres); case PRES_NUMBER_NOT_AVAILABLE: ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer, i); break; @@ -614,7 +614,7 @@ static int rose_diverting_leg_information2_encode(struct pri *pri, q931_call *ca ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1), buffer, i); break; default: - pri_message("!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres); + pri_message(pri, "!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres); case PRES_NUMBER_NOT_AVAILABLE: ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer, i); break; @@ -841,7 +841,7 @@ extern int eect_initiate_transfer(struct pri *pri, q931_call *c1, q931_call *c2) res = pri_call_apdu_queue(c1, Q931_FACILITY, buffer, i, NULL, NULL); if (res) { - pri_message("Could not queue ADPU in facility message\n"); + pri_message(pri, "Could not queue ADPU in facility message\n"); return -1; } @@ -850,7 +850,7 @@ extern int eect_initiate_transfer(struct pri *pri, q931_call *c1, q931_call *c2) res = q931_facility(c1->pri, c1); if (res) { - pri_message("Could not schedule facility message for call %d\n", c1->cr); + pri_message(pri, "Could not schedule facility message for call %d\n", c1->cr); return -1; } @@ -867,7 +867,7 @@ static int aoc_aoce_charging_request_decode(struct pri *pri, q931_call *call, un int pos1 = 0; if (pri->debug & PRI_DEBUG_AOC) - dump_apdu (data, len); + dump_apdu (pri, data, len); do { GET_COMPONENT(comp, pos1, vdata, len); @@ -875,17 +875,17 @@ static int aoc_aoce_charging_request_decode(struct pri *pri, q931_call *call, un ASN1_GET_INTEGER(comp, chargingcase); if (chargingcase >= 0 && chargingcase <= 2) { if (pri->debug & PRI_DEBUG_APDU) - pri_message("Channel %d/%d, Call %d - received AOC charging request - charging case: %i\n", + pri_message(pri, "Channel %d/%d, Call %d - received AOC charging request - charging case: %i\n", call->ds1no, call->channelno, call->cr, chargingcase); } else { - pri_message("!! unkown AOC ChargingCase: 0x%02X", chargingcase); + pri_message(pri, "!! unkown AOC ChargingCase: 0x%02X", chargingcase); chargingcase = -1; } NEXT_COMPONENT(comp, pos1); } while (pos1 < len); if (pos1 < len) { - pri_message("!! Only reached position %i in %i bytes long AOC-E structure:", pos1, len ); - dump_apdu (data, len); + pri_message(pri, "!! Only reached position %i in %i bytes long AOC-E structure:", pos1, len ); + dump_apdu (pri, data, len); return -1; /* Aborted before */ } return 0; @@ -901,7 +901,7 @@ static int aoc_aoce_charging_unit_decode(struct pri *pri, q931_call *call, unsig struct addressingdataelements_presentednumberunscreened chargednr; if (pri->debug & PRI_DEBUG_AOC) - dump_apdu (data, len); + dump_apdu (pri, data, len); do { GET_COMPONENT(comp1, pos1, vdata, len); /* AOCEChargingUnitInfo */ @@ -934,34 +934,34 @@ static int aoc_aoce_charging_unit_decode(struct pri *pri, q931_call *call, unsig case ASN1_NULL: /* notAvailable */ break; default: - pri_message("!! Don't know how to handle 0x%02X in AOC-E RecordedUnits\n", comp3->type); + pri_message(pri, "!! Don't know how to handle 0x%02X in AOC-E RecordedUnits\n", comp3->type); } NEXT_COMPONENT(comp3, pos3); } while (pos3 < sublen3); if (pri->debug & PRI_DEBUG_AOC) - pri_message("Channel %d/%d, Call %d - received AOC-E charging: %i unit%s\n", + pri_message(pri, "Channel %d/%d, Call %d - received AOC-E charging: %i unit%s\n", call->ds1no, call->channelno, call->cr, chargingunits, (chargingunits == 1) ? "" : "s"); break; case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_2): /* AOCEBillingID (0xA2) */ SUB_COMPONENT(comp2, pos2); GET_COMPONENT(comp2, pos2, vdata, len); ASN1_GET_INTEGER(comp2, chargetype); - pri_message("!! not handled: Channel %d/%d, Call %d - received AOC-E billing ID: %i\n", + pri_message(pri, "!! not handled: Channel %d/%d, Call %d - received AOC-E billing ID: %i\n", call->ds1no, call->channelno, call->cr, chargetype); break; default: - pri_message("!! Don't know how to handle 0x%02X in AOC-E RecordedUnitsList\n", comp2->type); + pri_message(pri, "!! Don't know how to handle 0x%02X in AOC-E RecordedUnitsList\n", comp2->type); } NEXT_COMPONENT(comp2, pos2); } while (pos2 < sublen2); break; case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1): /* freeOfCharge (0x81) */ if (pri->debug & PRI_DEBUG_AOC) - pri_message("Channel %d/%d, Call %d - received AOC-E free of charge\n", call->ds1no, call->channelno, call->cr); + pri_message(pri, "Channel %d/%d, Call %d - received AOC-E free of charge\n", call->ds1no, call->channelno, call->cr); chargingunits = 0; break; default: - pri_message("!! Invalid AOC-E specificChargingUnits. Expected Sequence (0x30) or Object Identifier (0x81/0x01) but received 0x%02X\n", comp1->type); + pri_message(pri, "!! Invalid AOC-E specificChargingUnits. Expected Sequence (0x30) or Object Identifier (0x81/0x01) but received 0x%02X\n", comp1->type); } NEXT_COMPONENT(comp1, pos1); GET_COMPONENT(comp1, pos1, vdata, len); /* get optional chargingAssociation. will 'break' when reached end of structure */ @@ -970,21 +970,21 @@ static int aoc_aoce_charging_unit_decode(struct pri *pri, q931_call *call, unsig case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_0): /* chargedNumber (0xA0) */ if(rose_presented_number_unscreened_decode(pri, call, comp1->data, comp1->len, &chargednr) != 0) return -1; - pri_message("!! not handled: Received ChargedNr '%s' \n", chargednr.partyaddress); - pri_message(" ton = %d, pres = %d, npi = %d\n", chargednr.ton, chargednr.pres, chargednr.npi); + pri_message(pri, "!! not handled: Received ChargedNr '%s' \n", chargednr.partyaddress); + pri_message(pri, " ton = %d, pres = %d, npi = %d\n", chargednr.ton, chargednr.pres, chargednr.npi); break; case ASN1_INTEGER: ASN1_GET_INTEGER(comp1, chargeIdentifier); break; default: - pri_message("!! Invalid AOC-E chargingAssociation. Expected Object Identifier (0xA0) or Integer (0x02) but received 0x%02X\n", comp1->type); + pri_message(pri, "!! Invalid AOC-E chargingAssociation. Expected Object Identifier (0xA0) or Integer (0x02) but received 0x%02X\n", comp1->type); } NEXT_COMPONENT(comp1, pos1); } while (pos1 < len); if (pos1 < len) { - pri_message("!! Only reached position %i in %i bytes long AOC-E structure:", pos1, len ); - dump_apdu (data, len); + pri_message(pri, "!! Only reached position %i in %i bytes long AOC-E structure:", pos1, len ); + dump_apdu (pri, data, len); return -1; /* oops - aborted before */ } call->aoc_units = chargingunits; @@ -1043,12 +1043,12 @@ static int aoc_aoce_charging_unit_encode(struct pri *pri, q931_call *c, long cha ASN1_FIXUP(compstk, compsp, buffer, i); if (pri->debug & PRI_DEBUG_AOC) - dump_apdu (buffer, i); + dump_apdu (pri, buffer, i); /* code below is untested */ res = pri_call_apdu_queue(c, Q931_FACILITY, buffer, i, NULL, NULL); if (res) { - pri_message("Could not queue ADPU in facility message\n"); + pri_message(pri, "Could not queue ADPU in facility message\n"); return -1; } @@ -1056,7 +1056,7 @@ static int aoc_aoce_charging_unit_encode(struct pri *pri, q931_call *c, long cha * have to explicitly send the facility message ourselves */ res = q931_facility(c->pri, c); if (res) { - pri_message("Could not schedule facility message for call %d\n", c->cr); + pri_message(pri, "Could not schedule facility message for call %d\n", c->cr); return -1; } @@ -1095,68 +1095,68 @@ extern int rose_invoke_decode(struct pri *pri, q931_call *call, unsigned char *d return -1; if (pri->debug & PRI_DEBUG_APDU) - pri_message(" [ Handling operation %d ]\n", operation_tag); + pri_message(pri, " [ Handling operation %d ]\n", operation_tag); switch (operation_tag) { case SS_CNID_CALLINGNAME: if (pri->debug & PRI_DEBUG_APDU) - pri_message(" Handle Name display operation\n"); + pri_message(pri, " Handle Name display operation\n"); switch (comp->type) { case ROSE_NAME_PRESENTATION_ALLOWED_SIMPLE: memcpy(call->callername, comp->data, comp->len); call->callername[comp->len] = 0; if (pri->debug & PRI_DEBUG_APDU) - pri_message(" Received caller name '%s'\n", call->callername); + pri_message(pri, " Received caller name '%s'\n", call->callername); return 0; default: if (pri->debug & PRI_DEBUG_APDU) - pri_message("Do not handle argument of type 0x%X\n", comp->type); + pri_message(pri, "Do not handle argument of type 0x%X\n", comp->type); return -1; } break; case ROSE_DIVERTING_LEG_INFORMATION2: if (pri->debug & PRI_DEBUG_APDU) - pri_message(" Handle DivertingLegInformation2\n"); + pri_message(pri, " Handle DivertingLegInformation2\n"); if (comp->type != (ASN1_CONSTRUCTOR | ASN1_SEQUENCE)) { /* Constructed Sequence */ - pri_message("Invalid DivertingLegInformation2Type argument\n"); + pri_message(pri, "Invalid DivertingLegInformation2Type argument\n"); return -1; } return rose_diverting_leg_information2_decode(pri, call, comp->data, comp->len); case ROSE_AOC_NO_CHARGING_INFO_AVAILABLE: if (pri->debug & PRI_DEBUG_APDU) { - pri_message("ROSE %i: AOC No Charging Info Available - not handled!", operation_tag); - dump_apdu (comp->data, comp->len); + pri_message(pri, "ROSE %i: AOC No Charging Info Available - not handled!", operation_tag); + dump_apdu (pri, comp->data, comp->len); } return -1; case ROSE_AOC_CHARGING_REQUEST: return aoc_aoce_charging_request_decode(pri, call, (u_int8_t *)comp, comp->len + 2); case ROSE_AOC_AOCS_CURRENCY: if (pri->debug & PRI_DEBUG_APDU) { - pri_message("ROSE %i: AOC-S Currency - not handled!", operation_tag); - dump_apdu ((u_int8_t *)comp, comp->len + 2); + pri_message(pri, "ROSE %i: AOC-S Currency - not handled!", operation_tag); + dump_apdu (pri, (u_int8_t *)comp, comp->len + 2); } return -1; case ROSE_AOC_AOCS_SPECIAL_ARR: if (pri->debug & PRI_DEBUG_APDU) { - pri_message("ROSE %i: AOC-S Special Array - not handled!", operation_tag); - dump_apdu ((u_int8_t *)comp, comp->len + 2); + pri_message(pri, "ROSE %i: AOC-S Special Array - not handled!", operation_tag); + dump_apdu (pri, (u_int8_t *)comp, comp->len + 2); } return -1; case ROSE_AOC_AOCD_CURRENCY: if (pri->debug & PRI_DEBUG_APDU) { - pri_message("ROSE %i: AOC-D Currency - not handled!", operation_tag); - dump_apdu ((u_int8_t *)comp, comp->len + 2); + pri_message(pri, "ROSE %i: AOC-D Currency - not handled!", operation_tag); + dump_apdu (pri, (u_int8_t *)comp, comp->len + 2); } return -1; case ROSE_AOC_AOCD_CHARGING_UNIT: if (pri->debug & PRI_DEBUG_APDU) { - pri_message("ROSE %i: AOC-D Charging Unit - not handled!", operation_tag); - dump_apdu ((u_int8_t *)comp, comp->len + 2); + pri_message(pri, "ROSE %i: AOC-D Charging Unit - not handled!", operation_tag); + dump_apdu (pri, (u_int8_t *)comp, comp->len + 2); } return -1; case ROSE_AOC_AOCE_CURRENCY: if (pri->debug & PRI_DEBUG_APDU) { - pri_message("ROSE %i: AOC-E Currency - not handled!", operation_tag); - dump_apdu ((u_int8_t *)comp, comp->len + 2); + pri_message(pri, "ROSE %i: AOC-E Currency - not handled!", operation_tag); + dump_apdu (pri, (u_int8_t *)comp, comp->len + 2); } return -1; case ROSE_AOC_AOCE_CHARGING_UNIT: @@ -1167,14 +1167,14 @@ extern int rose_invoke_decode(struct pri *pri, q931_call *call, unsigned char *d } case ROSE_AOC_IDENTIFICATION_OF_CHARGE: if (pri->debug & PRI_DEBUG_APDU) { - pri_message("ROSE %i: AOC Identification Of Charge - not handled!", operation_tag); - dump_apdu ((u_int8_t *)comp, comp->len + 2); + pri_message(pri, "ROSE %i: AOC Identification Of Charge - not handled!", operation_tag); + dump_apdu (pri, (u_int8_t *)comp, comp->len + 2); } return -1; default: if (pri->debug & PRI_DEBUG_APDU) { - pri_message("!! Unable to handle ROSE operation %d", operation_tag); - dump_apdu ((u_int8_t *)comp, comp->len + 2); + pri_message(pri, "!! Unable to handle ROSE operation %d", operation_tag); + dump_apdu (pri, (u_int8_t *)comp, comp->len + 2); } return -1; } @@ -1201,7 +1201,7 @@ extern int pri_call_apdu_queue(q931_call *call, int messagetype, void *apdu, int memcpy(new_event->apdu, apdu, apdu_len); new_event->apdu_len = apdu_len; } else { - pri_error("!! Malloc failed!\n"); + pri_error(call->pri, "!! Malloc failed!\n"); return -1; } diff --git a/pri_facility.h b/pri_facility.h index 0fd5f87..37dd728 100755 --- a/pri_facility.h +++ b/pri_facility.h @@ -147,7 +147,7 @@ struct rose_component { (component) = (struct rose_component*)&((ptr)[idx]); \ if ((idx)+(component)->len+2 > (length)) { \ if ((component)->len != 128) \ - pri_message("Length (%d) of 0x%X component is too long\n", (component)->len, (component)->type); \ + pri_message(pri, "Length (%d) of 0x%X component is too long\n", (component)->len, (component)->type); \ } /* pri_message("XX Got component %d (0x%02X), length %d\n", (component)->type, (component)->type, (component)->len); \ @@ -168,7 +168,7 @@ struct rose_component { #define CHECK_COMPONENT(component, comptype, message) \ if ((component)->type && ((component)->type & ASN1_TYPE_MASK) != (comptype)) { \ - pri_message((message), (component)->type); \ + pri_message(pri, (message), (component)->type); \ break; \ } diff --git a/pri_internal.h b/pri_internal.h index 3dcf0ad..23d2346 100755 --- a/pri_internal.h +++ b/pri_internal.h @@ -246,8 +246,8 @@ extern void pri_schedule_del(struct pri *pri, int ev); extern pri_event *pri_mkerror(struct pri *pri, char *errstr); -extern void pri_message(char *fmt, ...); +extern void pri_message(struct pri *pri, char *fmt, ...); -extern void pri_error(char *fmt, ...); +extern void pri_error(struct pri *pri, char *fmt, ...); #endif diff --git a/pri_q921.h b/pri_q921.h index 23bcfdc..1c4d6ad 100755 --- a/pri_q921.h +++ b/pri_q921.h @@ -161,7 +161,7 @@ typedef enum q921_state { } q921_state; /* Dumps a *known good* Q.921 packet */ -extern void q921_dump(q921_h *h, int len, int showraw, int txrx); +extern void q921_dump(struct pri *pri, q921_h *h, int len, int showraw, int txrx); /* Bring up the D-channel */ extern void q921_start(struct pri *pri, int now); diff --git a/pri_q931.h b/pri_q931.h index ee406ba..6b3fe50 100755 --- a/pri_q931.h +++ b/pri_q931.h @@ -276,7 +276,7 @@ extern int q931_call_setcrv(struct pri *pri, q931_call *call, int crv, int callm extern q931_call *q931_new_call(struct pri *pri); extern int q931_setup(struct pri *pri, q931_call *c, struct pri_sr *req); -extern void q931_dump(q931_h *h, int len, int txrx); +extern void q931_dump(struct pri *pri, q931_h *h, int len, int txrx); extern void __q931_destroycall(struct pri *pri, q931_call *c); diff --git a/prisched.c b/prisched.c index cc668ec..d414ece 100755 --- a/prisched.c +++ b/prisched.c @@ -38,7 +38,7 @@ int pri_schedule_event(struct pri *pri, int ms, void (*function)(void *data), vo if (!pri->pri_sched[x].callback) break; if (x == MAX_SCHED) { - pri_error("No more room in scheduler\n"); + pri_error(pri, "No more room in scheduler\n"); return -1; } if (x > maxsched) @@ -113,6 +113,6 @@ pri_event *pri_schedule_run(struct pri *pri) void pri_schedule_del(struct pri *pri,int id) { if ((id >= MAX_SCHED) || (id < 0)) - pri_error("Asked to delete sched id %d???\n", id); + pri_error(pri, "Asked to delete sched id %d???\n", id); pri->pri_sched[id].callback = NULL; } diff --git a/q921.c b/q921.c index 86bd122..bde095a 100755 --- a/q921.c +++ b/q921.c @@ -72,7 +72,7 @@ static int q921_transmit(struct pri *pri, q921_h *h, int len) return q921_transmit(pri->master, h, len); #ifdef RANDOM_DROPS if (!(random() % 3)) { - pri_message(" === Dropping Packet ===\n"); + pri_message(pri, " === Dropping Packet ===\n"); return 0; } #endif @@ -81,11 +81,11 @@ static int q921_transmit(struct pri *pri, q921_h *h, int len) #endif /* Just send it raw */ if (pri->debug & PRI_DEBUG_Q921_DUMP) - q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 1); + q921_dump(pri, h, len, pri->debug & PRI_DEBUG_Q921_RAW, 1); /* Write an extra two bytes for the FCS */ res = pri->write_func ? pri->write_func(pri, h, len + 2) : 0; if (res != (len + 2)) { - pri_error("Short write: %d/%d (%s)\n", res, len + 2, strerror(errno)); + pri_error(pri, "Short write: %d/%d (%s)\n", res, len + 2, strerror(errno)); return -1; } reschedule_t203(pri); @@ -108,11 +108,11 @@ static void q921_send_ua(struct pri *pri, int pfbit) h.h.c_r = 1; break; default: - pri_error("Don't know how to U/A on a type %d node\n", pri->localtype); + pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype); return; } if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("Sending Unnumbered Acknowledgement\n"); + pri_message(pri, "Sending Unnumbered Acknowledgement\n"); q921_transmit(pri, &h, 3); } @@ -140,11 +140,11 @@ static void q921_send_sabme(void *vpri, int now) h.h.c_r = 0; break; default: - pri_error("Don't know how to U/A on a type %d node\n", pri->localtype); + pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype); return; } if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("Sending Set Asynchronous Balanced Mode Extended\n"); + pri_message(pri, "Sending Set Asynchronous Balanced Mode Extended\n"); q921_transmit(pri, &h, 3); pri->q921_state = Q921_AWAITING_ESTABLISH; } @@ -167,7 +167,7 @@ static int q921_ack_packet(struct pri *pri, int num) else pri->txqueue = f->next; if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- ACKing packet %d, new txqueue is %d (-1 means empty)\n", f->h.n_s, pri->txqueue ? pri->txqueue->h.n_s : -1); + pri_message(pri, "-- ACKing packet %d, new txqueue is %d (-1 means empty)\n", f->h.n_s, pri->txqueue ? pri->txqueue->h.n_s : -1); /* Update v_a */ pri->v_a = num; free(f); @@ -181,7 +181,7 @@ static int q921_ack_packet(struct pri *pri, int num) if (!f->transmitted) { /* Send it now... */ if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Finally transmitting %d, since window opened up\n", f->h.n_s); + pri_message(pri, "-- Finally transmitting %d, since window opened up\n", f->h.n_s); f->transmitted++; pri->windowlen++; f->h.n_r = pri->v_r; @@ -207,7 +207,7 @@ static void reschedule_t203(struct pri *pri) if (pri->t203_timer) { pri_schedule_del(pri, pri->t203_timer); if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Restarting T203 counter\n"); + pri_message(pri, "-- Restarting T203 counter\n"); /* Nothing to transmit, start the T203 counter instead */ pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri); } @@ -222,7 +222,7 @@ static pri_event *q921_ack_rx(struct pri *pri, int ack) for (x=pri->v_a; (x != pri->v_s) && (x != ack); Q921_INC(x)); if (x != ack) { /* ACK was outside of our window --- ignore */ - pri_error("ACK received for '%d' outside of window of '%d' to '%d', restarting\n", ack, pri->v_a, pri->v_s); + pri_error(pri, "ACK received for '%d' outside of window of '%d' to '%d', restarting\n", ack, pri->v_a, pri->v_s); ev = q921_dchannel_down(pri); q921_start(pri, 1); pri->schedev = 1; @@ -230,31 +230,31 @@ static pri_event *q921_ack_rx(struct pri *pri, int ack) } /* Cancel each packet as necessary */ if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- ACKing all packets from %d to (but not including) %d\n", pri->v_a, ack); + pri_message(pri, "-- ACKing all packets from %d to (but not including) %d\n", pri->v_a, ack); for (x=pri->v_a; x != ack; Q921_INC(x)) cnt += q921_ack_packet(pri, x); if (!pri->txqueue) { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Since there was nothing left, stopping T200 counter\n"); + pri_message(pri, "-- Since there was nothing left, stopping T200 counter\n"); /* Something was ACK'd. Stop T200 counter */ pri_schedule_del(pri, pri->t200_timer); pri->t200_timer = 0; } if (pri->t203_timer) { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Stopping T203 counter since we got an ACK\n"); + pri_message(pri, "-- Stopping T203 counter since we got an ACK\n"); pri_schedule_del(pri, pri->t203_timer); pri->t203_timer = 0; } if (pri->txqueue) { /* Something left to transmit, Start the T200 counter again if we stopped it */ if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Something left to transmit (%d), restarting T200 counter\n", pri->txqueue->h.n_s); + pri_message(pri, "-- Something left to transmit (%d), restarting T200 counter\n", pri->txqueue->h.n_s); if (!pri->t200_timer) pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri); } else { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Nothing left, starting T203 counter\n"); + pri_message(pri, "-- Nothing left, starting T203 counter\n"); /* Nothing to transmit, start the T203 counter instead */ pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri); } @@ -278,11 +278,11 @@ static void q921_reject(struct pri *pri, int pf) h.h.c_r = 1; break; default: - pri_error("Don't know how to U/A on a type %d node\n", pri->localtype); + pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype); return; } if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("Sending Reject (%d)\n", pri->v_r); + pri_message(pri, "Sending Reject (%d)\n", pri->v_r); pri->sentrej = 1; q921_transmit(pri, &h, 4); } @@ -309,12 +309,12 @@ static void q921_rr(struct pri *pri, int pbit, int cmd) { h.h.c_r = 1; break; default: - pri_error("Don't know how to U/A on a type %d node\n", pri->localtype); + pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype); return; } pri->v_na = pri->v_r; /* Make a note that we've already acked this */ if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("Sending Receiver Ready (%d)\n", pri->v_r); + pri_message(pri, "Sending Receiver Ready (%d)\n", pri->v_r); q921_transmit(pri, &h, 4); } @@ -324,7 +324,7 @@ static void t200_expire(void *vpri) if (pri->txqueue) { /* Retransmit first packet in the queue, setting the poll bit */ if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- T200 counter expired, What to do...\n"); + pri_message(pri, "-- T200 counter expired, What to do...\n"); /* Force Poll bit */ pri->txqueue->h.p_f = 1; /* Update nr */ @@ -336,20 +336,20 @@ static void t200_expire(void *vpri) if (pri->retrans < pri->timers[PRI_TIMER_N200]) { /* Reschedule t200_timer */ if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Retransmitting %d bytes\n", pri->txqueue->len); + pri_message(pri, "-- Retransmitting %d bytes\n", pri->txqueue->len); if (pri->busy) q921_rr(pri, 1, 0); else { if (!pri->txqueue->transmitted) - pri_error("!! Not good - head of queue has not been transmitted yet\n"); + pri_error(pri, "!! Not good - head of queue has not been transmitted yet\n"); q921_transmit(pri, (q921_h *)&pri->txqueue->h, pri->txqueue->len); } if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Rescheduling retransmission (%d)\n", pri->retrans); + pri_message(pri, "-- Rescheduling retransmission (%d)\n", pri->retrans); pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri); } else { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Timeout occured, restarting PRI\n"); + pri_message(pri, "-- Timeout occured, restarting PRI\n"); pri->q921_state = Q921_LINK_CONNECTION_RELEASED; pri->t200_timer = 0; q921_dchannel_down(pri); @@ -358,7 +358,7 @@ static void t200_expire(void *vpri) } } else if (pri->solicitfbit) { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Retrying poll with f-bit\n"); + pri_message(pri, "-- Retrying poll with f-bit\n"); pri->retrans++; if (pri->retrans < pri->timers[PRI_TIMER_N200]) { pri->solicitfbit = 1; @@ -366,7 +366,7 @@ static void t200_expire(void *vpri) pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri); } else { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Timeout occured, restarting PRI\n"); + pri_message(pri, "-- Timeout occured, restarting PRI\n"); pri->q921_state = Q921_LINK_CONNECTION_RELEASED; pri->t200_timer = 0; q921_dchannel_down(pri); @@ -374,7 +374,7 @@ static void t200_expire(void *vpri) pri->schedev = 1; } } else { - pri_error("T200 counter expired, nothing to send...\n"); + pri_error(pri, "T200 counter expired, nothing to send...\n"); pri->t200_timer = 0; } } @@ -424,26 +424,26 @@ int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr) f->transmitted++; } else { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("Delaying transmission of %d, window is %d/%d long\n", + pri_message(pri, "Delaying transmission of %d, window is %d/%d long\n", f->h.n_s, pri->windowlen, pri->window); } } if (pri->t203_timer) { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("Stopping T_203 timer\n"); + pri_message(pri, "Stopping T_203 timer\n"); pri_schedule_del(pri, pri->t203_timer); pri->t203_timer = 0; } if (!pri->t200_timer) { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("Starting T_200 timer\n"); + pri_message(pri, "Starting T_200 timer\n"); pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri); } else if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("T_200 timer already going (%d)\n", pri->t200_timer); + pri_message(pri, "T_200 timer already going (%d)\n", pri->t200_timer); } else { - pri_error("!! Out of memory for Q.921 transmit\n"); + pri_error(pri, "!! Out of memory for Q.921 transmit\n"); return -1; } return 0; @@ -454,7 +454,7 @@ static void t203_expire(void *vpri) struct pri *pri = vpri; if (pri->q921_state == Q921_LINK_CONNECTION_ESTABLISHED) { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("T203 counter expired, sending RR and scheduling T203 again\n"); + pri_message(pri, "T203 counter expired, sending RR and scheduling T203 again\n"); /* Solicit an F-bit in the other's RR */ pri->solicitfbit = 1; pri->retrans = 0; @@ -463,7 +463,7 @@ static void t203_expire(void *vpri) pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri); } else { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("T203 counter expired in weird state %d\n", pri->q921_state); + pri_message(pri, "T203 counter expired in weird state %d\n", pri->q921_state); pri->t203_timer = 0; } } @@ -508,7 +508,7 @@ static pri_event *q921_handle_iframe(struct pri *pri, q921_i *i, int len) return NULL; } -void q921_dump(q921_h *h, int len, int showraw, int txrx) +void q921_dump(struct pri *pri, q921_h *h, int len, int showraw, int txrx) { int x; char *type; @@ -521,7 +521,7 @@ void q921_dump(q921_h *h, int len, int showraw, int txrx) if (buf) { for (x=0;xraw[x]); - pri_message("\n%c [ %s]\n", direction_tag, buf); + pri_message(pri, "\n%c [ %s]\n", direction_tag, buf); free(buf); } } @@ -529,17 +529,17 @@ void q921_dump(q921_h *h, int len, int showraw, int txrx) switch (h->h.data[0] & Q921_FRAMETYPE_MASK) { case 0: case 2: - pri_message("\n%c Informational frame:\n", direction_tag); + pri_message(pri, "\n%c Informational frame:\n", direction_tag); break; case 1: - pri_message("\n%c Supervisory frame:\n", direction_tag); + pri_message(pri, "\n%c Supervisory frame:\n", direction_tag); break; case 3: - pri_message("\n%c Unnumbered frame:\n", direction_tag); + pri_message(pri, "\n%c Unnumbered frame:\n", direction_tag); break; } - pri_message( + pri_message(pri, "%c SAPI: %02d C/R: %d EA: %d\n" "%c TEI: %03d EA: %d\n", direction_tag, @@ -553,7 +553,7 @@ void q921_dump(q921_h *h, int len, int showraw, int txrx) case 0: case 2: /* Informational frame */ - pri_message( + pri_message(pri, "%c N(S): %03d 0: %d\n" "%c N(R): %03d P: %d\n" "%c %d bytes of data\n", @@ -580,7 +580,7 @@ void q921_dump(q921_h *h, int len, int showraw, int txrx) type = "REJ (reject)"; break; } - pri_message( + pri_message(pri, "%c Zero: %d S: %d 01: %d [ %s ]\n" "%c N(R): %03d P/F: %d\n" "%c %d bytes of data\n", @@ -626,7 +626,7 @@ void q921_dump(q921_h *h, int len, int showraw, int txrx) break; } } - pri_message( + pri_message(pri, "%c M3: %d P/F: %d M2: %d 11: %d [ %s ]\n" "%c %d bytes of data\n", direction_tag, @@ -709,23 +709,23 @@ static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len) case 0: case 2: if (pri->q921_state != Q921_LINK_CONNECTION_ESTABLISHED) { - pri_error("!! Got I-frame while link state %d\n", pri->q921_state); + pri_error(pri, "!! Got I-frame while link state %d\n", pri->q921_state); return NULL; } /* Informational frame */ if (len < 4) { - pri_error("!! Received short I-frame (expected 4, got %d)\n", len); + pri_error(pri, "!! Received short I-frame (expected 4, got %d)\n", len); break; } return q921_handle_iframe(pri, &h->i, len); break; case 1: if (pri->q921_state != Q921_LINK_CONNECTION_ESTABLISHED) { - pri_error("!! Got S-frame while link down\n"); + pri_error(pri, "!! Got S-frame while link down\n"); return NULL; } if (len < 4) { - pri_error("!! Received short S-frame (expected 4, got %d)\n", len); + pri_error(pri, "!! Received short S-frame (expected 4, got %d)\n", len); break; } switch(h->s.ss) { @@ -740,10 +740,10 @@ static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len) /* If it's a p/f one then send back a RR in return with the p/f bit set */ if (pri->solicitfbit) { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Got RR response to our frame\n"); + pri_message(pri, "-- Got RR response to our frame\n"); } else { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Unsolicited RR with P/F bit, responding\n"); + pri_message(pri, "-- Unsolicited RR with P/F bit, responding\n"); q921_rr(pri, 1, 0); } pri->solicitfbit = 0; @@ -752,7 +752,7 @@ static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len) case 1: /* Receiver not ready */ if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Got receiver not ready\n"); + pri_message(pri, "-- Got receiver not ready\n"); if(h->s.p_f) { /* Send RR if poll bit set */ q921_rr(pri, h->s.p_f, 0); @@ -762,7 +762,7 @@ static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len) case 2: /* Just retransmit */ if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Got reject requesting packet %d... Retransmitting.\n", h->s.n_r); + pri_message(pri, "-- Got reject requesting packet %d... Retransmitting.\n", h->s.n_r); if (h->s.p_f) { /* If it has the poll bit set, send an appropriate supervisory response */ q921_rr(pri, 1, 0); @@ -774,7 +774,7 @@ static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len) /* Matches the request, or follows in our window, and has already been transmitted. */ sendnow = 1; - pri_error("!! Got reject for frame %d, retransmitting frame %d now, updating n_r!\n", h->s.n_r, f->h.n_s); + pri_error(pri, "!! Got reject for frame %d, retransmitting frame %d now, updating n_r!\n", h->s.n_r, f->h.n_s); f->h.n_r = pri->v_r; q921_transmit(pri, (q921_h *)(&f->h), f->len); } @@ -783,11 +783,11 @@ static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len) if (pri->txqueue) { /* This should never happen */ if (!h->s.p_f || h->s.n_r) { - pri_error("!! Got reject for frame %d, but we only have others!\n", h->s.n_r); + pri_error(pri, "!! Got reject for frame %d, but we only have others!\n", h->s.n_r); } } else { /* Hrm, we have nothing to send, but have been REJ'd. Reset v_a, v_s, etc */ - pri_error("!! Got reject for frame %d, but we have nothing -- resetting!\n", h->s.n_r); + pri_error(pri, "!! Got reject for frame %d, but we have nothing -- resetting!\n", h->s.n_r); pri->v_a = h->s.n_r; pri->v_s = h->s.n_r; /* Reset t200 timer if it was somehow going */ @@ -803,13 +803,13 @@ static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len) } break; default: - pri_error("!! XXX Unknown Supervisory frame ss=0x%02x,pf=%02xnr=%02x vs=%02x, va=%02x XXX\n", h->s.ss, h->s.p_f, h->s.n_r, + pri_error(pri, "!! XXX Unknown Supervisory frame ss=0x%02x,pf=%02xnr=%02x vs=%02x, va=%02x XXX\n", h->s.ss, h->s.p_f, h->s.n_r, pri->v_s, pri->v_a); } break; case 3: if (len < 3) { - pri_error("!! Received short unnumbered frame\n"); + pri_error(pri, "!! Received short unnumbered frame\n"); break; } switch(h->u.m3) { @@ -819,7 +819,7 @@ static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len) /* Section 5.7.1 says we should restart on receiving a DM response with the f-bit set to one, but we wait T200 first */ if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Got DM Mode from peer.\n"); + pri_message(pri, "-- Got DM Mode from peer.\n"); /* Disconnected mode, try again after T200 */ ev = q921_dchannel_down(pri); q921_start(pri, 0); @@ -827,7 +827,7 @@ static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len) } else { if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Ignoring unsolicited DM with p/f set to 0\n"); + pri_message(pri, "-- Ignoring unsolicited DM with p/f set to 0\n"); #if 0 /* Requesting that we start */ q921_start(pri, 0); @@ -835,12 +835,12 @@ static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len) } break; } else if (!h->u.m2) { - pri_message("XXX Unnumbered Information not implemented XXX\n"); + pri_message(pri, "XXX Unnumbered Information not implemented XXX\n"); } break; case 2: if (pri->debug & PRI_DEBUG_Q921_STATE) - pri_message("-- Got Disconnect from peer.\n"); + pri_message(pri, "-- Got Disconnect from peer.\n"); /* Acknowledge */ q921_send_ua(pri, h->u.p_f); ev = q921_dchannel_down(pri); @@ -850,7 +850,7 @@ static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len) if (h->u.m2 == 3) { /* SABME */ if (pri->debug & PRI_DEBUG_Q921_STATE) { - pri_message("-- Got SABME from %s peer.\n", h->h.c_r ? "network" : "cpe"); + pri_message(pri, "-- Got SABME from %s peer.\n", h->h.c_r ? "network" : "cpe"); } if (h->h.c_r) { pri->remotetype = PRI_NETWORK; @@ -872,22 +872,22 @@ static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len) /* It's a UA */ if (pri->q921_state == Q921_AWAITING_ESTABLISH) { if (pri->debug & PRI_DEBUG_Q921_STATE) { - pri_message("-- Got UA from %s peer Link up.\n", h->h.c_r ? "cpe" : "network"); + pri_message(pri, "-- Got UA from %s peer Link up.\n", h->h.c_r ? "cpe" : "network"); } return q921_dchannel_up(pri); } else - pri_error("!! Got a UA, but i'm in state %d\n", pri->q921_state); + pri_error(pri, "!! Got a UA, but i'm in state %d\n", pri->q921_state); } else - pri_error("!! Weird frame received (m3=3, m2 = %d)\n", h->u.m2); + pri_error(pri, "!! Weird frame received (m3=3, m2 = %d)\n", h->u.m2); break; case 4: - pri_error("!! Frame got rejected!\n"); + pri_error(pri, "!! Frame got rejected!\n"); break; case 5: - pri_error("!! XID frames not supported\n"); + pri_error(pri, "!! XID frames not supported\n"); break; default: - pri_error("!! Don't know what to do with M3=%d u-frames\n", h->u.m3); + pri_error(pri, "!! Don't know what to do with M3=%d u-frames\n", h->u.m3); } break; @@ -902,7 +902,7 @@ static pri_event *__q921_receive(struct pri *pri, q921_h *h, int len) len -= 2; if (!pri->master && pri->debug & PRI_DEBUG_Q921_DUMP) - q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 0); + q921_dump(pri, h, len, pri->debug & PRI_DEBUG_Q921_RAW, 0); /* Check some reject conditions -- Start by rejecting improper ea's */ if (h->h.ea1 || !(h->h.ea2)) @@ -941,7 +941,7 @@ pri_event *q921_receive(struct pri *pri, q921_h *h, int len) void q921_start(struct pri *pri, int now) { if (pri->q921_state != Q921_LINK_CONNECTION_RELEASED) { - pri_error("!! q921_start: Not in 'Link Connection Released' state\n"); + pri_error(pri, "!! q921_start: Not in 'Link Connection Released' state\n"); return; } /* Reset our interface */ diff --git a/q931.c b/q931.c index ba2e916..7e14be3 100755 --- a/q931.c +++ b/q931.c @@ -209,7 +209,7 @@ static char *ie2str(int ie); static char *msg2str(int msg); -#define FUNC_DUMP(name) void ((name))(int full_ie, q931_ie *ie, int len, char prefix) +#define FUNC_DUMP(name) void ((name))(int full_ie, struct pri *pri, q931_ie *ie, int len, char prefix) #define FUNC_RECV(name) int ((name))(int full_ie, struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len) #define FUNC_SEND(name) int ((name))(int full_ie, struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len, int order) @@ -273,7 +273,7 @@ static FUNC_RECV(receive_channel_id) int pos=0; #ifdef NO_BRI_SUPPORT if (!ie->data[0] & 0x20) { - pri_error("!! Not PRI type!?\n"); + pri_error(pri, "!! Not PRI type!?\n"); return -1; } #endif @@ -285,7 +285,7 @@ static FUNC_RECV(receive_channel_id) case 1: break; default: - pri_error("!! Unexpected Channel selection %d\n", ie->data[0] & 3); + pri_error(pri, "!! Unexpected Channel selection %d\n", ie->data[0] & 3); return -1; } #endif @@ -305,11 +305,11 @@ static FUNC_RECV(receive_channel_id) if (pos+2 < len) { /* More coming */ if ((ie->data[pos] & 0x0f) != 3) { - pri_error("!! Unexpected Channel Type %d\n", ie->data[1] & 0x0f); + pri_error(pri, "!! Unexpected Channel Type %d\n", ie->data[1] & 0x0f); return -1; } if ((ie->data[pos] & 0x60) != 0) { - pri_error("!! Invalid CCITT coding %d\n", (ie->data[1] & 0x60) >> 5); + pri_error(pri, "!! Invalid CCITT coding %d\n", (ie->data[1] & 0x60) >> 5); return -1; } if (ie->data[pos] & 0x10) { @@ -388,7 +388,7 @@ static FUNC_SEND(transmit_channel_id) /* We're done */ return pos + 2; } - pri_error("!! No channel map, no channel, and no ds1? What am I supposed to identify?\n"); + pri_error(pri, "!! No channel map, no channel, and no ds1? What am I supposed to identify?\n"); return -1; } @@ -402,30 +402,30 @@ static FUNC_DUMP(dump_channel_id) "No channel selected", "As indicated in following octets", "Reserved","Any channel selected" }; - pri_message("%c Channel ID (len=%2d) [ Ext: %d IntID: %s, %s Spare: %d, %s Dchan: %d\n", + pri_message(pri, "%c Channel ID (len=%2d) [ Ext: %d IntID: %s, %s Spare: %d, %s Dchan: %d\n", prefix, len, (ie->data[0] & 0x80) ? 1 : 0, (ie->data[0] & 0x40) ? "Explicit" : "Implicit", (ie->data[0] & 0x20) ? "PRI" : "Other", (ie->data[0] & 0x10) ? 1 : 0, (ie->data[0] & 0x08) ? "Exclusive" : "Preferred", (ie->data[0] & 0x04) ? 1 : 0); - pri_message("%c ChanSel: %s\n", + pri_message(pri, "%c ChanSel: %s\n", prefix, msg_chan_sel[(ie->data[0] & 0x3) + ((ie->data[0]>>3) & 0x4)]); pos++; len--; if (ie->data[0] & 0x40) { /* Explicitly defined DS1 */ - pri_message("%c Ext: %d DS1 Identifier: %d \n", prefix, (ie->data[pos] & 0x80) >> 7, ie->data[pos] & 0x7f); + pri_message(pri, "%c Ext: %d DS1 Identifier: %d \n", prefix, (ie->data[pos] & 0x80) >> 7, ie->data[pos] & 0x7f); pos++; } else { /* Implicitly defined DS1 */ } if (pos+2 < len) { /* Still more information here */ - pri_message("%c Ext: %d Coding: %d %s Specified Channel Type: %d\n", + pri_message(pri, "%c Ext: %d Coding: %d %s Specified Channel Type: %d\n", prefix, (ie->data[pos] & 0x80) >> 7, (ie->data[pos] & 60) >> 5, (ie->data[pos] & 0x10) ? "Slot Map" : "Number", ie->data[pos] & 0x0f); if (!(ie->data[pos] & 0x10)) { /* Number specified */ pos++; - pri_message("%c Ext: %d Channel: %d ]\n", prefix, (ie->data[pos] & 0x80) >> 7, + pri_message(pri, "%c Ext: %d Channel: %d ]\n", prefix, (ie->data[pos] & 0x80) >> 7, (ie->data[pos]) & 0x7f); } else { pos++; @@ -434,9 +434,9 @@ static FUNC_DUMP(dump_channel_id) res <<= 8; res |= ie->data[pos++]; } - pri_message("%c Map: %s ]\n", prefix, binary(res, 24)); + pri_message(pri, "%c Map: %s ]\n", prefix, binary(res, 24)); } - } else pri_message(" ]\n"); + } else pri_message(pri, " ]\n"); } static char *ri2str(int ri) @@ -451,7 +451,7 @@ static char *ri2str(int ri) static FUNC_DUMP(dump_restart_indicator) { - pri_message("%c Restart Indentifier (len=%2d) [ Ext: %d Spare: %d Resetting %s (%d) ]\n", + pri_message(pri, "%c Restart Indentifier (len=%2d) [ Ext: %d Spare: %d Resetting %s (%d) ]\n", prefix, len, (ie->data[0] & 0x80) >> 7, (ie->data[0] & 0x78) >> 3, ri2str(ie->data[0] & 0x7), ie->data[0] & 0x7); } @@ -476,7 +476,7 @@ static FUNC_SEND(transmit_restart_indicator) ie->data[0] = 0xA0 | (call->ri & 0x7); break; default: - pri_error("!! Invalid restart indicator value %d\n", call->ri); + pri_error(pri, "!! Invalid restart indicator value %d\n", call->ri); return-1; } return 3; @@ -567,11 +567,11 @@ static char *l32str(int proto) static FUNC_DUMP(dump_bearer_capability) { int pos=2; - pri_message("%c Bearer Capability (len=%2d) [ Ext: %d Q.931 Std: %d Info transfer capability: %s (%d)\n", + pri_message(pri, "%c Bearer Capability (len=%2d) [ Ext: %d Q.931 Std: %d Info transfer capability: %s (%d)\n", prefix, len, (ie->data[0] & 0x80 ) >> 7, (ie->data[0] & 0x60) >> 5, cap2str(ie->data[0] & 0x1f), (ie->data[0] & 0x1f)); - pri_message("%c Ext: %d Trans mode/rate: %s (%d)\n", prefix, (ie->data[1] & 0x80) >> 7, mode2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f); + pri_message(pri, "%c Ext: %d Trans mode/rate: %s (%d)\n", prefix, (ie->data[1] & 0x80) >> 7, mode2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f); if ((ie->data[1] & 0x7f) == 0x18) { - pri_message("%c Ext: %d Transfer rate multiplier: %d x 64\n", prefix, (ie->data[2] & 0x80) >> 7, ie->data[2] & 0x7f); + pri_message(pri, "%c Ext: %d Transfer rate multiplier: %d x 64\n", prefix, (ie->data[2] & 0x80) >> 7, ie->data[2] & 0x7f); pos++; } /* Stop here if no more */ @@ -579,15 +579,15 @@ static FUNC_DUMP(dump_bearer_capability) return; if ((ie->data[1] & 0x7f) != TRANS_MODE_PACKET) { /* Look for octets 5 and 5.a if present */ - pri_message("%c Ext: %d User information layer 1: %s (%d)\n", prefix, (ie->data[pos] >> 7), l12str(ie->data[pos] & 0x7f), ie->data[pos] & 0x7f); + pri_message(pri, "%c Ext: %d User information layer 1: %s (%d)\n", prefix, (ie->data[pos] >> 7), l12str(ie->data[pos] & 0x7f), ie->data[pos] & 0x7f); if ((ie->data[pos] & 0x7f) == PRI_LAYER_1_ITU_RATE_ADAPT) - pri_message("%c Ext: %d Rate adaptatation: %s (%d)\n", prefix, ie->data[pos] >> 7, ra2str(ie->data[pos] & 0x7f), ie->data[pos] & 0x7f); + pri_message(pri, "%c Ext: %d Rate adaptatation: %s (%d)\n", prefix, ie->data[pos] >> 7, ra2str(ie->data[pos] & 0x7f), ie->data[pos] & 0x7f); pos++; } else { /* Look for octets 6 and 7 but not 5 and 5.a */ - pri_message("%c Ext: %d User information layer 2: %s (%d)\n", prefix, ie->data[pos] >> 7, l22str(ie->data[pos] & 0x7f), ie->data[pos] & 0x7f); + pri_message(pri, "%c Ext: %d User information layer 2: %s (%d)\n", prefix, ie->data[pos] >> 7, l22str(ie->data[pos] & 0x7f), ie->data[pos] & 0x7f); pos++; - pri_message("%c Ext: %d User information layer 3: %s (%d)\n", prefix, ie->data[pos] >> 7, l32str(ie->data[pos] & 0x7f), ie->data[pos] & 0x7f); + pri_message(pri, "%c Ext: %d User information layer 3: %s (%d)\n", prefix, ie->data[pos] >> 7, l32str(ie->data[pos] & 0x7f), ie->data[pos] & 0x7f); pos++; } } @@ -596,7 +596,7 @@ static FUNC_RECV(receive_bearer_capability) { int pos=2; if (ie->data[0] & 0x60) { - pri_error("!! non-standard Q.931 standard field\n"); + pri_error(pri, "!! non-standard Q.931 standard field\n"); return -1; } call->transcapability = ie->data[0] & 0x1f; @@ -748,7 +748,7 @@ static FUNC_DUMP(dump_called_party_number) unsigned char cnum[256]; q931_get_number(cnum, sizeof(cnum), ie->data + 1, len - 3); - pri_message("%c Called Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d) '%s' ]\n", + pri_message(pri, "%c Called Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d) '%s' ]\n", prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f, cnum); } @@ -756,7 +756,7 @@ static FUNC_DUMP(dump_called_party_subaddr) { unsigned char cnum[256]; q931_get_number(cnum, sizeof(cnum), ie->data + 1, len - 3); - pri_message("%c Called Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n", + pri_message(pri, "%c Called Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n", prefix, len, ie->data[0] >> 7, subaddrtype2str((ie->data[0] & 0x70) >> 4), (ie->data[0] & 0x70) >> 4, (ie->data[0] & 0x08) >> 3, cnum); @@ -769,18 +769,18 @@ static FUNC_DUMP(dump_calling_party_number) q931_get_number(cnum, sizeof(cnum), ie->data + 1, len - 3); else q931_get_number(cnum, sizeof(cnum), ie->data + 2, len - 4); - pri_message("%c Calling Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d)\n", prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f); + pri_message(pri, "%c Calling Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d)\n", prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f); if (ie->data[0] & 0x80) - pri_message("%c Presentation: %s (%d) '%s' ]\n", prefix, pri_pres2str(0), 0, cnum); + pri_message(pri, "%c Presentation: %s (%d) '%s' ]\n", prefix, pri_pres2str(0), 0, cnum); else - pri_message("%c Presentation: %s (%d) '%s' ]\n", prefix, pri_pres2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f, cnum); + pri_message(pri, "%c Presentation: %s (%d) '%s' ]\n", prefix, pri_pres2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f, cnum); } static FUNC_DUMP(dump_calling_party_subaddr) { unsigned char cnum[256]; q931_get_number(cnum, sizeof(cnum), ie->data + 2, len - 4); - pri_message("%c Calling Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n", + pri_message(pri, "%c Calling Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n", prefix, len, ie->data[0] >> 7, subaddrtype2str((ie->data[0] & 0x70) >> 4), (ie->data[0] & 0x70) >> 4, (ie->data[0] & 0x08) >> 3, cnum); @@ -795,22 +795,22 @@ static FUNC_DUMP(dump_redirecting_number) do { switch(i) { case 0: /* Octet 3 */ - pri_message("%c Redirecting Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d)", + pri_message(pri, "%c Redirecting Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d)", prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f); break; case 1: /* Octet 3a */ - pri_message("\n%c Ext: %d Presentation: %s (%d)", + pri_message(pri, "\n%c Ext: %d Presentation: %s (%d)", prefix, ie->data[1] >> 7, pri_pres2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f); break; case 2: /* Octet 3b */ - pri_message("\n%c Ext: %d Reason: %s (%d)", + pri_message(pri, "\n%c Ext: %d Reason: %s (%d)", prefix, ie->data[2] >> 7, redirection_reason2str(ie->data[2] & 0x7f), ie->data[2] & 0x7f); break; } } while(!(ie->data[i++]& 0x80)); q931_get_number(cnum, sizeof(cnum), ie->data + i, ie->len - i); - pri_message(" '%s' ]\n", cnum); + pri_message(pri, " '%s' ]\n", cnum); } static FUNC_DUMP(dump_connected_number) @@ -822,18 +822,18 @@ static FUNC_DUMP(dump_connected_number) do { switch(i) { case 0: /* Octet 3 */ - pri_message("%c Connected Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d)", + pri_message(pri, "%c Connected Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d)", prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f); break; case 1: /* Octet 3a */ - pri_message("\n%c Ext: %d Presentation: %s (%d)", + pri_message(pri, "\n%c Ext: %d Presentation: %s (%d)", prefix, ie->data[1] >> 7, pri_pres2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f); break; } } while(!(ie->data[i++]& 0x80)); q931_get_number(cnum, sizeof(cnum), ie->data + i, ie->len - i); - pri_message(" '%s' ]\n", cnum); + pri_message(pri, " '%s' ]\n", cnum); } @@ -879,7 +879,7 @@ static FUNC_DUMP(dump_redirecting_subaddr) { unsigned char cnum[256]; q931_get_number(cnum, sizeof(cnum), ie->data + 2, len - 4); - pri_message("%c Redirecting Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n", + pri_message(pri, "%c Redirecting Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n", prefix, len, ie->data[0] >> 7, subaddrtype2str((ie->data[0] & 0x70) >> 4), (ie->data[0] & 0x70) >> 4, (ie->data[0] & 0x08) >> 3, cnum); @@ -944,10 +944,10 @@ static FUNC_SEND(transmit_calling_party_number) static FUNC_DUMP(dump_user_user) { int x; - pri_message("%c User-User Information (len=%2d) [", prefix, len); + pri_message(pri, "%c User-User Information (len=%2d) [", prefix, len); for (x=0;xlen;x++) - pri_message(" %02x", ie->data[x] & 0x7f); - pri_message(" ]\n"); + pri_message(pri, " %02x", ie->data[x] & 0x7f); + pri_message(pri, " ]\n"); } @@ -1003,10 +1003,10 @@ static char *loc2str(int loc) static FUNC_DUMP(dump_progress_indicator) { - pri_message("%c Progress Indicator (len=%2d) [ Ext: %d Coding: %s (%d) 0: %d Location: %s (%d)\n", + pri_message(pri, "%c Progress Indicator (len=%2d) [ Ext: %d Coding: %s (%d) 0: %d Location: %s (%d)\n", prefix, len, ie->data[0] >> 7, coding2str((ie->data[0] & 0x60) >> 5), (ie->data[0] & 0x60) >> 5, (ie->data[0] & 0x10) >> 4, loc2str(ie->data[0] & 0xf), ie->data[0] & 0xf); - pri_message("%c Ext: %d Progress Description: %s (%d) ]\n", + pri_message(pri, "%c Ext: %d Progress Description: %s (%d) ]\n", prefix, ie->data[1] >> 7, prog2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f); } @@ -1074,7 +1074,7 @@ static FUNC_RECV(receive_progress_indicator) call->progressmask |= PRI_PROG_INTERWORKING_NO_RELEASE_POST_ANSWER; break; default: - pri_error("XXX Invalid Progress indicator value received: %02x\n",(ie->data[1] & 0x7f)); + pri_error(pri, "XXX Invalid Progress indicator value received: %02x\n",(ie->data[1] & 0x7f)); break; } return 0; @@ -1094,7 +1094,7 @@ static FUNC_SEND(transmit_facility) return 0; if (tmp->apdu_len > 235) { /* TODO: find out how much sapce we can use */ - pri_message("Requested ADPU (%d bytes) is too long\n", tmp->apdu_len); + pri_message(pri, "Requested ADPU (%d bytes) is too long\n", tmp->apdu_len); return 0; @@ -1217,7 +1217,7 @@ static FUNC_SEND(transmit_facility) ASN1_ADD_SIMPLE(comp, 0x81, ie->data, i); break; default: - pri_message("!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres); + pri_message(pri, "!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres); case PRES_NUMBER_NOT_AVAILABLE: ASN1_ADD_SIMPLE(comp, 0x82, ie->data, i); break; @@ -1265,7 +1265,7 @@ static FUNC_SEND(transmit_facility) ASN1_ADD_SIMPLE(comp, 0x81, ie->data, i); break; default: - pri_message("!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres); + pri_message(pri, "!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres); case PRES_NUMBER_NOT_AVAILABLE: ASN1_ADD_SIMPLE(comp, 0x82, ie->data, i); break; @@ -1296,37 +1296,37 @@ static FUNC_RECV(receive_facility) #define Q932_HANDLE_PROC(component, my_state, name, handler) \ case component: \ if(state > my_state) { \ - pri_error("!! %s component received in wrong place\n"); \ + pri_error(pri, "!! %s component received in wrong place\n"); \ break; \ } \ state = my_state; \ if (pri->debug) \ - pri_message("Handle Q.932 %s component\n", name); \ + pri_message(pri, "Handle Q.932 %s component\n", name); \ (handler)(pri, call, comp->data, comp->len); \ break; #define Q932_HANDLE_NULL(component, my_state, name, handle) \ case component: \ if(state > my_state) { \ - pri_error("!! %s component received in wrong place\n"); \ + pri_error(pri, "!! %s component received in wrong place\n"); \ break; \ } \ state = my_state; \ if (pri->debug & PRI_DEBUG_APDU) \ - pri_message("Q.932 %s component is not handled\n", name); \ + pri_message(pri, "Q.932 %s component is not handled\n", name); \ break; if (ie->len < 1) return -1; if ((ie->data[i] & 0xe0) != 0x80) { - pri_error ("!! Invalid Protocol Profile field 0x%X\n", ie->data[i]); + pri_error(pri, "!! Invalid Protocol Profile field 0x%X\n", ie->data[i]); return -1; } switch(next_protocol = protocol = (ie->data[i] & 0x1f)) { case Q932_PROTOCOL_CMIP: case Q932_PROTOCOL_ACSE: if (pri->debug & PRI_DEBUG_APDU) - pri_message("!! Don't know how to handle Q.932 Protocol Profile of type 0x%X\n", protocol); + pri_message(pri, "!! Don't know how to handle Q.932 Protocol Profile of type 0x%X\n", protocol); return -1; case Q932_PROTOCOL_EXTENSIONS: state = Q932_STATE_NFE; @@ -1335,7 +1335,7 @@ static FUNC_RECV(receive_facility) case Q932_PROTOCOL_ROSE: break; default: - pri_error("!! Invalid Q.932 Protocol Profile of type 0x%X received\n", protocol); + pri_error(pri, "!! Invalid Q.932 Protocol Profile of type 0x%X received\n", protocol); return -1; } i++; @@ -1365,7 +1365,7 @@ static FUNC_RECV(receive_facility) Q932_HANDLE_NULL(COMP_TYPE_REJECT, Q932_STATE_SERVICE, "ROSE reject", NULL); default: if (pri->debug & PRI_DEBUG_APDU) - pri_message("Don't know how to handle ROSE component of type 0x%X\n", comp->type); + pri_message(pri, "Don't know how to handle ROSE component of type 0x%X\n", comp->type); break; } break; @@ -1373,7 +1373,7 @@ static FUNC_RECV(receive_facility) switch (comp->type) { default: if (pri->debug & PRI_DEBUG_APDU) - pri_message("Don't know how to handle CMIP component of type 0x%X\n", comp->type); + pri_message(pri, "Don't know how to handle CMIP component of type 0x%X\n", comp->type); break; } break; @@ -1381,7 +1381,7 @@ static FUNC_RECV(receive_facility) switch (comp->type) { default: if (pri->debug & PRI_DEBUG_APDU) - pri_message("Don't know how to handle ACSE component of type 0x%X\n", comp->type); + pri_message(pri, "Don't know how to handle ACSE component of type 0x%X\n", comp->type); break; } break; @@ -1421,7 +1421,7 @@ static FUNC_SEND(transmit_progress_indicator) code = Q931_PROG_INTERWORKING_NO_RELEASE_POST_ANSWER; else { code = 0; - pri_error("XXX Undefined progress bit: %x\n", call->progressmask); + pri_error(pri, "XXX Undefined progress bit: %x\n", call->progressmask); } if (code) { ie->data[0] = 0x80 | (call->progcode << 5) | (call->progloc); @@ -1476,7 +1476,7 @@ static char *callstate2str(int callstate) static FUNC_DUMP(dump_call_state) { - pri_message("%c Call State (len=%2d) [ Ext: %d Coding: %s (%d) Call state: %s (%d)\n", + pri_message(pri, "%c Call State (len=%2d) [ Ext: %d Coding: %s (%d) Call state: %s (%d)\n", prefix, len, ie->data[0] >> 7, coding2str((ie->data[0] & 0xC0) >> 6), (ie->data[0] & 0xC0) >> 6, callstate2str(ie->data[0] & 0x3f), ie->data[0] & 0x3f); } @@ -1484,28 +1484,28 @@ static FUNC_DUMP(dump_call_state) static FUNC_DUMP(dump_call_identity) { int x; - pri_message("%c Call Identity (len=%2d) [ ", prefix, len); + pri_message(pri, "%c Call Identity (len=%2d) [ ", prefix, len); for (x=0;xlen;x++) - pri_message("0x%02X ", ie->data[x]); - pri_message(" ]\n"); + pri_message(pri, "0x%02X ", ie->data[x]); + pri_message(pri, " ]\n"); } static FUNC_DUMP(dump_time_date) { - pri_message("%c Time Date (len=%2d) [ ", prefix, len); + pri_message(pri, "%c Time Date (len=%2d) [ ", prefix, len); if (ie->len > 0) - pri_message("%02d", ie->data[0]); + pri_message(pri, "%02d", ie->data[0]); if (ie->len > 1) - pri_message("-%02d", ie->data[1]); + pri_message(pri, "-%02d", ie->data[1]); if (ie->len > 2) - pri_message("-%02d", ie->data[2]); + pri_message(pri, "-%02d", ie->data[2]); if (ie->len > 3) - pri_message(" %02d", ie->data[3]); + pri_message(pri, " %02d", ie->data[3]); if (ie->len > 4) - pri_message(":%02d", ie->data[4]); + pri_message(pri, ":%02d", ie->data[4]); if (ie->len > 5) - pri_message(":%02d", ie->data[5]); - pri_message(" ]\n"); + pri_message(pri, ":%02d", ie->data[5]); + pri_message(pri, " ]\n"); } static FUNC_DUMP(dump_keypad_facility) @@ -1516,7 +1516,7 @@ static FUNC_DUMP(dump_keypad_facility) return; strncpy(tmp, (char *) ie->data, sizeof(tmp)); - pri_message("%c Keypad Facility (len=%2d) [ %s ]\n", prefix, ie->len, tmp ); + pri_message(pri, "%c Keypad Facility (len=%2d) [ %s ]\n", prefix, ie->len, tmp ); } static FUNC_RECV(receive_keypad_facility) @@ -1553,12 +1553,12 @@ static FUNC_DUMP(dump_display) for (y=x; xlen; x++) buf[x] = ie->data[x] & 0x7f; buf[x] = '\0'; - pri_message("%c Display (len=%2d) %s[ %s ]\n", prefix, ie->len, tmp, &buf[y]); + pri_message(pri, "%c Display (len=%2d) %s[ %s ]\n", prefix, ie->len, tmp, &buf[y]); free(buf); } } -static void dump_ie_data(unsigned char *c, int len) +static void dump_ie_data(struct pri *pri, unsigned char *c, int len) { char tmp[1024] = ""; int x=0; @@ -1593,25 +1593,25 @@ static void dump_ie_data(unsigned char *c, int len) } if (lastascii) tmp[x++] = '\''; - pri_message(tmp); + pri_message(pri, tmp); } static FUNC_DUMP(dump_facility) { - pri_message("%c Facility (len=%2d, codeset=%d) [ ", prefix, len, Q931_IE_CODESET(full_ie)); - dump_ie_data(ie->data, ie->len); - pri_message(" ]\n"); + pri_message(pri, "%c Facility (len=%2d, codeset=%d) [ ", prefix, len, Q931_IE_CODESET(full_ie)); + dump_ie_data(pri, ie->data, ie->len); + pri_message(pri, " ]\n"); } static FUNC_DUMP(dump_network_spec_fac) { - pri_message("%c Network-Specific Facilities (len=%2d) [ ", prefix, ie->len); + pri_message(pri, "%c Network-Specific Facilities (len=%2d) [ ", prefix, ie->len); if (ie->data[0] == 0x00) { - pri_message (code2str(ie->data[1], facilities, sizeof(facilities) / sizeof(facilities[0]))); + pri_message(pri, code2str(ie->data[1], facilities, sizeof(facilities) / sizeof(facilities[0]))); } else - dump_ie_data(ie->data, ie->len); - pri_message(" ]\n"); + dump_ie_data(pri, ie->data, ie->len); + pri_message(pri, " ]\n"); } static FUNC_RECV(receive_network_spec_fac) @@ -1657,10 +1657,10 @@ static char *pri_causeclass2str(int cause) static FUNC_DUMP(dump_cause) { int x; - pri_message("%c Cause (len=%2d) [ Ext: %d Coding: %s (%d) 0: %d Location: %s (%d)\n", + pri_message(pri, "%c Cause (len=%2d) [ Ext: %d Coding: %s (%d) 0: %d Location: %s (%d)\n", prefix, len, ie->data[0] >> 7, coding2str((ie->data[0] & 0x60) >> 5), (ie->data[0] & 0x60) >> 5, (ie->data[0] & 0x10) >> 4, loc2str(ie->data[0] & 0xf), ie->data[0] & 0xf); - pri_message("%c Ext: %d Cause: %s (%d), class = %s (%d) ]\n", + pri_message(pri, "%c Ext: %d Cause: %s (%d), class = %s (%d) ]\n", prefix, (ie->data[1] >> 7), pri_cause2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f, pri_causeclass2str((ie->data[1] & 0x7f) >> 4), (ie->data[1] & 0x7f) >> 4); if (ie->len < 3) @@ -1669,24 +1669,24 @@ static FUNC_DUMP(dump_cause) switch(ie->data[1] & 0x7f) { case PRI_CAUSE_IE_NONEXIST: for (x=2;xlen;x++) - pri_message("%c Cause data %d: %02x (%d, %s IE)\n", prefix, x-1, ie->data[x], ie->data[x], ie2str(ie->data[x])); + pri_message(pri, "%c Cause data %d: %02x (%d, %s IE)\n", prefix, x-1, ie->data[x], ie->data[x], ie2str(ie->data[x])); break; case PRI_CAUSE_WRONG_CALL_STATE: for (x=2;xlen;x++) - pri_message("%c Cause data %d: %02x (%d, %s message)\n", prefix, x-1, ie->data[x], ie->data[x], msg2str(ie->data[x])); + pri_message(pri, "%c Cause data %d: %02x (%d, %s message)\n", prefix, x-1, ie->data[x], ie->data[x], msg2str(ie->data[x])); break; case PRI_CAUSE_RECOVERY_ON_TIMER_EXPIRE: - pri_message("%c Cause data:", prefix); + pri_message(pri, "%c Cause data:", prefix); for (x=2;xlen;x++) - pri_message(" %02x", ie->data[x]); - pri_message(" (Timer T"); + pri_message(pri, " %02x", ie->data[x]); + pri_message(pri, " (Timer T"); for (x=2;xlen;x++) - pri_message("%c", ((ie->data[x] >= ' ') && (ie->data[x] < 0x7f)) ? ie->data[x] : '.'); - pri_message(")\n"); + pri_message(pri, "%c", ((ie->data[x] >= ' ') && (ie->data[x] < 0x7f)) ? ie->data[x] : '.'); + pri_message(pri, ")\n"); break; default: for (x=2;xlen;x++) - pri_message("%c Cause data %d: %02x (%d)\n", prefix, x-1, ie->data[x], ie->data[x]); + pri_message(pri, "%c Cause data %d: %02x (%d)\n", prefix, x-1, ie->data[x], ie->data[x]); break; } } @@ -1717,7 +1717,7 @@ static FUNC_SEND(transmit_cause) static FUNC_DUMP(dump_sending_complete) { - pri_message("%c Sending Complete (len=%2d)\n", prefix, len); + pri_message(pri, "%c Sending Complete (len=%2d)\n", prefix, len); } static FUNC_RECV(receive_sending_complete) @@ -1770,7 +1770,7 @@ static char *notify2str(int info) static FUNC_DUMP(dump_notify) { - pri_message("%c Notification indicator (len=%2d): Ext: %d %s (%d)\n", prefix, len, ie->data[0] >> 7, notify2str(ie->data[0] & 0x7f), ie->data[0] & 0x7f); + pri_message(pri, "%c Notification indicator (len=%2d): Ext: %d %s (%d)\n", prefix, len, ie->data[0] >> 7, notify2str(ie->data[0] & 0x7f), ie->data[0] & 0x7f); } static FUNC_RECV(receive_notify) @@ -1790,7 +1790,7 @@ static FUNC_SEND(transmit_notify) static FUNC_DUMP(dump_shift) { - pri_message("%c %sLocking Shift (len=%02d): Requested codeset %d\n", prefix, (full_ie & 8) ? "Non-" : "", len, full_ie & 7); + pri_message(pri, "%c %sLocking Shift (len=%02d): Requested codeset %d\n", prefix, (full_ie & 8) ? "Non-" : "", len, full_ie & 7); } static char *lineinfo2str(int info) @@ -1827,7 +1827,7 @@ static char *lineinfo2str(int info) static FUNC_DUMP(dump_line_information) { - pri_message("%c Originating Line Information (len=%02d): %s (%d)\n", prefix, len, lineinfo2str(ie->data[0]), ie->data[0]); + pri_message(pri, "%c Originating Line Information (len=%02d): %s (%d)\n", prefix, len, lineinfo2str(ie->data[0]), ie->data[0]); } static FUNC_RECV(receive_line_information) @@ -1882,43 +1882,43 @@ static FUNC_DUMP(dump_generic_digits) int idx; int value; if (len < 3) { - pri_message("%c Generic Digits (len=%02d): Invalid length\n", prefix, len); + pri_message(pri, "%c Generic Digits (len=%02d): Invalid length\n", prefix, len); return; } encoding = (ie->data[0] >> 5) & 7; type = ie->data[0] & 0x1F; - pri_message("%c Generic Digits (len=%02d): Encoding %s Type %s\n", prefix, len, gdencoding2str(encoding), gdtype2str(type)); + pri_message(pri, "%c Generic Digits (len=%02d): Encoding %s Type %s\n", prefix, len, gdencoding2str(encoding), gdtype2str(type)); if (encoding == 3) { /* Binary */ - pri_message("%c Don't know how to handle binary encoding\n"); + pri_message(pri, "%c Don't know how to handle binary encoding\n"); return; } if (len == 3) /* No number information */ return; - pri_message("%c Digits: "); + pri_message(pri, "%c Digits: "); value = 0; for(idx = 3; idx < len; ++idx) { switch(encoding) { case 0: /* BCD even */ case 1: /* BCD odd */ - pri_message("%d", ie->data[idx-2] & 0x0f); + pri_message(pri, "%d", ie->data[idx-2] & 0x0f); value = value * 10 + (ie->data[idx-2] & 0x0f); if(!encoding || (idx+1 < len)) { /* Special handling for BCD odd */ - pri_message("%d", (ie->data[idx-2] >> 4) & 0x0f); + pri_message(pri, "%d", (ie->data[idx-2] >> 4) & 0x0f); value = value * 10 + ((ie->data[idx-2] >> 4) & 0x0f); } break; case 2: /* IA5 */ - pri_message("%c", ie->data[idx-2]); + pri_message(pri, "%c", ie->data[idx-2]); value = value * 10 + ie->data[idx-2] - '0'; break; } } switch(type) { case 4: /* Info Digits */ - pri_message(" - %s", lineinfo2str(value)); + pri_message(pri, " - %s", lineinfo2str(value)); break; } - pri_message("\n"); + pri_message(pri, "\n"); } static FUNC_RECV(receive_generic_digits) @@ -1931,13 +1931,13 @@ static FUNC_RECV(receive_generic_digits) char number[260]; if (len < 3) { - pri_error("Invalid length of Generic Digits IE\n"); + pri_error(pri, "Invalid length of Generic Digits IE\n"); return -1; } encoding = (ie->data[0] >> 5) & 7; type = ie->data[0] & 0x1F; if (encoding == 3) { /* Binary */ - pri_message("!! Unable to handle binary encoded Generic Digits IE\n"); + pri_message(pri, "!! Unable to handle binary encoded Generic Digits IE\n"); return 0; } if (len == 3) /* No number information */ @@ -2043,12 +2043,12 @@ static char *signal2str(int signal) static FUNC_DUMP(dump_signal) { - pri_message("%c Signal (len=%02d): ", prefix, len); + pri_message(pri, "%c Signal (len=%02d): ", prefix, len); if (len < 3) { - pri_message("Invalid length\n"); + pri_message(pri, "Invalid length\n"); return; } - pri_message("Signal %s (%d)\n", signal2str(ie->data[0]), ie->data[0]); + pri_message(pri, "Signal %s (%d)\n", signal2str(ie->data[0]), ie->data[0]); } @@ -2187,7 +2187,7 @@ static inline int q931_cr(q931_h *h) int cr = 0; int x; if (h->crlen > 3) { - pri_error("Call Reference Length Too long: %d\n", h->crlen); + pri_error(NULL, "Call Reference Length Too long: %d\n", h->crlen); return -1; } switch (h->crlen) { @@ -2205,25 +2205,25 @@ static inline int q931_cr(q931_h *h) } break; default: - pri_error("Call Reference Length not supported: %d\n", h->crlen); + pri_error(NULL, "Call Reference Length not supported: %d\n", h->crlen); } return cr; } -static inline void q931_dumpie(int codeset, q931_ie *ie, char prefix) +static inline void q931_dumpie(struct pri *pri, int codeset, q931_ie *ie, char prefix) { unsigned int x; int full_ie = Q931_FULL_IE(codeset, ie->ie); int base_ie; - pri_message("%c [", prefix); - pri_message("%02x", ie->ie); + pri_message(pri, "%c [", prefix); + pri_message(pri, "%02x", ie->ie); if (!(ie->ie & 0x80)) { - pri_message(" %02x", ielen(ie)-2); + pri_message(pri, " %02x", ielen(ie)-2); for (x = 0; x + 2 < ielen(ie); ++x) - pri_message(" %02x", ie->data[x]); + pri_message(pri, " %02x", ie->data[x]); } - pri_message("]\n"); + pri_message(pri, "]\n"); /* Special treatment for shifts */ if((full_ie & 0xf0) == Q931_LOCKING_SHIFT) @@ -2234,13 +2234,13 @@ static inline void q931_dumpie(int codeset, q931_ie *ie, char prefix) for (x=0;xdebug & PRI_DEBUG_Q931_STATE) - pri_message("-- Making new call for cr %d\n", cr); + pri_message(pri, "-- Making new call for cr %d\n", cr); cur = malloc(sizeof(struct q931_call)); if (cur) { call_init(cur); @@ -2301,7 +2301,7 @@ static void q931_destroy(struct pri *pri, int cr, q931_call *c) else *pri->callpool = cur->next; if (pri->debug & PRI_DEBUG_Q931_STATE) - pri_message("NEW_HANGUP DEBUG: Destroying the call, ourstate %s, peerstate %s\n",callstate2str(cur->ourcallstate),callstate2str(cur->peercallstate)); + pri_message(pri, "NEW_HANGUP DEBUG: Destroying the call, ourstate %s, peerstate %s\n",callstate2str(cur->ourcallstate),callstate2str(cur->peercallstate)); if (cur->retranstimer) pri_schedule_del(pri, cur->retranstimer); pri_call_apdu_queue_cleanup(cur); @@ -2311,7 +2311,7 @@ static void q931_destroy(struct pri *pri, int cr, q931_call *c) prev = cur; cur = cur->next; } - pri_error("Can't destroy call %d!\n", cr); + pri_error(pri, "Can't destroy call %d!\n", cr); } static void q931_destroycall(struct pri *pri, int cr) @@ -2374,12 +2374,12 @@ static int add_ie(struct pri *pri, q931_call *call, int msgtype, int ie, q931_ie } return total_res; } else { - pri_error("!! Don't know how to add an IE %s (%d)\n", ie2str(ie), ie); + pri_error(pri, "!! Don't know how to add an IE %s (%d)\n", ie2str(ie), ie); return -1; } } } - pri_error("!! Unknown IE %d (%s)\n", ie, ie2str(ie)); + pri_error(pri, "!! Unknown IE %d (%s)\n", ie, ie2str(ie)); return -1; } @@ -2394,7 +2394,7 @@ static char *disc2str(int disc) return code2str(disc, discs, sizeof(discs) / sizeof(discs[0])); } -void q931_dump(q931_h *h, int len, int txrx) +void q931_dump(struct pri *pri, q931_h *h, int len, int txrx) { q931_mh *mh; char c; @@ -2402,17 +2402,17 @@ void q931_dump(q931_h *h, int len, int txrx) int cur_codeset; int codeset; c = txrx ? '>' : '<'; - pri_message("%c Protocol Discriminator: %s (%d) len=%d\n", c, disc2str(h->pd), h->pd, len); - pri_message("%c Call Ref: len=%2d (reference %d/0x%X) (%s)\n", c, h->crlen, q931_cr(h) & 0x7FFF, q931_cr(h) & 0x7FFF, (h->crv[0] & 0x80) ? "Terminator" : "Originator"); + pri_message(pri, "%c Protocol Discriminator: %s (%d) len=%d\n", c, disc2str(h->pd), h->pd, len); + pri_message(pri, "%c Call Ref: len=%2d (reference %d/0x%X) (%s)\n", c, h->crlen, q931_cr(h) & 0x7FFF, q931_cr(h) & 0x7FFF, (h->crv[0] & 0x80) ? "Terminator" : "Originator"); /* Message header begins at the end of the call reference number */ mh = (q931_mh *)(h->contents + h->crlen); - pri_message("%c Message type: %s (%d)\n", c, msg2str(mh->msg), mh->msg); + pri_message(NULL, "%c Message type: %s (%d)\n", c, msg2str(mh->msg), mh->msg); /* Drop length of header, including call reference */ len -= (h->crlen + 3); codeset = cur_codeset = 0; while(x < len) { r = ielen((q931_ie *)(mh->data + x)); - q931_dumpie(cur_codeset, (q931_ie *)(mh->data + x), c); + q931_dumpie(pri, cur_codeset, (q931_ie *)(mh->data + x), c); switch (mh->data[x] & 0xf8) { case Q931_LOCKING_SHIFT: if ((mh->data[x] & 7) > 0) @@ -2428,7 +2428,7 @@ void q931_dump(q931_h *h, int len, int txrx) x += r; } if (x > len) - pri_error("XXX Message longer than it should be?? XXX\n"); + pri_error(pri, "XXX Message longer than it should be?? XXX\n"); } static int q931_handle_ie(int codeset, struct pri *pri, q931_call *c, int msg, q931_ie *ie) @@ -2436,19 +2436,19 @@ static int q931_handle_ie(int codeset, struct pri *pri, q931_call *c, int msg, q unsigned int x; int full_ie = Q931_FULL_IE(codeset, ie->ie); if (pri->debug & PRI_DEBUG_Q931_STATE) - pri_message("-- Processing IE %d (cs%d, %s)\n", ie->ie, codeset, ie2str(full_ie)); + pri_message(pri, "-- Processing IE %d (cs%d, %s)\n", ie->ie, codeset, ie2str(full_ie)); for (x=0;xdebug & PRI_DEBUG_Q931_ANOMALY) - pri_error("!! No handler for IE %d (cs%d, %s)\n", ie->ie, codeset, ie2str(full_ie)); + pri_error(pri, "!! No handler for IE %d (cs%d, %s)\n", ie->ie, codeset, ie2str(full_ie)); return -1; } } } - pri_message("!! Unknown IE %d (cs%d, %s)\n", ie->ie, codeset, ie2str(full_ie)); + pri_message(pri, "!! Unknown IE %d (cs%d, %s)\n", ie->ie, codeset, ie2str(full_ie)); return -1; } @@ -2486,7 +2486,7 @@ static int q931_xmit(struct pri *pri, q931_h *h, int len, int cr) message body after the transmit puts the sections of the message in the right order in the log */ if (pri->debug & PRI_DEBUG_Q931_DUMP) - q931_dump(h, len, 1); + q931_dump(pri, h, len, 1); #ifdef LIBPRI_COUNTERS pri->q931_txcount++; #endif @@ -2519,7 +2519,7 @@ static int send_message(struct pri *pri, q931_call *c, int msgtype, int ies[]) int tmpres; tmpres = add_ie(pri, c, mh->msg, ies[x], (q931_ie *)(mh->data + offset), len, &codeset); if (tmpres < 0) { - pri_error("!! Unable to add IE '%s'\n", ie2str(ies[x])); + pri_error(pri, "!! Unable to add IE '%s'\n", ie2str(ies[x])); return -1; } res += tmpres; @@ -2532,7 +2532,7 @@ static int send_message(struct pri *pri, q931_call *c, int msgtype, int ies[]) } if (res < 0) { - pri_error("!! Unable to add IE '%s'\n", ie2str(ies[x])); + pri_error(pri, "!! Unable to add IE '%s'\n", ie2str(ies[x])); return -1; } @@ -2566,7 +2566,7 @@ static int q931_status(struct pri *pri, q931_call *c, int cause) cur = cur->next; } if (!cur) { - pri_message("YYY Here we get reset YYY\n"); + pri_message(pri, "YYY Here we get reset YYY\n"); /* something went wrong, respond with "no such call" */ c->ourcallstate = Q931_CALL_STATE_NULL; c->peercallstate = Q931_CALL_STATE_NULL; @@ -2630,7 +2630,7 @@ int q931_call_progress(struct pri *pri, q931_call *c, int channel, int info) c->progressmask = PRI_PROG_INBAND_AVAILABLE; } else { /* PI is mandatory IE for PROGRESS message - Q.931 3.1.8 */ - pri_error("XXX Progress message requested but no information is provided\n"); + pri_error(pri, "XXX Progress message requested but no information is provided\n"); c->progressmask = 0; } c->alive = 1; @@ -2714,7 +2714,7 @@ static void pri_connect_timeout(void *data) struct q931_call *c = data; struct pri *pri = c->pri; if (pri->debug & PRI_DEBUG_Q931_STATE) - pri_message("Timed out looking for connect acknowledge\n"); + pri_message(pri, "Timed out looking for connect acknowledge\n"); q931_disconnect(pri, c, PRI_CAUSE_NORMAL_CLEARING); } @@ -2724,7 +2724,7 @@ static void pri_release_timeout(void *data) struct q931_call *c = data; struct pri *pri = c->pri; if (pri->debug & PRI_DEBUG_Q931_STATE) - pri_message("Timed out looking for release complete\n"); + pri_message(pri, "Timed out looking for release complete\n"); c->t308_timedout++; c->alive = 1; q931_release(pri, c, PRI_CAUSE_NORMAL_CLEARING); @@ -2736,7 +2736,7 @@ static void pri_release_finaltimeout(void *data) struct pri *pri = c->pri; c->alive = 1; if (pri->debug & PRI_DEBUG_Q931_STATE) - pri_message("Final time-out looking for release complete\n"); + pri_message(pri, "Final time-out looking for release complete\n"); c->t308_timedout++; c->ourcallstate = Q931_CALL_STATE_NULL; c->peercallstate = Q931_CALL_STATE_NULL; @@ -2754,7 +2754,7 @@ static void pri_disconnect_timeout(void *data) struct q931_call *c = data; struct pri *pri = c->pri; if (pri->debug & PRI_DEBUG_Q931_STATE) - pri_message("Timed out looking for release\n"); + pri_message(pri, "Timed out looking for release\n"); c->alive = 1; q931_release(pri, c, PRI_CAUSE_NORMAL_CLEARING); } @@ -2994,7 +2994,7 @@ int q931_hangup(struct pri *pri, q931_call *c, int cause) int disconnect = 1; int release_compl = 0; if (pri->debug & PRI_DEBUG_Q931_STATE) - pri_message("NEW_HANGUP DEBUG: Calling q931_hangup, ourstate %s, peerstate %s\n",callstate2str(c->ourcallstate),callstate2str(c->peercallstate)); + pri_message(pri, "NEW_HANGUP DEBUG: Calling q931_hangup, ourstate %s, peerstate %s\n",callstate2str(c->ourcallstate),callstate2str(c->peercallstate)); if (!pri || !c) return -1; /* If mandatory IE was missing, insist upon that cause code */ @@ -3047,7 +3047,7 @@ int q931_hangup(struct pri *pri, q931_call *c, int cause) else q931_release(pri,c,cause); } else - pri_error("Wierd, doing nothing but this shouldn't happen, ourstate %s, peerstate %s\n",callstate2str(c->ourcallstate),callstate2str(c->peercallstate)); + pri_error(pri, "Wierd, doing nothing but this shouldn't happen, ourstate %s, peerstate %s\n",callstate2str(c->ourcallstate),callstate2str(c->peercallstate)); break; case Q931_CALL_STATE_DISCONNECT_REQUEST: /* sent DISCONNECT */ @@ -3067,10 +3067,10 @@ int q931_hangup(struct pri *pri, q931_call *c, int cause) case Q931_CALL_STATE_RESTART: case Q931_CALL_STATE_RESTART_REQUEST: /* sent RESTART */ - pri_error("q931_hangup shouldn't be called in this state, ourstate %s, peerstate %s\n",callstate2str(c->ourcallstate),callstate2str(c->peercallstate)); + pri_error(pri, "q931_hangup shouldn't be called in this state, ourstate %s, peerstate %s\n",callstate2str(c->ourcallstate),callstate2str(c->peercallstate)); break; default: - pri_error("We're not yet handling hanging up when our state is %d, contact support@digium.com, ourstate %s, peerstate %s\n",callstate2str(c->ourcallstate),callstate2str(c->peercallstate)); + pri_error(pri, "We're not yet handling hanging up when our state is %d, contact support@digium.com, ourstate %s, peerstate %s\n",callstate2str(c->ourcallstate),callstate2str(c->peercallstate)); return -1; } /* we did handle hangup properly at this point */ @@ -3094,7 +3094,7 @@ int q931_receive(struct pri *pri, q931_h *h, int len) memset(last_ie, 0, sizeof(last_ie)); if (pri->debug & PRI_DEBUG_Q931_DUMP) - q931_dump(h, len, 0); + q931_dump(pri, h, len, 0); #ifdef LIBPRI_COUNTERS pri->q931_rxcount++; #endif @@ -3107,19 +3107,19 @@ int q931_receive(struct pri *pri, q931_h *h, int len) q931_xmit(pri, h, len, 1); return 0; } else if (h->pd != pri->protodisc) { - pri_error("Warning: unknown/inappropriate protocol discriminator received (%02x/%d)\n", h->pd, h->pd); + pri_error(pri, "Warning: unknown/inappropriate protocol discriminator received (%02x/%d)\n", h->pd, h->pd); return 0; } c = q931_getcall(pri, q931_cr(h)); if (!c) { - pri_error("Unable to locate call %d\n", q931_cr(h)); + pri_error(pri, "Unable to locate call %d\n", q931_cr(h)); return -1; } /* Preliminary handling */ switch(mh->msg) { case Q931_RESTART: if (pri->debug & PRI_DEBUG_Q931_STATE) - pri_message("-- Processing Q.931 Restart\n"); + pri_message(pri, "-- Processing Q.931 Restart\n"); /* Reset information */ c->channelno = -1; c->slotmap = -1; @@ -3132,7 +3132,7 @@ int q931_receive(struct pri *pri, q931_h *h, int len) break; case Q931_SETUP: if (pri->debug & PRI_DEBUG_Q931_STATE) - pri_message("-- Processing Q.931 Call Setup\n"); + pri_message(pri, "-- Processing Q.931 Call Setup\n"); c->channelno = -1; c->slotmap = -1; c->chanflags = 0; @@ -3225,10 +3225,10 @@ int q931_receive(struct pri *pri, q931_h *h, int len) case Q931_SUSPEND: case Q931_SUSPEND_ACKNOWLEDGE: case Q931_SUSPEND_REJECT: - pri_error("!! Not yet handling pre-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg); + pri_error(pri, "!! Not yet handling pre-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg); /* Fall through */ default: - pri_error("!! Don't know how to post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg); + pri_error(pri, "!! Don't know how to post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg); q931_status(pri,c, PRI_CAUSE_MESSAGE_TYPE_NONEXIST); if (c->newcall) q931_destroycall(pri,c->cr); @@ -3253,7 +3253,7 @@ int q931_receive(struct pri *pri, q931_h *h, int len) } r = ielen(ie); if (r > len) { - pri_error("XXX Message longer than it should be?? XXX\n"); + pri_error(pri, "XXX Message longer than it should be?? XXX\n"); return -1; } /* Special processing for codeset shifts */ @@ -3262,15 +3262,15 @@ int q931_receive(struct pri *pri, q931_h *h, int len) y = ie->ie & 7; /* Requested codeset */ /* Locking shifts couldn't go to lower codeset, and couldn't follows non-locking shifts - verify this */ if ((cur_codeset != codeset) && (pri->debug & PRI_DEBUG_Q931_ANOMALY)) - pri_message("XXX Locking shift immediately follows non-locking shift (from %d through %d to %d) XXX\n", codeset, cur_codeset, y); + pri_message(pri, "XXX Locking shift immediately follows non-locking shift (from %d through %d to %d) XXX\n", codeset, cur_codeset, y); if (y > 0) { if ((y < codeset) && (pri->debug & PRI_DEBUG_Q931_ANOMALY)) - pri_error("!! Trying to locked downshift codeset from %d to %d !!\n", codeset, y); + pri_error(pri, "!! Trying to locked downshift codeset from %d to %d !!\n", codeset, y); codeset = cur_codeset = y; } else { /* Locking shift to codeset 0 is forbidden by all specifications */ - pri_error("!! Invalid locking shift to codeset 0 !!\n"); + pri_error(pri, "!! Invalid locking shift to codeset 0 !!\n"); } break; case Q931_NON_LOCKING_SHIFT: @@ -3281,7 +3281,7 @@ int q931_receive(struct pri *pri, q931_h *h, int len) if (!(ie->ie & 0x80)) { if (last_ie[cur_codeset] > ie->ie) { if ((pri->debug & PRI_DEBUG_Q931_ANOMALY)) - pri_message("XXX Out-of-order IE %d at codeset %d (last was %d)\n", ie->ie, cur_codeset, last_ie[cur_codeset]); + pri_message(pri, "XXX Out-of-order IE %d at codeset %d (last was %d)\n", ie->ie, cur_codeset, last_ie[cur_codeset]); } else last_ie[cur_codeset] = ie->ie; @@ -3292,7 +3292,7 @@ int q931_receive(struct pri *pri, q931_h *h, int len) case PRI_SWITCH_ATT4ESS: if (cur_codeset != codeset) { if ((pri->debug & PRI_DEBUG_Q931_DUMP)) - pri_message("XXX Ignoring IE %d for temporary codeset %d XXX\n", ie->ie, cur_codeset); + pri_message(pri, "XXX Ignoring IE %d for temporary codeset %d XXX\n", ie->ie, cur_codeset); break; } /* Fall through */ @@ -3314,7 +3314,7 @@ int q931_receive(struct pri *pri, q931_h *h, int len) /* check if there is no channel identification when we're configured as network -> that's not an error */ if (((pri->localtype != PRI_NETWORK) || (mh->msg != Q931_SETUP) || (mandies[x] != Q931_CHANNEL_IDENT)) && ((mh->msg != Q931_PROGRESS) || (mandies[x] != Q931_PROGRESS_INDICATOR))) { - pri_error("XXX Missing handling for mandatory IE %d (cs%d, %s) XXX\n", Q931_IE_IE(mandies[x]), Q931_IE_CODESET(mandies[x]), ie2str(mandies[x])); + pri_error(pri, "XXX Missing handling for mandatory IE %d (cs%d, %s) XXX\n", Q931_IE_IE(mandies[x]), Q931_IE_CODESET(mandies[x]), ie2str(mandies[x])); missingmand++; } } @@ -3432,7 +3432,7 @@ int q931_receive(struct pri *pri, q931_h *h, int len) pri->ev.facname.cref = c->cr; pri->ev.facname.call = c; #if 0 - pri_message("Sending facility event (%s/%s)\n", pri->ev.facname.callingname, pri->ev.facname.callingnum); + pri_message(pri, "Sending facility event (%s/%s)\n", pri->ev.facname.callingname, pri->ev.facname.callingnum); #endif return Q931_RES_HAVEEVENT; case Q931_PROGRESS: @@ -3493,7 +3493,7 @@ int q931_receive(struct pri *pri, q931_h *h, int len) /* Also when the STATUS asks for the call of an unexisting reference send RELEASE_COMPL */ if ((pri->debug & PRI_DEBUG_Q931_ANOMALY) && (c->cause != PRI_CAUSE_INTERWORKING)) - pri_error("Received unsolicited status: %s\n", pri_cause2str(c->cause)); + pri_error(pri, "Received unsolicited status: %s\n", pri_cause2str(c->cause)); /* Workaround for S-12 ver 7.3 - it responds for invalid/non-implemented IEs at SETUP with null call state */ if (!c->sugcallstate && (c->ourcallstate != Q931_CALL_STATE_CALL_INITIATED)) { pri->ev.hangup.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16); @@ -3665,11 +3665,11 @@ int q931_receive(struct pri *pri, q931_h *h, int len) case Q931_SUSPEND: case Q931_SUSPEND_ACKNOWLEDGE: case Q931_SUSPEND_REJECT: - pri_error("!! Not yet handling post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg); + pri_error(pri, "!! Not yet handling post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg); /* Fall through */ default: - pri_error("!! Don't know how to post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg); + pri_error(pri, "!! Don't know how to post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg); q931_status(pri,c, PRI_CAUSE_MESSAGE_TYPE_NONEXIST); if (c->newcall) q931_destroycall(pri,c->cr);