mirror of
				https://gitea.osmocom.org/cellular-infrastructure/osmo-mgw.git
				synced 2025-11-03 21:43:32 +00:00 
			
		
		
		
	move to hex TMSI representation
In OpenBSC, we traditionally displayed a TMSI in its integer representation, which is quite unusual in the telecom world. A TMSI is normally printed as a series of 8 hex digits. This patch aligns OpenBSC with the telecom industry standard. Signed-off-by: Vadim Yanitskiy <axilirator@gmail.com>
This commit is contained in:
		
				
					committed by
					
						
						Harald Welte
					
				
			
			
				
	
			
			
			
						parent
						
							d2fa7a509a
						
					
				
				
					commit
					044fbe6568
				
			@@ -14,7 +14,7 @@
 | 
			
		||||
 | 
			
		||||
#define GSM_SUBSCRIBER_FIRST_CONTACT	0x00000001
 | 
			
		||||
/* gprs_sgsn.h defines additional flags including and above bit 16 (0x10000) */
 | 
			
		||||
#define tmsi_from_string(str) strtoul(str, NULL, 10)
 | 
			
		||||
#define tmsi_from_string(str) strtoul(str + 2, NULL, 16)
 | 
			
		||||
 | 
			
		||||
#define GSM_SUBSCRIBER_NO_EXPIRATION	0x0
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -893,9 +893,10 @@ struct gsm_subscriber *db_get_subscriber(enum gsm_subscriber_field field,
 | 
			
		||||
	subscr->id = dbi_result_get_ulonglong(result, "id");
 | 
			
		||||
 | 
			
		||||
	db_set_from_query(subscr, result);
 | 
			
		||||
	DEBUGP(DDB, "Found Subscriber: ID %llu, IMSI %s, NAME '%s', TMSI %u, EXTEN '%s', LAC %hu, AUTH %u\n",
 | 
			
		||||
		subscr->id, subscr->imsi, subscr->name, subscr->tmsi, subscr->extension,
 | 
			
		||||
		subscr->lac, subscr->authorized);
 | 
			
		||||
	DEBUGP(DDB, "Found Subscriber: ID %llu, IMSI %s, NAME '%s', "
 | 
			
		||||
		"TMSI 0x%08x, EXTEN '%s', LAC %hu, AUTH %u\n",
 | 
			
		||||
		subscr->id, subscr->imsi, subscr->name, subscr->tmsi,
 | 
			
		||||
		subscr->extension, subscr->lac, subscr->authorized);
 | 
			
		||||
	dbi_result_free(result);
 | 
			
		||||
 | 
			
		||||
	get_equipment_by_subscr(subscr);
 | 
			
		||||
@@ -935,7 +936,7 @@ int db_subscriber_update(struct gsm_subscriber *subscr)
 | 
			
		||||
int db_sync_subscriber(struct gsm_subscriber *subscriber)
 | 
			
		||||
{
 | 
			
		||||
	dbi_result result;
 | 
			
		||||
	char tmsi[14];
 | 
			
		||||
	char tmsi[11];
 | 
			
		||||
	char *q_tmsi, *q_name, *q_extension;
 | 
			
		||||
 | 
			
		||||
	dbi_conn_quote_string_copy(conn, 
 | 
			
		||||
@@ -944,7 +945,7 @@ int db_sync_subscriber(struct gsm_subscriber *subscriber)
 | 
			
		||||
				   subscriber->extension, &q_extension);
 | 
			
		||||
	
 | 
			
		||||
	if (subscriber->tmsi != GSM_RESERVED_TMSI) {
 | 
			
		||||
		sprintf(tmsi, "%u", subscriber->tmsi);
 | 
			
		||||
		sprintf(tmsi, "0x%08x", subscriber->tmsi);
 | 
			
		||||
		dbi_conn_quote_string_copy(conn,
 | 
			
		||||
				   tmsi,
 | 
			
		||||
				   &q_tmsi);
 | 
			
		||||
@@ -1194,7 +1195,7 @@ int db_subscriber_expire(void *priv, void (*callback)(void *priv, long long unsi
 | 
			
		||||
int db_subscriber_alloc_tmsi(struct gsm_subscriber *subscriber)
 | 
			
		||||
{
 | 
			
		||||
	dbi_result result = NULL;
 | 
			
		||||
	char tmsi[14];
 | 
			
		||||
	char tmsi[11];
 | 
			
		||||
	char *tmsi_quoted;
 | 
			
		||||
 | 
			
		||||
	for (;;) {
 | 
			
		||||
@@ -1205,7 +1206,7 @@ int db_subscriber_alloc_tmsi(struct gsm_subscriber *subscriber)
 | 
			
		||||
		if (subscriber->tmsi == GSM_RESERVED_TMSI)
 | 
			
		||||
			continue;
 | 
			
		||||
 | 
			
		||||
		sprintf(tmsi, "%u", subscriber->tmsi);
 | 
			
		||||
		sprintf(tmsi, "0x%08x", subscriber->tmsi);
 | 
			
		||||
		dbi_conn_quote_string_copy(conn, tmsi, &tmsi_quoted);
 | 
			
		||||
		result = dbi_conn_queryf(conn,
 | 
			
		||||
			"SELECT * FROM Subscriber "
 | 
			
		||||
 
 | 
			
		||||
@@ -200,7 +200,7 @@ int main()
 | 
			
		||||
	alice->lac=42;
 | 
			
		||||
	db_sync_subscriber(alice);
 | 
			
		||||
	/* Get by TMSI */
 | 
			
		||||
	snprintf(scratch_str, sizeof(scratch_str), "%"PRIu32, alice->tmsi);
 | 
			
		||||
	snprintf(scratch_str, sizeof(scratch_str), "0x%08x", alice->tmsi);
 | 
			
		||||
	alice_db = db_get_subscriber(GSM_SUBSCRIBER_TMSI, scratch_str);
 | 
			
		||||
	COMPARE(alice, alice_db);
 | 
			
		||||
	SUBSCR_PUT(alice_db);
 | 
			
		||||
@@ -227,7 +227,7 @@ int main()
 | 
			
		||||
	db_subscriber_assoc_imei(alice, "1234567890");
 | 
			
		||||
	db_subscriber_assoc_imei(alice, "6543560920");
 | 
			
		||||
	/* Get by TMSI */
 | 
			
		||||
	snprintf(scratch_str, sizeof(scratch_str), "%"PRIu32, alice->tmsi);
 | 
			
		||||
	snprintf(scratch_str, sizeof(scratch_str), "0x%08x", alice->tmsi);
 | 
			
		||||
	alice_db = db_get_subscriber(GSM_SUBSCRIBER_TMSI, scratch_str);
 | 
			
		||||
	COMPARE(alice, alice_db);
 | 
			
		||||
	SUBSCR_PUT(alice_db);
 | 
			
		||||
 
 | 
			
		||||
@@ -93,7 +93,7 @@ static void test_mi_functionality(void)
 | 
			
		||||
	/* tmsi code */
 | 
			
		||||
	mi_len = gsm48_generate_mid_from_tmsi(mi, tmsi);
 | 
			
		||||
	gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len - 2);
 | 
			
		||||
	COMPARE((uint32_t)strtoul(mi_parsed, NULL, 10), ==, tmsi);
 | 
			
		||||
	COMPARE((uint32_t)tmsi_from_string(mi_parsed), ==, tmsi);
 | 
			
		||||
 | 
			
		||||
	/* imsi code */
 | 
			
		||||
	mi_len = gsm48_generate_mid_from_imsi(mi, imsi_odd);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user