[libpri-commits] rmudgett: branch 1.4 r1842 - /branches/1.4/q921.c
SVN commits to the libpri project
libpri-commits at lists.digium.com
Mon Aug 2 13:47:14 CDT 2010
Author: rmudgett
Date: Mon Aug 2 13:47:10 2010
New Revision: 1842
URL: http://svnview.digium.com/svn/libpri?view=rev&rev=1842
Log:
Renamed local struct pri *pri variables to struct pri *ctrl in q921.c.
The context tagging for my editor is much happier now that the struct and
the variable do not have the same name. (At least for this file.)
Modified:
branches/1.4/q921.c
Modified: branches/1.4/q921.c
URL: http://svnview.digium.com/svn/libpri/branches/1.4/q921.c?view=diff&rev=1842&r1=1841&r2=1842
==============================================================================
--- branches/1.4/q921.c (original)
+++ branches/1.4/q921.c Mon Aug 2 13:47:10 2010
@@ -48,120 +48,120 @@
#define RANDOM_DROPS
*/
-#define Q921_INIT(pri, hf) do { \
+#define Q921_INIT(ctrl, hf) do { \
memset(&(hf),0,sizeof(hf)); \
- (hf).h.sapi = (pri)->sapi; \
+ (hf).h.sapi = (ctrl)->sapi; \
(hf).h.ea1 = 0; \
(hf).h.ea2 = 1; \
- (hf).h.tei = (pri)->tei; \
+ (hf).h.tei = (ctrl)->tei; \
} while(0)
-static void reschedule_t200(struct pri *pri);
-static void q921_dump_pri(struct pri *pri);
-static void q921_establish_data_link(struct pri *pri);
-static void q921_mdl_error(struct pri *pri, char error);
-static void q921_mdl_remove(struct pri *pri);
-
-static void q921_setstate(struct pri *pri, int newstate)
-{
- if (pri->debug & PRI_DEBUG_Q921_STATE) {
- if ((pri->q921_state != newstate) && (newstate != 7) && (newstate != 8)) {
- pri_message(pri, "Changing from state %d to %d\n", pri->q921_state, newstate);
- }
- }
- pri->q921_state = newstate;
-}
-
-static void q921_discard_retransmissions(struct pri *pri)
+static void reschedule_t200(struct pri *ctrl);
+static void q921_dump_pri(struct pri *ctrl);
+static void q921_establish_data_link(struct pri *ctrl);
+static void q921_mdl_error(struct pri *ctrl, char error);
+static void q921_mdl_remove(struct pri *ctrl);
+
+static void q921_setstate(struct pri *ctrl, int newstate)
+{
+ if (ctrl->debug & PRI_DEBUG_Q921_STATE) {
+ if ((ctrl->q921_state != newstate) && (newstate != 7) && (newstate != 8)) {
+ pri_message(ctrl, "Changing from state %d to %d\n", ctrl->q921_state, newstate);
+ }
+ }
+ ctrl->q921_state = newstate;
+}
+
+static void q921_discard_retransmissions(struct pri *ctrl)
{
struct q921_frame *f, *p;
- f = pri->txqueue;
+ f = ctrl->txqueue;
while(f) {
p = f;
f = f->next;
/* Free frame */
free(p);
}
- pri->txqueue = NULL;
-}
-
-static void q921_discard_iqueue(struct pri *pri)
-{
- q921_discard_retransmissions(pri);
-}
-
-static int q921_transmit(struct pri *pri, q921_h *h, int len)
+ ctrl->txqueue = NULL;
+}
+
+static void q921_discard_iqueue(struct pri *ctrl)
+{
+ q921_discard_retransmissions(ctrl);
+}
+
+static int q921_transmit(struct pri *ctrl, q921_h *h, int len)
{
int res;
- pri = PRI_MASTER(pri);
+ ctrl = PRI_MASTER(ctrl);
#ifdef RANDOM_DROPS
if (!(random() % 3)) {
- pri_message(pri, " === Dropping Packet ===\n");
+ pri_message(ctrl, " === Dropping Packet ===\n");
return 0;
}
#endif
#ifdef LIBPRI_COUNTERS
- pri->q921_txcount++;
+ ctrl->q921_txcount++;
#endif
/* Just send it raw */
- if (pri->debug & (PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_RAW))
- q921_dump(pri, h, len, pri->debug & PRI_DEBUG_Q921_RAW, 1);
+ if (ctrl->debug & (PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_RAW))
+ q921_dump(ctrl, h, len, ctrl->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;
+ res = ctrl->write_func ? ctrl->write_func(ctrl, h, len + 2) : 0;
if (res != (len + 2)) {
- pri_error(pri, "Short write: %d/%d (%s)\n", res, len + 2, strerror(errno));
+ pri_error(ctrl, "Short write: %d/%d (%s)\n", res, len + 2, strerror(errno));
return -1;
}
return 0;
}
-static void q921_send_tei(struct pri *pri, int message, int ri, int ai, int iscommand)
+static void q921_send_tei(struct pri *ctrl, int message, int ri, int ai, int iscommand)
{
q921_u *f;
if (!(f = calloc(1, sizeof(*f) + 5)))
return;
- Q921_INIT(pri, *f);
- f->h.c_r = (pri->localtype == PRI_NETWORK) ? iscommand : !iscommand;
+ Q921_INIT(ctrl, *f);
+ f->h.c_r = (ctrl->localtype == PRI_NETWORK) ? iscommand : !iscommand;
f->ft = Q921_FRAMETYPE_U;
f->data[0] = 0x0f; /* Management entity */
f->data[1] = (ri >> 8) & 0xff;
f->data[2] = ri & 0xff;
f->data[3] = message;
f->data[4] = (ai << 1) | 1;
- if (pri->debug & PRI_DEBUG_Q921_STATE)
- pri_message(pri, "Sending TEI management message %d, TEI=%d\n", message, ai);
- q921_transmit(pri, (q921_h *)f, 8);
+ if (ctrl->debug & PRI_DEBUG_Q921_STATE)
+ pri_message(ctrl, "Sending TEI management message %d, TEI=%d\n", message, ai);
+ q921_transmit(ctrl, (q921_h *)f, 8);
free(f);
}
static void q921_tei_request(void *vpri)
{
- struct pri *pri = (struct pri *)vpri;
- pri->n202_counter++;
- if (pri->n202_counter > pri->timers[PRI_TIMER_N202]) {
- pri_error(pri, "Unable to receive TEI from network!\n");
- pri->n202_counter = 0;
+ struct pri *ctrl = (struct pri *)vpri;
+ ctrl->n202_counter++;
+ if (ctrl->n202_counter > ctrl->timers[PRI_TIMER_N202]) {
+ pri_error(ctrl, "Unable to receive TEI from network!\n");
+ ctrl->n202_counter = 0;
return;
}
- pri->ri = random() % 65535;
- q921_send_tei(PRI_MASTER(pri), Q921_TEI_IDENTITY_REQUEST, pri->ri, Q921_TEI_GROUP, 1);
- pri_schedule_del(pri, pri->t202_timer);
- pri->t202_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T202], q921_tei_request, pri);
-}
-
-static void q921_send_ua(struct pri *pri, int pfbit)
+ ctrl->ri = random() % 65535;
+ q921_send_tei(PRI_MASTER(ctrl), Q921_TEI_IDENTITY_REQUEST, ctrl->ri, Q921_TEI_GROUP, 1);
+ pri_schedule_del(ctrl, ctrl->t202_timer);
+ ctrl->t202_timer = pri_schedule_event(ctrl, ctrl->timers[PRI_TIMER_T202], q921_tei_request, ctrl);
+}
+
+static void q921_send_ua(struct pri *ctrl, int pfbit)
{
q921_h h;
- Q921_INIT(pri, h);
+ Q921_INIT(ctrl, h);
h.u.m3 = 3; /* M3 = 3 */
h.u.m2 = 0; /* M2 = 0 */
h.u.p_f = pfbit; /* Final bit on */
h.u.ft = Q921_FRAMETYPE_U;
- switch(pri->localtype) {
+ switch(ctrl->localtype) {
case PRI_NETWORK:
h.h.c_r = 0;
break;
@@ -169,24 +169,24 @@
h.h.c_r = 1;
break;
default:
- pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype);
+ pri_error(ctrl, "Don't know how to U/A on a type %d node\n", ctrl->localtype);
return;
}
- if (pri->debug & (PRI_DEBUG_Q921_STATE | PRI_DEBUG_Q921_DUMP))
- pri_message(pri, "Sending Unnumbered Acknowledgement\n");
- q921_transmit(pri, &h, 3);
-}
-
-static void q921_send_sabme(struct pri *pri)
+ if (ctrl->debug & (PRI_DEBUG_Q921_STATE | PRI_DEBUG_Q921_DUMP))
+ pri_message(ctrl, "Sending Unnumbered Acknowledgement\n");
+ q921_transmit(ctrl, &h, 3);
+}
+
+static void q921_send_sabme(struct pri *ctrl)
{
q921_h h;
- Q921_INIT(pri, h);
+ Q921_INIT(ctrl, h);
h.u.m3 = 3; /* M3 = 3 */
h.u.m2 = 3; /* M2 = 3 */
h.u.p_f = 1; /* Poll bit set */
h.u.ft = Q921_FRAMETYPE_U;
- switch(pri->localtype) {
+ switch(ctrl->localtype) {
case PRI_NETWORK:
h.h.c_r = 1;
break;
@@ -194,10 +194,10 @@
h.h.c_r = 0;
break;
default:
- pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype);
+ pri_error(ctrl, "Don't know how to U/A on a type %d node\n", ctrl->localtype);
return;
}
- q921_transmit(pri, &h, 3);
+ q921_transmit(ctrl, &h, 3);
}
#if 0
@@ -207,10 +207,10 @@
}
#endif
-static int q921_ack_packet(struct pri *pri, int num)
+static int q921_ack_packet(struct pri *ctrl, int num)
{
struct q921_frame *f, *prev = NULL;
- f = pri->txqueue;
+ f = ctrl->txqueue;
while (f) {
if (f->h.n_s == num) {
/* Cancel each packet as necessary */
@@ -218,9 +218,9 @@
if (prev)
prev->next = f->next;
else
- pri->txqueue = f->next;
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- 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);
+ ctrl->txqueue = f->next;
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "-- ACKing packet %d, new txqueue is %d (-1 means empty)\n", f->h.n_s, ctrl->txqueue ? ctrl->txqueue->h.n_s : -1);
/* Update v_a */
free(f);
return 1;
@@ -234,30 +234,30 @@
static void t203_expire(void *);
static void t200_expire(void *);
-static void reschedule_t200(struct pri *pri)
-{
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "-- Restarting T200 timer\n");
- pri_schedule_del(pri, pri->t200_timer);
- pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
-}
-
-#define restart_t200(pri) reschedule_t200((pri))
+static void reschedule_t200(struct pri *ctrl)
+{
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "-- Restarting T200 timer\n");
+ pri_schedule_del(ctrl, ctrl->t200_timer);
+ ctrl->t200_timer = pri_schedule_event(ctrl, ctrl->timers[PRI_TIMER_T200], t200_expire, ctrl);
+}
+
+#define restart_t200(ctrl) reschedule_t200((ctrl))
#if 0
-static void reschedule_t203(struct pri *pri)
-{
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "-- Restarting T203 timer\n");
- pri_schedule_del(pri, pri->t203_timer);
- pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri);
+static void reschedule_t203(struct pri *ctrl)
+{
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "-- Restarting T203 timer\n");
+ pri_schedule_del(ctrl, ctrl->t203_timer);
+ ctrl->t203_timer = pri_schedule_event(ctrl, ctrl->timers[PRI_TIMER_T203], t203_expire, ctrl);
}
#endif
#if 0
-static int q921_unacked_iframes(struct pri *pri)
-{
- struct q921_frame *f = pri->txqueue;
+static int q921_unacked_iframes(struct pri *ctrl)
+{
+ struct q921_frame *f = ctrl->txqueue;
int cnt = 0;
while(f) {
@@ -270,107 +270,107 @@
}
#endif
-static void start_t203(struct pri *pri)
-{
- if (pri->t203_timer) {
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "T203 requested to start without stopping first\n");
- pri_schedule_del(pri, pri->t203_timer);
- }
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "-- Starting T203 timer\n");
- pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri);
-}
-
-static void stop_t203(struct pri *pri)
-{
- if (pri->t203_timer) {
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "-- Stopping T203 timer\n");
- pri_schedule_del(pri, pri->t203_timer);
- pri->t203_timer = 0;
+static void start_t203(struct pri *ctrl)
+{
+ if (ctrl->t203_timer) {
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "T203 requested to start without stopping first\n");
+ pri_schedule_del(ctrl, ctrl->t203_timer);
+ }
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "-- Starting T203 timer\n");
+ ctrl->t203_timer = pri_schedule_event(ctrl, ctrl->timers[PRI_TIMER_T203], t203_expire, ctrl);
+}
+
+static void stop_t203(struct pri *ctrl)
+{
+ if (ctrl->t203_timer) {
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "-- Stopping T203 timer\n");
+ pri_schedule_del(ctrl, ctrl->t203_timer);
+ ctrl->t203_timer = 0;
} else {
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "-- T203 requested to stop when not started\n");
- }
-}
-
-static void start_t200(struct pri *pri)
-{
- if (pri->t200_timer) {
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "T200 requested to start without stopping first\n");
- pri_schedule_del(pri, pri->t200_timer);
- }
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "-- Starting T200 timer\n");
- pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
-}
-
-static void stop_t200(struct pri *pri)
-{
- if (pri->t200_timer) {
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "-- Stopping T200 timer\n");
- pri_schedule_del(pri, pri->t200_timer);
- pri->t200_timer = 0;
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "-- T203 requested to stop when not started\n");
+ }
+}
+
+static void start_t200(struct pri *ctrl)
+{
+ if (ctrl->t200_timer) {
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "T200 requested to start without stopping first\n");
+ pri_schedule_del(ctrl, ctrl->t200_timer);
+ }
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "-- Starting T200 timer\n");
+ ctrl->t200_timer = pri_schedule_event(ctrl, ctrl->timers[PRI_TIMER_T200], t200_expire, ctrl);
+}
+
+static void stop_t200(struct pri *ctrl)
+{
+ if (ctrl->t200_timer) {
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "-- Stopping T200 timer\n");
+ pri_schedule_del(ctrl, ctrl->t200_timer);
+ ctrl->t200_timer = 0;
} else {
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "-- T200 requested to stop when not started\n");
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "-- T200 requested to stop when not started\n");
}
}
/* This is the equivalent of the I-Frame queued up path in Figure B.7 in MULTI_FRAME_ESTABLISHED */
-static int q921_send_queued_iframes(struct pri *pri)
+static int q921_send_queued_iframes(struct pri *ctrl)
{
struct q921_frame *f;
int frames_txd = 0;
- if (pri->peer_rx_busy || (pri->v_s == Q921_ADD(pri->v_a, pri->timers[PRI_TIMER_K]))) {
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "Couldn't transmit I frame at this time due to peer busy condition or window shut\n");
+ if (ctrl->peer_rx_busy || (ctrl->v_s == Q921_ADD(ctrl->v_a, ctrl->timers[PRI_TIMER_K]))) {
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "Couldn't transmit I frame at this time due to peer busy condition or window shut\n");
return 0;
}
- f = pri->txqueue;
- while (f && (pri->v_s != Q921_ADD(pri->v_a, pri->timers[PRI_TIMER_K]))) {
+ f = ctrl->txqueue;
+ while (f && (ctrl->v_s != Q921_ADD(ctrl->v_a, ctrl->timers[PRI_TIMER_K]))) {
if (!f->transmitted) {
/* Send it now... */
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "-- Finally transmitting %d, since window opened up (%d)\n", f->h.n_s, pri->timers[PRI_TIMER_K]);
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "-- Finally transmitting %d, since window opened up (%d)\n", f->h.n_s, ctrl->timers[PRI_TIMER_K]);
f->transmitted++;
- f->h.n_s = pri->v_s;
- f->h.n_r = pri->v_r;
+ f->h.n_s = ctrl->v_s;
+ f->h.n_r = ctrl->v_r;
f->h.ft = 0;
f->h.p_f = 0;
- q921_transmit(pri, (q921_h *)(&f->h), f->len);
- Q921_INC(pri->v_s);
+ q921_transmit(ctrl, (q921_h *)(&f->h), f->len);
+ Q921_INC(ctrl->v_s);
frames_txd++;
- pri->acknowledge_pending = 0;
+ ctrl->acknowledge_pending = 0;
}
f = f->next;
}
if (frames_txd) {
- if (!pri->t200_timer) {
- stop_t203(pri);
- start_t200(pri);
+ if (!ctrl->t200_timer) {
+ stop_t203(ctrl);
+ start_t200(ctrl);
}
}
return frames_txd;
}
-static void q921_reject(struct pri *pri, int pf)
+static void q921_reject(struct pri *ctrl, int pf)
{
q921_h h;
- Q921_INIT(pri, h);
+ Q921_INIT(ctrl, h);
h.s.x0 = 0; /* Always 0 */
h.s.ss = 2; /* Reject */
h.s.ft = 1; /* Frametype (01) */
- h.s.n_r = pri->v_r; /* Where to start retransmission */
+ h.s.n_r = ctrl->v_r; /* Where to start retransmission */
h.s.p_f = pf;
- switch(pri->localtype) {
+ switch(ctrl->localtype) {
case PRI_NETWORK:
h.h.c_r = 0;
break;
@@ -378,23 +378,23 @@
h.h.c_r = 1;
break;
default:
- pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype);
+ pri_error(ctrl, "Don't know how to U/A on a type %d node\n", ctrl->localtype);
return;
}
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "Sending Reject (%d)\n", pri->v_r);
- q921_transmit(pri, &h, 4);
-}
-
-static void q921_rr(struct pri *pri, int pbit, int cmd) {
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "Sending Reject (%d)\n", ctrl->v_r);
+ q921_transmit(ctrl, &h, 4);
+}
+
+static void q921_rr(struct pri *ctrl, int pbit, int cmd) {
q921_h h;
- Q921_INIT(pri, h);
+ Q921_INIT(ctrl, h);
h.s.x0 = 0; /* Always 0 */
h.s.ss = 0; /* Receive Ready */
h.s.ft = 1; /* Frametype (01) */
- h.s.n_r = pri->v_r; /* N/R */
+ h.s.n_r = ctrl->v_r; /* N/R */
h.s.p_f = pbit; /* Poll/Final set appropriately */
- switch(pri->localtype) {
+ switch(ctrl->localtype) {
case PRI_NETWORK:
if (cmd)
h.h.c_r = 1;
@@ -408,20 +408,20 @@
h.h.c_r = 1;
break;
default:
- pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype);
+ pri_error(ctrl, "Don't know how to U/A on a type %d node\n", ctrl->localtype);
return;
}
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "Sending Receiver Ready (%d)\n", pri->v_r);
- q921_transmit(pri, &h, 4);
-}
-
-static void transmit_enquiry(struct pri *pri)
-{
- if (!pri->own_rx_busy) {
- q921_rr(pri, 1, 1);
- pri->acknowledge_pending = 0;
- start_t200(pri);
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "Sending Receiver Ready (%d)\n", ctrl->v_r);
+ q921_transmit(ctrl, &h, 4);
+}
+
+static void transmit_enquiry(struct pri *ctrl)
+{
+ if (!ctrl->own_rx_busy) {
+ q921_rr(ctrl, 1, 1);
+ ctrl->acknowledge_pending = 0;
+ start_t200(ctrl);
} else {
/* XXX: Implement me... */
}
@@ -429,71 +429,71 @@
static void t200_expire(void *vpri)
{
- struct pri *pri = vpri;
-
- if (pri->debug & PRI_DEBUG_Q921_DUMP) {
- pri_message(pri, "%s\n", __FUNCTION__);
- q921_dump_pri(pri);
- }
-
- pri->t200_timer = 0;
-
- switch (pri->q921_state) {
+ struct pri *ctrl = vpri;
+
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP) {
+ pri_message(ctrl, "%s\n", __FUNCTION__);
+ q921_dump_pri(ctrl);
+ }
+
+ ctrl->t200_timer = 0;
+
+ switch (ctrl->q921_state) {
case Q921_MULTI_FRAME_ESTABLISHED:
- pri->RC = 0;
- transmit_enquiry(pri);
- pri->RC++;
- q921_setstate(pri, Q921_TIMER_RECOVERY);
+ ctrl->RC = 0;
+ transmit_enquiry(ctrl);
+ ctrl->RC++;
+ q921_setstate(ctrl, Q921_TIMER_RECOVERY);
break;
case Q921_TIMER_RECOVERY:
/* SDL Flow Figure B.8/Q.921 Page 81 */
- if (pri->RC != pri->timers[PRI_TIMER_N200]) {
+ if (ctrl->RC != ctrl->timers[PRI_TIMER_N200]) {
#if 0
- if (pri->v_s == pri->v_a) {
- transmit_enquiry(pri);
+ if (ctrl->v_s == ctrl->v_a) {
+ transmit_enquiry(ctrl);
}
#else
/* We are chosing to enquiry by default (to reduce risk of T200 timer errors at the other
* side, instead of retransmission of the last I frame we sent */
- transmit_enquiry(pri);
+ transmit_enquiry(ctrl);
#endif
- pri->RC++;
+ ctrl->RC++;
} else {
- //pri_error(pri, "MDL-ERROR (I): T200 = N200 in timer recovery state\n");
- q921_mdl_error(pri, 'I');
- q921_establish_data_link(pri);
- pri->l3initiated = 0;
- q921_setstate(pri, Q921_AWAITING_ESTABLISHMENT);
+ //pri_error(ctrl, "MDL-ERROR (I): T200 = N200 in timer recovery state\n");
+ q921_mdl_error(ctrl, 'I');
+ q921_establish_data_link(ctrl);
+ ctrl->l3initiated = 0;
+ q921_setstate(ctrl, Q921_AWAITING_ESTABLISHMENT);
}
break;
case Q921_AWAITING_ESTABLISHMENT:
- if (pri->RC != pri->timers[PRI_TIMER_N200]) {
- pri->RC++;
- q921_send_sabme(pri);
- start_t200(pri);
+ if (ctrl->RC != ctrl->timers[PRI_TIMER_N200]) {
+ ctrl->RC++;
+ q921_send_sabme(ctrl);
+ start_t200(ctrl);
} else {
- q921_discard_iqueue(pri);
- //pri_error(pri, "MDL-ERROR (G) : T200 expired N200 times in state %d\n", pri->q921_state);
- q921_mdl_error(pri, 'G');
- q921_setstate(pri, Q921_TEI_ASSIGNED);
+ q921_discard_iqueue(ctrl);
+ //pri_error(ctrl, "MDL-ERROR (G) : T200 expired N200 times in state %d\n", ctrl->q921_state);
+ q921_mdl_error(ctrl, 'G');
+ q921_setstate(ctrl, Q921_TEI_ASSIGNED);
/* DL-RELEASE indication */
- q931_dl_indication(pri, PRI_EVENT_DCHAN_DOWN);
- }
- break;
- default:
- pri_error(pri, "Cannot handle T200 expire in state %d\n", pri->q921_state);
+ q931_dl_indication(ctrl, PRI_EVENT_DCHAN_DOWN);
+ }
+ break;
+ default:
+ pri_error(ctrl, "Cannot handle T200 expire in state %d\n", ctrl->q921_state);
}
}
/* This is sending a DL-UNIT-DATA request */
-int q921_transmit_uiframe(struct pri *pri, void *buf, int len)
+int q921_transmit_uiframe(struct pri *ctrl, void *buf, int len)
{
uint8_t ubuf[512];
q921_h *h = (void *)&ubuf[0];
if (len >= 512) {
- pri_error(pri, "Requested to send UI frame larger than 512 bytes!\n");
+ pri_error(ctrl, "Requested to send UI frame larger than 512 bytes!\n");
return -1;
}
@@ -501,13 +501,13 @@
h->h.sapi = 0;
h->h.ea1 = 0;
h->h.ea2 = 1;
- h->h.tei = pri->tei;
+ h->h.tei = ctrl->tei;
h->u.m3 = 0;
h->u.m2 = 0;
h->u.p_f = 0; /* Poll bit set */
h->u.ft = Q921_FRAMETYPE_U;
- switch(pri->localtype) {
+ switch(ctrl->localtype) {
case PRI_NETWORK:
h->h.c_r = 1;
break;
@@ -515,23 +515,23 @@
h->h.c_r = 0;
break;
default:
- pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype);
+ pri_error(ctrl, "Don't know how to U/A on a type %d node\n", ctrl->localtype);
return -1;
}
memcpy(h->u.data, buf, len);
- q921_transmit(pri, h, len + 3);
+ q921_transmit(ctrl, h, len + 3);
return 0;
}
static struct pri * pri_find_tei(struct pri *vpri, int sapi, int tei)
{
- struct pri *pri;
- for (pri = PRI_MASTER(vpri); pri; pri = pri->subchannel) {
- if (pri->tei == tei && pri->sapi == sapi)
- return pri;
+ struct pri *ctrl;
+ for (ctrl = PRI_MASTER(vpri); ctrl; ctrl = ctrl->subchannel) {
+ if (ctrl->tei == tei && ctrl->sapi == sapi)
+ return ctrl;
}
return NULL;
@@ -541,7 +541,7 @@
int q921_transmit_iframe(struct pri *vpri, int tei, void *buf, int len, int cr)
{
q921_frame *f, *prev=NULL;
- struct pri *pri;
+ struct pri *ctrl;
if (BRI_NT_PTMP(vpri)) {
if (tei == Q921_TEI_GROUP) {
@@ -549,31 +549,31 @@
return 0;
}
- pri = pri_find_tei(vpri, Q921_SAPI_CALL_CTRL, tei);
- if (!pri) {
+ ctrl = pri_find_tei(vpri, Q921_SAPI_CALL_CTRL, tei);
+ if (!ctrl) {
pri_error(vpri, "Huh?! Unable to locate PRI associated with TEI %d. Did we have to ditch it due to error conditions?\n", tei);
return 0;
}
} else if (BRI_TE_PTMP(vpri)) {
/* We don't care what the tei is, since we only support one sub and one TEI */
- pri = PRI_MASTER(vpri)->subchannel;
-
- if (pri->q921_state == Q921_TEI_UNASSIGNED) {
- q921_tei_request(pri);
- q921_setstate(pri, Q921_ESTABLISH_AWAITING_TEI);
+ ctrl = PRI_MASTER(vpri)->subchannel;
+
+ if (ctrl->q921_state == Q921_TEI_UNASSIGNED) {
+ q921_tei_request(ctrl);
+ q921_setstate(ctrl, Q921_ESTABLISH_AWAITING_TEI);
}
} else {
/* Should just be PTP modes, which shouldn't have subs */
- pri = vpri;
+ ctrl = vpri;
}
/* Figure B.7/Q.921 Page 70 */
- switch (pri->q921_state) {
+ switch (ctrl->q921_state) {
case Q921_TEI_ASSIGNED:
/* If we aren't in a state compatiable with DL-DATA requests, start getting us there here */
- q921_establish_data_link(pri);
- pri->l3initiated = 1;
- q921_setstate(pri, Q921_AWAITING_ESTABLISHMENT);
+ q921_establish_data_link(ctrl);
+ ctrl->l3initiated = 1;
+ q921_setstate(ctrl, Q921_AWAITING_ESTABLISHMENT);
/* For all rest, we've done the work to get us up prior to this and fall through */
case Q921_TEI_UNASSIGNED:
case Q921_ESTABLISH_AWAITING_TEI:
@@ -581,11 +581,11 @@
case Q921_TIMER_RECOVERY:
case Q921_AWAITING_ESTABLISHMENT:
case Q921_MULTI_FRAME_ESTABLISHED:
- for (f=pri->txqueue; f; f = f->next) prev = f;
+ for (f=ctrl->txqueue; f; f = f->next) prev = f;
f = calloc(1, sizeof(q921_frame) + len + 2);
if (f) {
- Q921_INIT(pri, f->h);
- switch(pri->localtype) {
+ Q921_INIT(ctrl, f->h);
+ switch(ctrl->localtype) {
case PRI_NETWORK:
if (cr)
f->h.h.c_r = 1;
@@ -606,58 +606,58 @@
if (prev)
prev->next = f;
else
- pri->txqueue = f;
-
- if (pri->q921_state != Q921_MULTI_FRAME_ESTABLISHED) {
+ ctrl->txqueue = f;
+
+ if (ctrl->q921_state != Q921_MULTI_FRAME_ESTABLISHED) {
return 0;
}
- if (pri->peer_rx_busy || (pri->v_s == Q921_ADD(pri->v_a, pri->timers[PRI_TIMER_K]))) {
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "Couldn't transmit I frame at this time due to peer busy condition or window shut\n");
+ if (ctrl->peer_rx_busy || (ctrl->v_s == Q921_ADD(ctrl->v_a, ctrl->timers[PRI_TIMER_K]))) {
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "Couldn't transmit I frame at this time due to peer busy condition or window shut\n");
return 0;
}
- q921_send_queued_iframes(pri);
+ q921_send_queued_iframes(ctrl);
return 0;
} else {
- pri_error(pri, "!! Out of memory for Q.921 transmit\n");
+ pri_error(ctrl, "!! Out of memory for Q.921 transmit\n");
return -1;
}
default:
- pri_error(pri, "Cannot transmit frames in state %d\n", pri->q921_state);
+ pri_error(ctrl, "Cannot transmit frames in state %d\n", ctrl->q921_state);
}
return 0;
}
static void t203_expire(void *vpri)
{
- struct pri *pri = vpri;
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "%s\n", __FUNCTION__);
- pri->t203_timer = 0;
- switch (pri->q921_state) {
+ struct pri *ctrl = vpri;
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "%s\n", __FUNCTION__);
+ ctrl->t203_timer = 0;
+ switch (ctrl->q921_state) {
case Q921_MULTI_FRAME_ESTABLISHED:
- transmit_enquiry(pri);
- pri->RC = 0;
- q921_setstate(pri, Q921_TIMER_RECOVERY);
- break;
- default:
- if (pri->debug & PRI_DEBUG_Q921_DUMP)
- pri_message(pri, "T203 counter expired in weird state %d\n", pri->q921_state);
- pri->t203_timer = 0;
- }
-}
-
-static void q921_dump_iqueue_info(struct pri *pri, int force)
+ transmit_enquiry(ctrl);
+ ctrl->RC = 0;
+ q921_setstate(ctrl, Q921_TIMER_RECOVERY);
+ break;
+ default:
+ if (ctrl->debug & PRI_DEBUG_Q921_DUMP)
+ pri_message(ctrl, "T203 counter expired in weird state %d\n", ctrl->q921_state);
+ ctrl->t203_timer = 0;
+ }
+}
+
+static void q921_dump_iqueue_info(struct pri *ctrl, int force)
{
struct q921_frame *f;
int pending = 0, unacked = 0;
unacked = pending = 0;
- for (f = pri->txqueue; f && f->next; f = f->next) {
+ for (f = ctrl->txqueue; f && f->next; f = f->next) {
if (f->transmitted) {
unacked++;
} else {
@@ -666,54 +666,54 @@
}
if (force)
- pri_error(pri, "Number of pending packets %d, sent but unacked %d\n", pending, unacked);
+ pri_error(ctrl, "Number of pending packets %d, sent but unacked %d\n", pending, unacked);
return;
}
-static void q921_dump_pri_by_h(struct pri *pri, q921_h *h);
-
-void q921_dump(struct pri *pri, q921_h *h, int len, int showraw, int txrx)
+static void q921_dump_pri_by_h(struct pri *ctrl, q921_h *h);
+
+void q921_dump(struct pri *ctrl, q921_h *h, int len, int showraw, int txrx)
{
int x;
char *type;
char direction_tag;
- q921_dump_pri_by_h(pri, h);
+ q921_dump_pri_by_h(ctrl, h);
direction_tag = txrx ? '>' : '<';
if (showraw) {
char *buf = malloc(len * 3 + 1);
int buflen = 0;
if (buf) {
- pri_message(pri, "\n");
+ pri_message(ctrl, "\n");
for (x=0;x<len;x++)
buflen += sprintf(buf + buflen, "%02x ", h->raw[x]);
- pri_message(pri, "%c [ %s]\n", direction_tag, buf);
+ pri_message(ctrl, "%c [ %s]\n", direction_tag, buf);
free(buf);
}
}
- pri_message(pri, "\n");
+ pri_message(ctrl, "\n");
switch (h->h.data[0] & Q921_FRAMETYPE_MASK) {
case 0:
case 2:
- pri_message(pri, "%c Informational frame:\n", direction_tag);
+ pri_message(ctrl, "%c Informational frame:\n", direction_tag);
break;
case 1:
- pri_message(pri, "%c Supervisory frame:\n", direction_tag);
+ pri_message(ctrl, "%c Supervisory frame:\n", direction_tag);
break;
case 3:
- pri_message(pri, "%c Unnumbered frame:\n", direction_tag);
+ pri_message(ctrl, "%c Unnumbered frame:\n", direction_tag);
break;
}
- pri_message(pri, "%c SAPI: %02d C/R: %d EA: %d\n",
+ pri_message(ctrl, "%c SAPI: %02d C/R: %d EA: %d\n",
direction_tag,
h->h.sapi,
h->h.c_r,
h->h.ea1);
- pri_message(pri, "%c TEI: %03d EA: %d\n",
+ pri_message(ctrl, "%c TEI: %03d EA: %d\n",
direction_tag,
h->h.tei,
h->h.ea2);
@@ -722,15 +722,15 @@
case 0:
case 2:
/* Informational frame */
- pri_message(pri, "%c N(S): %03d 0: %d\n",
+ pri_message(ctrl, "%c N(S): %03d 0: %d\n",
direction_tag,
h->i.n_s,
h->i.ft);
- pri_message(pri, "%c N(R): %03d P: %d\n",
+ pri_message(ctrl, "%c N(R): %03d P: %d\n",
direction_tag,
h->i.n_r,
h->i.p_f);
- pri_message(pri, "%c %d bytes of data\n",
+ pri_message(ctrl, "%c %d bytes of data\n",
direction_tag,
len - 4);
break;
@@ -748,17 +748,17 @@
type = "REJ (reject)";
break;
}
- pri_message(pri, "%c Zero: %d S: %d 01: %d [ %s ]\n",
+ pri_message(ctrl, "%c Zero: %d S: %d 01: %d [ %s ]\n",
direction_tag,
h->s.x0,
h->s.ss,
h->s.ft,
type);
- pri_message(pri, "%c N(R): %03d P/F: %d\n",
+ pri_message(ctrl, "%c N(R): %03d P/F: %d\n",
direction_tag,
h->s.n_r,
h->s.p_f);
- pri_message(pri, "%c %d bytes of data\n",
+ pri_message(ctrl, "%c %d bytes of data\n",
direction_tag,
len - 4);
break;
@@ -793,14 +793,14 @@
break;
}
}
- pri_message(pri, "%c M3: %d P/F: %d M2: %d 11: %d [ %s ]\n",
+ pri_message(ctrl, "%c M3: %d P/F: %d M2: %d 11: %d [ %s ]\n",
direction_tag,
h->u.m3,
h->u.p_f,
h->u.m2,
h->u.ft,
type);
- pri_message(pri, "%c %d bytes of data\n",
+ pri_message(ctrl, "%c %d bytes of data\n",
direction_tag,
len - 3);
break;
@@ -839,60 +839,60 @@
type = "Unknown";
break;
}
- pri_message(pri, "%c MDL Message: %s (%d)\n", direction_tag, type, h->u.data[3]);
- pri_message(pri, "%c RI: %d\n", direction_tag, ri);
- pri_message(pri, "%c Ai: %d E:%d\n", direction_tag, (h->u.data[4] >> 1) & 0x7f, h->u.data[4] & 1);
- }
-}
-
-static void q921_dump_pri(struct pri *pri)
-{
- pri_message(pri, "TEI: %d State %d\n", pri->tei, pri->q921_state);
- pri_message(pri, "V(S) %d V(A) %d V(R) %d\n", pri->v_s, pri->v_a, pri->v_r);
- pri_message(pri, "K %d, RC %d, l3initiated %d, reject_except %d ack_pend %d\n", pri->timers[PRI_TIMER_K], pri->RC, pri->l3initiated, pri->reject_exception, pri->acknowledge_pending);
- pri_message(pri, "T200 %d, N200 %d, T203 %d\n", pri->t200_timer, 3, pri->t203_timer);
+ pri_message(ctrl, "%c MDL Message: %s (%d)\n", direction_tag, type, h->u.data[3]);
+ pri_message(ctrl, "%c RI: %d\n", direction_tag, ri);
+ pri_message(ctrl, "%c Ai: %d E:%d\n", direction_tag, (h->u.data[4] >> 1) & 0x7f, h->u.data[4] & 1);
+ }
+}
+
+static void q921_dump_pri(struct pri *ctrl)
+{
+ pri_message(ctrl, "TEI: %d State %d\n", ctrl->tei, ctrl->q921_state);
+ pri_message(ctrl, "V(S) %d V(A) %d V(R) %d\n", ctrl->v_s, ctrl->v_a, ctrl->v_r);
+ pri_message(ctrl, "K %d, RC %d, l3initiated %d, reject_except %d ack_pend %d\n", ctrl->timers[PRI_TIMER_K], ctrl->RC, ctrl->l3initiated, ctrl->reject_exception, ctrl->acknowledge_pending);
+ pri_message(ctrl, "T200 %d, N200 %d, T203 %d\n", ctrl->t200_timer, 3, ctrl->t203_timer);
}
static void q921_dump_pri_by_h(struct pri *vpri, q921_h *h)
{
- struct pri *pri = NULL;
+ struct pri *ctrl = NULL;
if (!vpri) {
return;
}
if (BRI_NT_PTMP(vpri)) {
- pri = pri_find_tei(vpri, h->h.sapi, h->h.tei);
+ ctrl = pri_find_tei(vpri, h->h.sapi, h->h.tei);
} else if (BRI_TE_PTMP(vpri)) {
- pri = PRI_MASTER(vpri)->subchannel;
+ ctrl = PRI_MASTER(vpri)->subchannel;
} else
- pri = vpri;
- if (pri) {
- q921_dump_pri(pri);
+ ctrl = vpri;
+ if (ctrl) {
+ q921_dump_pri(ctrl);
} else if (!PTMP_MODE(vpri)) {
pri_error(vpri, "Huh.... no pri found to dump\n");
}
}
-static pri_event *q921_receive_MDL(struct pri *pri, q921_u *h, int len)
+static pri_event *q921_receive_MDL(struct pri *ctrl, q921_u *h, int len)
{
int ri;
- struct pri *sub = pri;
+ struct pri *sub = ctrl;
pri_event *res = NULL;
int tei;
- if (!BRI_NT_PTMP(pri) && !BRI_TE_PTMP(pri)) {
- pri_error(pri, "Received MDL/TEI managemement message, but configured for mode other than PTMP!\n");
+ if (!BRI_NT_PTMP(ctrl) && !BRI_TE_PTMP(ctrl)) {
+ pri_error(ctrl, "Received MDL/TEI managemement message, but configured for mode other than PTMP!\n");
return NULL;
}
- if (pri->debug & PRI_DEBUG_Q921_STATE)
- pri_message(pri, "Received MDL message\n");
+ if (ctrl->debug & PRI_DEBUG_Q921_STATE)
+ pri_message(ctrl, "Received MDL message\n");
if (h->data[0] != 0x0f) {
- pri_error(pri, "Received MDL with unsupported management entity %02x\n", h->data[0]);
+ pri_error(ctrl, "Received MDL with unsupported management entity %02x\n", h->data[0]);
return NULL;
}
if (!(h->data[4] & 0x01)) {
- pri_error(pri, "Received MDL with multibyte TEI identifier\n");
+ pri_error(ctrl, "Received MDL with multibyte TEI identifier\n");
return NULL;
}
ri = (h->data[1] << 8) | h->data[2];
@@ -900,13 +900,13 @@
switch(h->data[3]) {
case Q921_TEI_IDENTITY_REQUEST:
- if (!BRI_NT_PTMP(pri)) {
+ if (!BRI_NT_PTMP(ctrl)) {
return NULL;
}
if (tei != 127) {
- pri_error(pri, "Received TEI identity request with invalid TEI %d\n", tei);
- q921_send_tei(pri, Q921_TEI_IDENTITY_DENIED, ri, tei, 1);
+ pri_error(ctrl, "Received TEI identity request with invalid TEI %d\n", tei);
+ q921_send_tei(ctrl, Q921_TEI_IDENTITY_DENIED, ri, tei, 1);
}
tei = 64;
while (sub->subchannel) {
@@ -916,176 +916,176 @@
}
if (tei >= Q921_TEI_GROUP) {
- pri_error(pri, "Reached maximum TEI quota, cannot assign new TEI\n");
+ pri_error(ctrl, "Reached maximum TEI quota, cannot assign new TEI\n");
return NULL;
}
- sub->subchannel = __pri_new_tei(-1, pri->localtype, pri->switchtype, pri, NULL, NULL, NULL, tei, 1);
+ sub->subchannel = __pri_new_tei(-1, ctrl->localtype, ctrl->switchtype, ctrl, NULL, NULL, NULL, tei, 1);
if (!sub->subchannel) {
- pri_error(pri, "Unable to allocate D-channel for new TEI %d\n", tei);
+ pri_error(ctrl, "Unable to allocate D-channel for new TEI %d\n", tei);
return NULL;
}
q921_setstate(sub->subchannel, Q921_TEI_ASSIGNED);
- if (pri->debug & PRI_DEBUG_Q921_STATE) {
- pri_message(pri, "Allocating new TEI %d\n", tei);
- }
- q921_send_tei(pri, Q921_TEI_IDENTITY_ASSIGNED, ri, tei, 1);
+ if (ctrl->debug & PRI_DEBUG_Q921_STATE) {
+ pri_message(ctrl, "Allocating new TEI %d\n", tei);
+ }
+ q921_send_tei(ctrl, Q921_TEI_IDENTITY_ASSIGNED, ri, tei, 1);
break;
case Q921_TEI_IDENTITY_ASSIGNED:
- if (!BRI_TE_PTMP(pri))
+ if (!BRI_TE_PTMP(ctrl))
return NULL;
/* Assuming we're operating on the sub here */
- pri = pri->subchannel;
+ ctrl = ctrl->subchannel;
- switch (pri->q921_state) {
+ switch (ctrl->q921_state) {
case Q921_ASSIGN_AWAITING_TEI:
case Q921_ESTABLISH_AWAITING_TEI:
break;
default:
- pri_message(pri, "Ignoring unrequested TEI assign message\n");
+ pri_message(ctrl, "Ignoring unrequested TEI assign message\n");
return NULL;
}
- if (ri != pri->ri) {
- pri_message(pri, "TEI assignment received for invalid Ri %02x (our is %02x)\n", ri, pri->ri);
+ if (ri != ctrl->ri) {
+ pri_message(ctrl, "TEI assignment received for invalid Ri %02x (our is %02x)\n", ri, ctrl->ri);
return NULL;
}
- pri_schedule_del(pri, pri->t202_timer);
- pri->t202_timer = 0;
- pri->tei = tei;
-
- switch (pri->q921_state) {
+ pri_schedule_del(ctrl, ctrl->t202_timer);
+ ctrl->t202_timer = 0;
+ ctrl->tei = tei;
+
+ switch (ctrl->q921_state) {
case Q921_ASSIGN_AWAITING_TEI:
- q921_setstate(pri, Q921_TEI_ASSIGNED);
- pri->ev.gen.e = PRI_EVENT_DCHAN_UP;
- res = &pri->ev;
+ q921_setstate(ctrl, Q921_TEI_ASSIGNED);
+ ctrl->ev.gen.e = PRI_EVENT_DCHAN_UP;
+ res = &ctrl->ev;
break;
case Q921_ESTABLISH_AWAITING_TEI:
- q921_establish_data_link(pri);
- pri->l3initiated = 1;
- q921_setstate(pri, Q921_AWAITING_ESTABLISHMENT);
+ q921_establish_data_link(ctrl);
+ ctrl->l3initiated = 1;
+ q921_setstate(ctrl, Q921_AWAITING_ESTABLISHMENT);
break;
default:
- pri_error(pri, "Error 3\n");
+ pri_error(ctrl, "Error 3\n");
return NULL;
}
break;
case Q921_TEI_IDENTITY_CHECK_REQUEST:
- if (!BRI_TE_PTMP(pri))
+ if (!BRI_TE_PTMP(ctrl))
return NULL;
- if (pri->subchannel->q921_state < Q921_TEI_ASSIGNED)
+ if (ctrl->subchannel->q921_state < Q921_TEI_ASSIGNED)
return NULL;
/* If it's addressed to the group TEI or to our TEI specifically, we respond */
- if ((tei == Q921_TEI_GROUP) || (tei == pri->subchannel->tei))
- q921_send_tei(pri, Q921_TEI_IDENTITY_CHECK_RESPONSE, random() % 65535, pri->subchannel->tei, 1);
+ if ((tei == Q921_TEI_GROUP) || (tei == ctrl->subchannel->tei))
+ q921_send_tei(ctrl, Q921_TEI_IDENTITY_CHECK_RESPONSE, random() % 65535, ctrl->subchannel->tei, 1);
break;
case Q921_TEI_IDENTITY_REMOVE:
- if (!BRI_TE_PTMP(pri))
+ if (!BRI_TE_PTMP(ctrl))
return NULL;
- if ((tei == Q921_TEI_GROUP) || (tei == pri->subchannel->tei)) {
- q921_setstate(pri->subchannel, Q921_TEI_UNASSIGNED);
- q921_start(pri->subchannel);
+ if ((tei == Q921_TEI_GROUP) || (tei == ctrl->subchannel->tei)) {
+ q921_setstate(ctrl->subchannel, Q921_TEI_UNASSIGNED);
+ q921_start(ctrl->subchannel);
}
}
return res; /* Do we need to return something??? */
}
-static int is_command(struct pri *pri, q921_h *h)
+static int is_command(struct pri *ctrl, q921_h *h)
{
int command = 0;
int c_r = h->s.h.c_r;
- if ((pri->localtype == PRI_NETWORK && c_r == 0) ||
- (pri->localtype == PRI_CPE && c_r == 1))
+ if ((ctrl->localtype == PRI_NETWORK && c_r == 0) ||
+ (ctrl->localtype == PRI_CPE && c_r == 1))
command = 1;
return command;
}
-static void q921_clear_exception_conditions(struct pri *pri)
-{
- pri->own_rx_busy = 0;
- pri->peer_rx_busy = 0;
- pri->reject_exception = 0;
- pri->acknowledge_pending = 0;
-}
-
-static pri_event * q921_sabme_rx(struct pri *pri, q921_h *h)
+static void q921_clear_exception_conditions(struct pri *ctrl)
+{
+ ctrl->own_rx_busy = 0;
+ ctrl->peer_rx_busy = 0;
+ ctrl->reject_exception = 0;
+ ctrl->acknowledge_pending = 0;
+}
+
+static pri_event * q921_sabme_rx(struct pri *ctrl, q921_h *h)
{
pri_event *res = NULL;
- switch (pri->q921_state) {
+ switch (ctrl->q921_state) {
case Q921_TIMER_RECOVERY:
/* Timer recovery state handling is same as multiframe established */
case Q921_MULTI_FRAME_ESTABLISHED:
/* Send Unnumbered Acknowledgement */
- q921_send_ua(pri, h->u.p_f);
- q921_clear_exception_conditions(pri);
- //pri_error(pri, "MDL-ERROR (F), SABME in state %d\n", pri->q921_state);
- q921_mdl_error(pri, 'F');
- if (pri->v_s != pri->v_a) {
- q921_discard_iqueue(pri);
+ q921_send_ua(ctrl, h->u.p_f);
+ q921_clear_exception_conditions(ctrl);
+ //pri_error(ctrl, "MDL-ERROR (F), SABME in state %d\n", ctrl->q921_state);
+ q921_mdl_error(ctrl, 'F');
+ if (ctrl->v_s != ctrl->v_a) {
+ q921_discard_iqueue(ctrl);
/* DL-ESTABLISH indication */
- q931_dl_indication(pri, PRI_EVENT_DCHAN_UP);
- }
- stop_t200(pri);
- start_t203(pri);
- pri->v_s = pri->v_a = pri->v_r = 0;
- q921_setstate(pri, Q921_MULTI_FRAME_ESTABLISHED);
+ q931_dl_indication(ctrl, PRI_EVENT_DCHAN_UP);
+ }
+ stop_t200(ctrl);
+ start_t203(ctrl);
+ ctrl->v_s = ctrl->v_a = ctrl->v_r = 0;
+ q921_setstate(ctrl, Q921_MULTI_FRAME_ESTABLISHED);
break;
case Q921_TEI_ASSIGNED:
- q921_send_ua(pri, h->u.p_f);
- q921_clear_exception_conditions(pri);
- pri->v_s = pri->v_a = pri->v_r = 0;
+ q921_send_ua(ctrl, h->u.p_f);
+ q921_clear_exception_conditions(ctrl);
+ ctrl->v_s = ctrl->v_a = ctrl->v_r = 0;
/* DL-ESTABLISH indication */
- q931_dl_indication(pri, PRI_EVENT_DCHAN_UP);
- if (PTP_MODE(pri)) {
- pri->ev.gen.e = PRI_EVENT_DCHAN_UP;
- res = &pri->ev;
- }
- start_t203(pri);
- q921_setstate(pri, Q921_MULTI_FRAME_ESTABLISHED);
+ q931_dl_indication(ctrl, PRI_EVENT_DCHAN_UP);
+ if (PTP_MODE(ctrl)) {
[... 1467 lines stripped ...]
More information about the libpri-commits
mailing list