summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-03-04 10:55:40 +0100
committerHarald Welte <laforge@gnumonks.org>2010-03-04 10:55:40 +0100
commitafedeabd919972dcc3968b0d9743dc0b1a80774c (patch)
tree0626cdf58fa03d855f30ed6bb4e56a1a243e3285
parentfbc5ca080beedf8ca032cdd409db30838843f79b (diff)
move some gsm48 utility functions to libosmocore
* gsm48_generate_lai() gsm48_generate_mid_from_tmsi() gsm48_generate_mid_from_imsi() * gsm48_cc_msg_names[]
-rw-r--r--openbsc/include/openbsc/gsm_04_08.h6
-rw-r--r--openbsc/include/openbsc/gsm_data.h3
-rw-r--r--openbsc/src/gsm_04_08.c4
-rw-r--r--openbsc/src/gsm_04_08_utils.c160
-rw-r--r--openbsc/src/system_information.c18
-rw-r--r--openbsc/tests/gsm0408/gsm0408_test.c8
6 files changed, 19 insertions, 180 deletions
diff --git a/openbsc/include/openbsc/gsm_04_08.h b/openbsc/include/openbsc/gsm_04_08.h
index 70eb8f92e..c4018cd11 100644
--- a/openbsc/include/openbsc/gsm_04_08.h
+++ b/openbsc/include/openbsc/gsm_04_08.h
@@ -16,8 +16,6 @@ struct gsm_trans;
void gsm0408_allow_everyone(int allow);
int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id);
-void gsm0408_generate_lai(struct gsm48_loc_area_id *lai48, u_int16_t mcc,
- u_int16_t mnc, u_int16_t lac);
enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci);
enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci);
@@ -26,8 +24,6 @@ int gsm48_tx_mm_auth_req(struct gsm_lchan *lchan, u_int8_t *rand, int key_seq);
int gsm48_tx_mm_auth_rej(struct gsm_lchan *lchan);
struct msgb *gsm48_msgb_alloc(void);
int gsm48_sendmsg(struct msgb *msg, struct gsm_trans *trans);
-int gsm48_generate_mid_from_tmsi(u_int8_t *buf, u_int32_t tmsi);
-int gsm48_generate_mid_from_imsi(u_int8_t *buf, const char* imsi);
int gsm48_mi_to_string(char *string, const int str_len, const u_int8_t *mi, const int mi_len);
int gsm48_send_rr_release(struct gsm_lchan *lchan);
@@ -48,8 +44,6 @@ int encode_bcd_number(u_int8_t *bcd_lv, u_int8_t max_len,
int decode_bcd_number(char *output, int output_len, const u_int8_t *bcd_lv,
int h_len);
-extern const char *gsm0408_cc_msg_names[];
-
int send_siemens_mrpci(struct gsm_lchan *lchan, u_int8_t *classmark2_lv);
int gsm48_paging_extract_mi(struct msgb *msg, char *mi_string, u_int8_t *mi_type);
int gsm48_handle_paging_resp(struct msgb *msg, struct gsm_subscriber *subscr);
diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h
index 717c81b77..53ba8fff1 100644
--- a/openbsc/include/openbsc/gsm_data.h
+++ b/openbsc/include/openbsc/gsm_data.h
@@ -646,9 +646,6 @@ struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
struct gsm_bts *start_bts);
-char *gsm_band_name(enum gsm_band band);
-enum gsm_band gsm_band_parse(const char *mhz);
-
extern void *tall_bsc_ctx;
extern int ipacc_rtp_direct;
diff --git a/openbsc/src/gsm_04_08.c b/openbsc/src/gsm_04_08.c
index 242c09faa..a41420c18 100644
--- a/openbsc/src/gsm_04_08.c
+++ b/openbsc/src/gsm_04_08.c
@@ -748,7 +748,7 @@ int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi)
gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT;
lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
- gsm0408_generate_lai(lai, bts->network->country_code,
+ gsm48_generate_lai(lai, bts->network->country_code,
bts->network->network_code, bts->location_area_code);
mid = msgb_put(msg, GSM48_MID_TMSI_LEN);
@@ -3349,7 +3349,7 @@ static int gsm0408_rcv_cc(struct msgb *msg)
"Received '%s' from MS in state %d (%s)\n",
lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr,
transaction_id, (lchan->subscr)?(lchan->subscr->extension):"-",
- gsm0408_cc_msg_names[msg_type], trans?(trans->cc.state):0,
+ gsm48_cc_msg_names[msg_type], trans?(trans->cc.state):0,
cc_state_names[trans?(trans->cc.state):0]);
/* Create transaction */
diff --git a/openbsc/src/gsm_04_08_utils.c b/openbsc/src/gsm_04_08_utils.c
index 53c57cae2..68f34f409 100644
--- a/openbsc/src/gsm_04_08_utils.c
+++ b/openbsc/src/gsm_04_08_utils.c
@@ -29,6 +29,7 @@
#include <netinet/in.h>
#include <osmocore/msgb.h>
+#include <osmocore/gsm48.h>
#include <openbsc/debug.h>
#include <openbsc/gsm_04_08.h>
#include <openbsc/transaction.h>
@@ -42,75 +43,6 @@
* or should OpenBSC always act as RTP relay/proxy in between (0) ? */
int ipacc_rtp_direct = 1;
-
-const char *gsm0408_cc_msg_names[] = {
- "unknown 0x00",
- "ALERTING",
- "CALL_PROC",
- "PROGRESS",
- "ESTAB",
- "SETUP",
- "ESTAB_CONF",
- "CONNECT",
- "CALL_CONF",
- "START_CC",
- "unknown 0x0a",
- "RECALL",
- "unknown 0x0c",
- "unknown 0x0d",
- "EMERG_SETUP",
- "CONNECT_ACK",
- "USER_INFO",
- "unknown 0x11",
- "unknown 0x12",
- "MODIFY_REJECT",
- "unknown 0x14",
- "unknown 0x15",
- "unknown 0x16",
- "MODIFY",
- "HOLD",
- "HOLD_ACK",
- "HOLD_REJ",
- "unknown 0x1b",
- "RETR",
- "RETR_ACK",
- "RETR_REJ",
- "MODIFY_COMPL",
- "unknown 0x20",
- "unknown 0x21",
- "unknown 0x22",
- "unknown 0x23",
- "unknown 0x24",
- "DISCONNECT",
- "unknown 0x26",
- "unknown 0x27",
- "unknown 0x28",
- "unknown 0x29",
- "RELEASE_COMPL",
- "unknown 0x2b",
- "unknown 0x2c",
- "RELEASE",
- "unknown 0x2e",
- "unknown 0x2f",
- "unknown 0x30",
- "STOP_DTMF",
- "STOP_DTMF_ACK",
- "unknown 0x33",
- "STATUS_ENQ",
- "START_DTMF",
- "START_DTMF_ACK",
- "START_DTMF_REJ",
- "unknown 0x38",
- "CONG_CTRL",
- "FACILITY",
- "unknown 0x3b",
- "STATUS",
- "unknown 0x3c",
- "NOTIFY",
- "unknown 0x3f",
-};
-
-
struct msgb *gsm48_msgb_alloc(void)
{
return msgb_alloc_headroom(GSM48_ALLOC_SIZE, GSM48_ALLOC_HEADROOM,
@@ -136,7 +68,7 @@ int gsm48_sendmsg(struct msgb *msg, struct gsm_trans *trans)
"Sending '%s' to MS.\n", msg->trx->bts->nr,
msg->trx->nr, msg->lchan->ts->nr,
gh->proto_discr & 0xf0,
- gsm0408_cc_msg_names[gh->msg_type & 0x3f]);
+ gsm48_cc_msg_names[gh->msg_type & 0x3f]);
else
DEBUGP(DCC, "(bts %d trx %d ts %d pd %02x) "
"Sending 0x%02x to MS.\n", msg->trx->bts->nr,
@@ -149,94 +81,6 @@ int gsm48_sendmsg(struct msgb *msg, struct gsm_trans *trans)
return rsl_data_request(msg, 0);
}
-static void to_bcd(u_int8_t *bcd, u_int16_t val)
-{
- bcd[2] = val % 10;
- val = val / 10;
- bcd[1] = val % 10;
- val = val / 10;
- bcd[0] = val % 10;
- val = val / 10;
-}
-
-static char bcd2char(u_int8_t bcd)
-{
- if (bcd < 0xa)
- return '0' + bcd;
- else
- return 'A' + (bcd - 0xa);
-}
-
-/* only works for numbers in ascci */
-static u_int8_t char2bcd(char c)
-{
- return c - 0x30;
-}
-
-
-void gsm0408_generate_lai(struct gsm48_loc_area_id *lai48, u_int16_t mcc,
- u_int16_t mnc, u_int16_t lac)
-{
- u_int8_t bcd[3];
-
- to_bcd(bcd, mcc);
- lai48->digits[0] = bcd[0] | (bcd[1] << 4);
- lai48->digits[1] = bcd[2];
-
- to_bcd(bcd, mnc);
- /* FIXME: do we need three-digit MNC? See Table 10.5.3 */
-#if 0
- lai48->digits[1] |= bcd[2] << 4;
- lai48->digits[2] = bcd[0] | (bcd[1] << 4);
-#else
- lai48->digits[1] |= 0xf << 4;
- lai48->digits[2] = bcd[1] | (bcd[2] << 4);
-#endif
-
- lai48->lac = htons(lac);
-}
-
-int gsm48_generate_mid_from_tmsi(u_int8_t *buf, u_int32_t tmsi)
-{
- u_int32_t *tptr = (u_int32_t *) &buf[3];
-
- buf[0] = GSM48_IE_MOBILE_ID;
- buf[1] = GSM48_TMSI_LEN;
- buf[2] = 0xf0 | GSM_MI_TYPE_TMSI;
- *tptr = htonl(tmsi);
-
- return 7;
-}
-
-int gsm48_generate_mid_from_imsi(u_int8_t *buf, const char *imsi)
-{
- unsigned int length = strlen(imsi), i, off = 0;
- u_int8_t odd = (length & 0x1) == 1;
-
- buf[0] = GSM48_IE_MOBILE_ID;
- buf[2] = char2bcd(imsi[0]) << 4 | GSM_MI_TYPE_IMSI | (odd << 3);
-
- /* if the length is even we will fill half of the last octet */
- if (odd)
- buf[1] = (length + 1) >> 1;
- else
- buf[1] = (length + 2) >> 1;
-
- for (i = 1; i < buf[1]; ++i) {
- u_int8_t lower, upper;
-
- lower = char2bcd(imsi[++off]);
- if (!odd && off + 1 == length)
- upper = 0x0f;
- else
- upper = char2bcd(imsi[++off]) & 0x0f;
-
- buf[2 + i] = (upper << 4) | lower;
- }
-
- return 2 + buf[1];
-}
-
/* Section 9.1.8 / Table 9.9 */
struct chreq {
u_int8_t val;
diff --git a/openbsc/src/system_information.c b/openbsc/src/system_information.c
index 36dc6b901..a9df0ba26 100644
--- a/openbsc/src/system_information.c
+++ b/openbsc/src/system_information.c
@@ -287,9 +287,9 @@ static int generate_si3(u_int8_t *output, struct gsm_bts *bts)
si3->header.system_information = GSM48_MT_RR_SYSINFO_3;
si3->cell_identity = htons(bts->cell_identity);
- gsm0408_generate_lai(&si3->lai, bts->network->country_code,
- bts->network->network_code,
- bts->location_area_code);
+ gsm48_generate_lai(&si3->lai, bts->network->country_code,
+ bts->network->network_code,
+ bts->location_area_code);
si3->control_channel_desc = bts->si_common.chan_desc;
si3->cell_options = bts->si_common.cell_options;
si3->cell_sel_par = bts->si_common.cell_sel_par;
@@ -319,9 +319,9 @@ static int generate_si4(u_int8_t *output, struct gsm_bts *bts)
si4->header.skip_indicator = 0;
si4->header.system_information = GSM48_MT_RR_SYSINFO_4;
- gsm0408_generate_lai(&si4->lai, bts->network->country_code,
- bts->network->network_code,
- bts->location_area_code);
+ gsm48_generate_lai(&si4->lai, bts->network->country_code,
+ bts->network->network_code,
+ bts->location_area_code);
si4->cell_sel_par = bts->si_common.cell_sel_par;
si4->rach_control = bts->si_common.rach_control;
@@ -384,9 +384,9 @@ static int generate_si6(u_int8_t *output, struct gsm_bts *bts)
si6->skip_indicator = 0;
si6->system_information = GSM48_MT_RR_SYSINFO_6;
si6->cell_identity = htons(bts->cell_identity);
- gsm0408_generate_lai(&si6->lai, bts->network->country_code,
- bts->network->network_code,
- bts->location_area_code);
+ gsm48_generate_lai(&si6->lai, bts->network->country_code,
+ bts->network->network_code,
+ bts->location_area_code);
si6->cell_options = bts->si_common.cell_options;
si6->ncc_permitted = bts->si_common.ncc_permitted;
diff --git a/openbsc/tests/gsm0408/gsm0408_test.c b/openbsc/tests/gsm0408/gsm0408_test.c
index bbf812965..287d4ee99 100644
--- a/openbsc/tests/gsm0408/gsm0408_test.c
+++ b/openbsc/tests/gsm0408/gsm0408_test.c
@@ -23,6 +23,8 @@
#include <stdio.h>
#include <stdlib.h>
+#include <arpa/inet.h>
+
#include <openbsc/gsm_04_08.h>
#include <openbsc/gsm_subscriber.h>
#include <openbsc/debug.h>
@@ -52,13 +54,13 @@ static void test_location_area_identifier(void)
* Test the default/test setup. Coming from
* bsc_hack.c dumps
*/
- gsm0408_generate_lai(&lai48, 1, 1, 1);
+ gsm48_generate_lai(&lai48, 1, 1, 1);
COMPARE(lai48.digits[0], ==, 0x00);
COMPARE(lai48.digits[1], ==, 0xF1);
COMPARE(lai48.digits[2], ==, 0x10);
COMPARE(lai48.lac, ==, htons(0x0001));
- gsm0408_generate_lai(&lai48, 602, 1, 15);
+ gsm48_generate_lai(&lai48, 602, 1, 15);
COMPARE(lai48.digits[0], ==, 0x06);
COMPARE(lai48.digits[1], ==, 0xF2);
COMPARE(lai48.digits[2], ==, 0x10);
@@ -97,6 +99,8 @@ int main(int argc, char** argv)
{
test_location_area_identifier();
test_mi_functionality();
+
+ exit(0);
}