From 39e2eadc99c38876c39700cc2f8fa2a2973c1fdd Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 23 Jul 2009 21:13:03 +0200 Subject: centralize the code that needs to deal with transaction_id There were many places in the code where we had to explicitly reference the transaction_id and put it into a packet. By introducing and optional gsm_trans parameter to gsm48_sendmsg(), we can implement this code once rather than dozens of time. --- openbsc/include/openbsc/gsm_04_08.h | 3 +- openbsc/src/gsm_04_08.c | 120 ++++++++++++------------------------ 2 files changed, 43 insertions(+), 80 deletions(-) diff --git a/openbsc/include/openbsc/gsm_04_08.h b/openbsc/include/openbsc/gsm_04_08.h index 2fe23d1fc..2ed95f326 100644 --- a/openbsc/include/openbsc/gsm_04_08.h +++ b/openbsc/include/openbsc/gsm_04_08.h @@ -646,6 +646,7 @@ struct msgb; struct gsm_bts; struct gsm_subscriber; struct gsm_network; +struct gsm_trans; /* config options controlling the behaviour of the lower leves */ void gsm0408_allow_everyone(int allow); @@ -659,7 +660,7 @@ enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra); int gsm48_tx_mm_info(struct gsm_lchan *lchan); struct msgb *gsm48_msgb_alloc(void); -int gsm48_sendmsg(struct msgb *msg); +int gsm48_sendmsg(struct msgb *msg, struct gsm_trans *trans); int generate_mid_from_tmsi(u_int8_t *buf, u_int32_t tmsi); int gsm48_send_rr_release(struct gsm_lchan *lchan); diff --git a/openbsc/src/gsm_04_08.c b/openbsc/src/gsm_04_08.c index 507daf998..ab9a4085b 100644 --- a/openbsc/src/gsm_04_08.c +++ b/openbsc/src/gsm_04_08.c @@ -983,10 +983,18 @@ struct msgb *gsm48_msgb_alloc(void) "GSM 04.08"); } -int gsm48_sendmsg(struct msgb *msg) +int gsm48_sendmsg(struct msgb *msg, struct gsm_trans *trans) { + struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data; + + /* if we get passed a transaction reference, do some common + * work that the caller no longer has to do */ + if (trans) { + gh->proto_discr = trans->protocol | trans->transaction_id; + msg->lchan = trans->lchan; + } + if (msg->lchan) { - struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data; msg->trx = msg->lchan->ts->trx; if ((gh->proto_discr & GSM48_PDISC_MASK) == GSM48_PDISC_CC) @@ -1022,7 +1030,7 @@ int gsm0408_loc_upd_rej(struct gsm_lchan *lchan, u_int8_t cause) DEBUGP(DMM, "-> LOCATION UPDATING REJECT on channel: %d\n", lchan->nr); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, NULL); } /* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */ @@ -1050,7 +1058,7 @@ int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi) DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n"); - ret = gsm48_sendmsg(msg); + ret = gsm48_sendmsg(msg, NULL); ret = gsm48_tx_mm_info(lchan); @@ -1121,7 +1129,7 @@ static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type) gh->msg_type = GSM48_MT_MM_ID_REQ; gh->data[0] = id_type; - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, NULL); } #define MI_SIZE 32 @@ -1302,7 +1310,7 @@ int gsm48_tx_chan_mode_modify(struct gsm_lchan *lchan, u_int8_t mode) cmm->chan_desc.h0.arfcn_low = arfcn & 0xff; cmm->mode = mode; - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, NULL); } #if 0 @@ -1382,7 +1390,7 @@ int gsm48_tx_mm_info(struct gsm_lchan *lchan) ptr8[7] |= 0x80; #endif - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, NULL); } static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan) @@ -1408,7 +1416,7 @@ static int gsm48_tx_mm_serv_rej(struct gsm_lchan *lchan, gh->data[0] = value; DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, NULL); } @@ -1778,7 +1786,7 @@ int gsm48_send_rr_release(struct gsm_lchan *lchan) lchan->nr, lchan->type); /* Send actual release request to MS */ - gsm48_sendmsg(msg); + gsm48_sendmsg(msg, NULL); /* Deactivate the SACCH on the BTS side */ return rsl_deact_sacch(lchan); @@ -1808,8 +1816,6 @@ static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg) struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); u_int8_t *cause, *call_state; - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_STATUS; cause = msgb_put(msg, 3); @@ -1820,7 +1826,7 @@ static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg) call_state = msgb_put(msg, 1); call_state[0] = 0xc0 | 0x00; - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_tx_simple(struct gsm_lchan *lchan, @@ -1834,7 +1840,7 @@ static int gsm48_tx_simple(struct gsm_lchan *lchan, gh->proto_discr = pdisc; gh->msg_type = msg_type; - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, NULL); } static void gsm48_stop_cc_timer(struct gsm_trans *trans) @@ -2294,8 +2300,6 @@ static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg) } } - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_SETUP; gsm48_start_cc_timer(trans, 0x303, GSM48_T303); @@ -2327,7 +2331,7 @@ static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg) new_cc_state(trans, GSM_CSTATE_CALL_PRESENT); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg) @@ -2381,8 +2385,6 @@ static int gsm48_cc_tx_call_proc(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_CALL_PROC; new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC); @@ -2397,7 +2399,7 @@ static int gsm48_cc_tx_call_proc(struct gsm_trans *trans, void *arg) if (proceeding->fields & MNCC_F_PROGRESS) encode_progress(msg, 0, &proceeding->progress); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg) @@ -2445,8 +2447,6 @@ static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_ALERTING; /* facility */ @@ -2461,7 +2461,7 @@ static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg) new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg) @@ -2470,8 +2470,6 @@ static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_PROGRESS; /* progress */ @@ -2480,7 +2478,7 @@ static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg) if (progress->fields & MNCC_F_USERUSER) encode_useruser(msg, 0, &progress->useruser); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg) @@ -2489,8 +2487,6 @@ static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_CONNECT; gsm48_stop_cc_timer(trans); @@ -2511,7 +2507,7 @@ static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg) new_cc_state(trans, GSM_CSTATE_CONNECT_IND); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg) @@ -2578,13 +2574,11 @@ static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_CONNECT_ACK; new_cc_state(trans, GSM_CSTATE_ACTIVE); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg) @@ -2646,8 +2640,6 @@ static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_DISCONNECT; gsm48_stop_cc_timer(trans); @@ -2674,7 +2666,7 @@ static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg) new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg) @@ -2739,8 +2731,6 @@ static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_RELEASE; trans->callref = 0; @@ -2764,7 +2754,7 @@ static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg) if (trans->cc.state != GSM_CSTATE_RELEASE_REQ) new_cc_state(trans, GSM_CSTATE_RELEASE_REQ); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg) @@ -2833,8 +2823,6 @@ static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_RELEASE_COMPL; trans->callref = 0; @@ -2853,7 +2841,7 @@ static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg) trans_free(trans); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg) @@ -2888,14 +2876,12 @@ static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_FACILITY; /* facility */ encode_facility(msg, 1, &fac->facility); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg) @@ -2912,11 +2898,9 @@ static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_HOLD_ACK; - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg) @@ -2925,8 +2909,6 @@ static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_HOLD_REJ; /* cause */ @@ -2935,7 +2917,7 @@ static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg) else encode_cause(msg, 1, &default_cause); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg) @@ -2953,11 +2935,9 @@ static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_RETR_ACK; - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg) @@ -2966,8 +2946,6 @@ static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_RETR_REJ; /* cause */ @@ -2976,7 +2954,7 @@ static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg) else encode_cause(msg, 1, &default_cause); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg) @@ -3005,15 +2983,13 @@ static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_START_DTMF_ACK; /* keypad */ if (dtmf->fields & MNCC_F_KEYPAD) encode_keypad(msg, dtmf->keypad); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg) @@ -3022,8 +2998,6 @@ static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_START_DTMF_REJ; /* cause */ @@ -3032,7 +3006,7 @@ static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg) else encode_cause(msg, 1, &default_cause); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg) @@ -3040,11 +3014,9 @@ static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK; - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg) @@ -3085,8 +3057,6 @@ static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_MODIFY; gsm48_start_cc_timer(trans, 0x323, GSM48_T323); @@ -3096,7 +3066,7 @@ static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg) new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg) @@ -3129,8 +3099,6 @@ static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_MODIFY_COMPL; /* bearer capability */ @@ -3138,7 +3106,7 @@ static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg) new_cc_state(trans, GSM_CSTATE_ACTIVE); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg) @@ -3177,8 +3145,6 @@ static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_MODIFY_REJECT; /* bearer capability */ @@ -3188,7 +3154,7 @@ static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg) new_cc_state(trans, GSM_CSTATE_ACTIVE); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg) @@ -3197,14 +3163,12 @@ static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_NOTIFY; /* notify */ encode_notify(msg, notify->notify); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg) @@ -3229,8 +3193,6 @@ static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg) struct msgb *msg = gsm48_msgb_alloc(); struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); - gh->proto_discr = GSM48_PDISC_CC | trans->transaction_id; - msg->lchan = trans->lchan; gh->msg_type = GSM48_MT_CC_USER_INFO; /* user-user */ @@ -3240,7 +3202,7 @@ static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg) if (user->more) encode_more(msg); - return gsm48_sendmsg(msg); + return gsm48_sendmsg(msg, trans); } static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg) -- cgit v1.2.3