usim_data.c 21.6 KB
Newer Older
Lionel Gauthier's avatar
GPLv3  
Lionel Gauthier committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*******************************************************************************
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.


    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
Cedric Roux's avatar
 
Cedric Roux committed
15

Lionel Gauthier's avatar
GPLv3  
Lionel Gauthier committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
   included in this distribution in the file called "COPYING". If not,
   see <http://www.gnu.org/licenses/>.

  Contact Information
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr

  Address      : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France.

 *******************************************************************************/
/*****************************************************************************
Cedric Roux's avatar
 
Cedric Roux committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
Source		usim_data.c

Version		0.1

Date		2012/10/31

Product		USIM data generator

Subsystem	USIM data generator main process

Author		Frederic Maurel

Description	Implements the utility used to generate data stored in the
		USIM application

*****************************************************************************/

#include "network.h"

#include "usim_api.h"
#include "memory.h"

#include <stdio.h>	// perror, printf
#include <stdlib.h>	// exit
#include <string.h>	// memset, memcpy, strncpy

56 57 58
//#define SELECTED_PLMN SFR1
#define SELECTED_PLMN FCT1

Cedric Roux's avatar
 
Cedric Roux committed
59 60 61 62 63 64
/****************************************************************************/
/****************  E X T E R N A L    D E F I N I T I O N S  ****************/
/****************************************************************************/

#define KSI			USIM_KSI_NOT_AVAILABLE
#define KSI_ASME		USIM_KSI_NOT_AVAILABLE
Lionel Gauthier's avatar
 
Lionel Gauthier committed
65
#define INT_ALGO		USIM_INT_EIA1
66
#define ENC_ALGO		USIM_ENC_EEA0
Cedric Roux's avatar
 
Cedric Roux committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
#define SECURITY_ALGORITHMS	(ENC_ALGO | INT_ALGO)

#define MIN_TAC			0x0000
#define MAX_TAC			0xFFFE

#define DEFAULT_TMSI		0x0000000D
#define DEFAULT_P_TMSI		0x0000000D
#define DEFAULT_M_TMSI		0x0000000D
#define DEFAULT_LAC		0xFFFE
#define DEFAULT_RAC		0x01
#define DEFAULT_TAC		0x0001

#define DEFAULT_MME_ID		0x0102
#define DEFAULT_MME_CODE	0x0F

#define PRINT_PLMN_DIGIT(d)	if ((d) != 0xf) printf("%u", (d))

#define PRINT_PLMN(plmn)		\
    PRINT_PLMN_DIGIT((plmn).MCCdigit1);	\
    PRINT_PLMN_DIGIT((plmn).MCCdigit2);	\
    PRINT_PLMN_DIGIT((plmn).MCCdigit3);	\
    PRINT_PLMN_DIGIT((plmn).MNCdigit1);	\
    PRINT_PLMN_DIGIT((plmn).MNCdigit2);	\
    PRINT_PLMN_DIGIT((plmn).MNCdigit3)

/****************************************************************************/
/*******************  L O C A L    D E F I N I T I O N S  *******************/
/****************************************************************************/

static void _display_usage(const char* command);

static void _display_usim_data(const usim_data_t* data);

/****************************************************************************/
/******************  E X P O R T E D    F U N C T I O N S  ******************/
/****************************************************************************/

int main (int argc, const char* argv[])
{
    int rc;
    usim_data_t usim_data;

    unsigned char gen_data;

    /*
     * Read command line parameters
     */
    if (argc != 2) {
	fprintf(stderr, "Invalid parameter\n");
	_display_usage(argv[0]);
117
	exit(EXIT_FAILURE);
Cedric Roux's avatar
 
Cedric Roux committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
    }
    else if ( (strcmp(argv[1], "--gen") == 0) ||
	      (strcmp(argv[1], "-g") == 0) ) {
	/* Generate USIM data files */
	gen_data = TRUE;
    }
    else if ( (strcmp(argv[1], "--print") == 0) ||
	      (strcmp(argv[1], "-p") == 0) ) {
	/* Display content of USIM data files */
	gen_data = FALSE;
    }
    else {
	/* Display usage */
	_display_usage(argv[0]);
	exit(EXIT_SUCCESS);
    }

    if (gen_data)
    {
	/*
	 * Initialize USIM data
	 */
	memset(&usim_data, 0, sizeof(usim_data_t));
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

//#if (SELECTED_PLMN == FCT1)
#if 1
    /*
     * International Mobile Subscriber Identity
     * IMSI = MCC + MNC + MSIN = 310 (USA) + 028 (UNKNOWN) + 90832150
     */
#warning "IMSI 310.028.90832150"
    usim_data.imsi.length = 8;
    usim_data.imsi.u.num.parity = EVEN_PARITY;      // Parity: even
    usim_data.imsi.u.num.digit1 = 3;                // MCC digit 1
    usim_data.imsi.u.num.digit2 = 1;                // MCC digit 2
    usim_data.imsi.u.num.digit3 = 0;                // MCC digit 3
    usim_data.imsi.u.num.digit4 = 0;                // MNC digit 1
    usim_data.imsi.u.num.digit5 = 2;                // MNC digit 2
    usim_data.imsi.u.num.digit6 = 8;                // MNC digit 3
    usim_data.imsi.u.num.digit7 = 9;
    usim_data.imsi.u.num.digit8 = 0;
    usim_data.imsi.u.num.digit9 = 8;
    usim_data.imsi.u.num.digit10 = 3;
    usim_data.imsi.u.num.digit11 = 2;
    usim_data.imsi.u.num.digit12 = 1;
    usim_data.imsi.u.num.digit13 = 5;
    usim_data.imsi.u.num.digit14 = 0;
    usim_data.imsi.u.num.digit15 = 0b1111;
#else
Cedric Roux's avatar
 
Cedric Roux committed
167 168 169 170
	/*
	 * International Mobile Subscriber Identity
	 * IMSI = MCC + MNC + MSIN = 208 (France) + 10 (SFR) + 00001234
	 */
171 172 173
#warning "IMSI 208.10.00001234"
/*	usim_data.imsi.length = 8;
    usim_data.imsi.u.num.parity = EVEN_PARITY;      // Parity: even
winckel's avatar
winckel committed
174 175 176 177 178
	usim_data.imsi.u.num.digit1 = 2;                // MCC digit 1
	usim_data.imsi.u.num.digit2 = 0;                // MCC digit 2
	usim_data.imsi.u.num.digit3 = 8;                // MCC digit 3
	usim_data.imsi.u.num.digit4 = 1;                // MNC digit 1
	usim_data.imsi.u.num.digit5 = 0;                // MNC digit 2
179
	usim_data.imsi.u.num.digit6 = 0b1111;     // MNC digit 3
Cedric Roux's avatar
 
Cedric Roux committed
180 181 182 183 184 185 186 187
	usim_data.imsi.u.num.digit7 = 0;
	usim_data.imsi.u.num.digit8 = 0;
	usim_data.imsi.u.num.digit9 = 0;
	usim_data.imsi.u.num.digit10 = 0;
	usim_data.imsi.u.num.digit11 = 1;
	usim_data.imsi.u.num.digit12 = 2;
	usim_data.imsi.u.num.digit13 = 3;
	usim_data.imsi.u.num.digit14 = 4;
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
	usim_data.imsi.u.num.digit15 = 0b1111;*/
    usim_data.imsi.length = 8;
    usim_data.imsi.u.num.parity = 0x0;  // Type of identity = IMSI, even
    usim_data.imsi.u.num.digit1 = 2;    // MCC digit 1
    usim_data.imsi.u.num.digit2 = 0;    // MCC digit 2
    usim_data.imsi.u.num.digit3 = 8;    // MCC digit 3
    usim_data.imsi.u.num.digit4 = 1;    // MNC digit 1
    usim_data.imsi.u.num.digit5 = 0;    // MNC digit 2
    usim_data.imsi.u.num.digit6 = 0;
    usim_data.imsi.u.num.digit7 = 0;
    usim_data.imsi.u.num.digit8 = 0;
    usim_data.imsi.u.num.digit9 = 0;
    usim_data.imsi.u.num.digit10 = 0;
    usim_data.imsi.u.num.digit11 = 1;
    usim_data.imsi.u.num.digit12 = 2;
    usim_data.imsi.u.num.digit13 = 3;
    usim_data.imsi.u.num.digit14 = 4;
    usim_data.imsi.u.num.digit15 = 0xF;
#endif
Cedric Roux's avatar
 
Cedric Roux committed
207 208 209 210 211 212
	/*
	 * Ciphering and Integrity Keys
	 */
	usim_data.keys.ksi = KSI;
	memset(&usim_data.keys.ck, 0, USIM_CK_SIZE);
	memset(&usim_data.keys.ik, 0, USIM_IK_SIZE);
winckel's avatar
winckel committed
213

Cedric Roux's avatar
 
Cedric Roux committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227
	/*
	 * Higher Priority PLMN search period
	 */
	usim_data.hpplmn = 0x00;	/* Disable timer */
	/*
	 * List of Forbidden PLMNs
	 */
	for (int i = 0; i < USIM_FPLMN_MAX; i++) {
	    memset(&usim_data.fplmn[i], 0xff, sizeof(plmn_t));
	}
	/*
	 * Location Information
	 */
	usim_data.loci.tmsi = DEFAULT_TMSI;
228
    usim_data.loci.lai.plmn = network_records[SELECTED_PLMN].plmn;
Cedric Roux's avatar
 
Cedric Roux committed
229 230 231 232 233 234 235 236 237
	usim_data.loci.lai.lac = DEFAULT_LAC;
	usim_data.loci.status = USIM_LOCI_NOT_UPDATED;
	/*
	 * Packet Switched Location Information
	 */
	usim_data.psloci.p_tmsi = DEFAULT_P_TMSI;
	usim_data.psloci.signature[0] = 0x01;
	usim_data.psloci.signature[1] = 0x02;
	usim_data.psloci.signature[2] = 0x03;
238
    usim_data.psloci.rai.plmn = network_records[SELECTED_PLMN].plmn;
Cedric Roux's avatar
 
Cedric Roux committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
	usim_data.psloci.rai.lac = DEFAULT_LAC;
	usim_data.psloci.rai.rac = DEFAULT_RAC;
	usim_data.psloci.status = USIM_PSLOCI_NOT_UPDATED;
	/*
	 * Administrative Data
	 */
	usim_data.ad.UE_Operation_Mode = USIM_NORMAL_MODE;
	usim_data.ad.Additional_Info = 0xffff;
	usim_data.ad.MNC_Length = 2;
	/*
	 * EPS NAS security context
	 */
	usim_data.securityctx.length = 52;
	usim_data.securityctx.KSIasme.type = USIM_KSI_ASME_TAG;
	usim_data.securityctx.KSIasme.length = 1;
	usim_data.securityctx.KSIasme.value[0] = KSI_ASME;
	usim_data.securityctx.Kasme.type = USIM_K_ASME_TAG;
	usim_data.securityctx.Kasme.length = USIM_K_ASME_SIZE;
	memset(usim_data.securityctx.Kasme.value, 0,
	       usim_data.securityctx.Kasme.length);
	usim_data.securityctx.ulNAScount.type = USIM_UL_NAS_COUNT_TAG;
	usim_data.securityctx.ulNAScount.length = USIM_UL_NAS_COUNT_SIZE;
	memset(usim_data.securityctx.ulNAScount.value, 0,
	       usim_data.securityctx.ulNAScount.length);
	usim_data.securityctx.dlNAScount.type = USIM_DL_NAS_COUNT_TAG;
	usim_data.securityctx.dlNAScount.length = USIM_DL_NAS_COUNT_SIZE;
	memset(usim_data.securityctx.dlNAScount.value, 0,
	       usim_data.securityctx.dlNAScount.length);
	usim_data.securityctx.algorithmID.type = USIM_INT_ENC_ALGORITHMS_TAG;
	usim_data.securityctx.algorithmID.length = 1;
	usim_data.securityctx.algorithmID.value[0] = SECURITY_ALGORITHMS;
	/*
	 * Subcriber's Number
	 */
	usim_data.msisdn.length = 7;
	usim_data.msisdn.number.ext = 1;
	usim_data.msisdn.number.ton = MSISDN_TON_UNKNOWKN;
	usim_data.msisdn.number.npi = MSISDN_NPI_ISDN_TELEPHONY;
	usim_data.msisdn.number.digit[0].msb = 3;
	usim_data.msisdn.number.digit[0].lsb = 3;
	usim_data.msisdn.number.digit[1].msb = 6;
	usim_data.msisdn.number.digit[1].lsb = 1;
	usim_data.msisdn.number.digit[2].msb = 1;
	usim_data.msisdn.number.digit[2].lsb = 1;
	usim_data.msisdn.number.digit[3].msb = 2;
	usim_data.msisdn.number.digit[3].lsb = 3;
	usim_data.msisdn.number.digit[4].msb = 4;
	usim_data.msisdn.number.digit[4].lsb = 5;
	usim_data.msisdn.number.digit[5].msb = 6;
	usim_data.msisdn.number.digit[5].lsb = 0xf;
	usim_data.msisdn.number.digit[6].msb = 0xf;
	usim_data.msisdn.number.digit[6].lsb = 0xf;
	usim_data.msisdn.number.digit[7].msb = 0xf;
	usim_data.msisdn.number.digit[7].lsb = 0xf;
	usim_data.msisdn.number.digit[8].msb = 0xf;
	usim_data.msisdn.number.digit[8].lsb = 0xf;
	usim_data.msisdn.number.digit[9].msb = 0xf;
	usim_data.msisdn.number.digit[9].lsb = 0xf;
	usim_data.msisdn.conf1_record_id = 0xff;	/* Not used */
	usim_data.msisdn.ext1_record_id = 0xff;		/* Not used */
	/*
	 * PLMN Network Name and Operator PLMN List
	 */
	for (int i = SFR1; i < VDF2; i++) {
	    network_record_t record = network_records[i];
	    usim_data.pnn[i].fullname.type = USIM_PNN_FULLNAME_TAG;
	    usim_data.pnn[i].fullname.length = strlen(record.fullname);
	    strncpy((char*)usim_data.pnn[i].fullname.value, record.fullname,
		    usim_data.pnn[i].fullname.length);
	    usim_data.pnn[i].shortname.type = USIM_PNN_SHORTNAME_TAG;
	    usim_data.pnn[i].shortname.length = strlen(record.shortname);
	    strncpy((char*)usim_data.pnn[i].shortname.value, record.shortname,
		    usim_data.pnn[i].shortname.length);
	    usim_data.opl[i].plmn = record.plmn;
	    usim_data.opl[i].start = record.tac_start;
	    usim_data.opl[i].end = record.tac_end;
	    usim_data.opl[i].record_id = i;
	}
	for (int i = VDF2; i < USIM_OPL_MAX; i++) {
	    memset(&usim_data.opl[i].plmn, 0xff, sizeof(plmn_t));
	}

	/*
	 * List of Equivalent HPLMNs
	 */
	usim_data.ehplmn[0] = network_records[SFR2].plmn;
	usim_data.ehplmn[1] = network_records[SFR3].plmn;
	/*
	 * Home PLMN Selector with Access Technology
	 */
329
	usim_data.hplmn.plmn = network_records[SELECTED_PLMN].plmn;
Cedric Roux's avatar
 
Cedric Roux committed
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
	usim_data.hplmn.AcT = (USIM_ACT_GSM | USIM_ACT_UTRAN | USIM_ACT_EUTRAN);
	/*
	 * List of user controlled PLMN selector with Access Technology
	 */
	for (int i = 0; i < USIM_PLMN_MAX; i++) {
	    memset(&usim_data.plmn[i], 0xff, sizeof(plmn_t));
	}
	/*
	 * List of operator controlled PLMN selector with Access Technology
	 */
	usim_data.oplmn[0].plmn = network_records[VDF1].plmn;
	usim_data.oplmn[0].AcT = (USIM_ACT_GSM | USIM_ACT_UTRAN | USIM_ACT_EUTRAN);
	usim_data.oplmn[1].plmn = network_records[VDF2].plmn;
	usim_data.oplmn[1].AcT = (USIM_ACT_GSM | USIM_ACT_UTRAN | USIM_ACT_EUTRAN);
	usim_data.oplmn[2].plmn = network_records[VDF3].plmn;
	usim_data.oplmn[2].AcT = (USIM_ACT_GSM | USIM_ACT_UTRAN | USIM_ACT_EUTRAN);
	usim_data.oplmn[3].plmn = network_records[VDF4].plmn;
	usim_data.oplmn[3].AcT = (USIM_ACT_GSM | USIM_ACT_UTRAN | USIM_ACT_EUTRAN);
	usim_data.oplmn[4].plmn = network_records[VDF5].plmn;
	usim_data.oplmn[4].AcT = (USIM_ACT_GSM | USIM_ACT_UTRAN | USIM_ACT_EUTRAN);
	for (int i = 5; i < USIM_OPLMN_MAX; i++) {
	    memset(&usim_data.oplmn[i], 0xff, sizeof(plmn_t));
	}
	/*
	 * EPS Location Information
	 */
356
	usim_data.epsloci.guti.gummei.plmn = network_records[SELECTED_PLMN].plmn;
Cedric Roux's avatar
 
Cedric Roux committed
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
	usim_data.epsloci.guti.gummei.MMEgid = DEFAULT_MME_ID;
	usim_data.epsloci.guti.gummei.MMEcode = DEFAULT_MME_CODE;
	usim_data.epsloci.guti.m_tmsi = DEFAULT_M_TMSI;
	usim_data.epsloci.tai.plmn = usim_data.epsloci.guti.gummei.plmn;
	usim_data.epsloci.tai.tac = DEFAULT_TAC;
	usim_data.epsloci.status = USIM_EPSLOCI_UPDATED;
	/*
	 * Non-Access Stratum configuration
	 */
	usim_data.nasconfig.NAS_SignallingPriority.type = USIM_NAS_SIGNALLING_PRIORITY_TAG;
	usim_data.nasconfig.NAS_SignallingPriority.length = 1;
	usim_data.nasconfig.NAS_SignallingPriority.value[0] = 0x00;
	usim_data.nasconfig.NMO_I_Behaviour.type = USIM_NMO_I_BEHAVIOUR_TAG;
	usim_data.nasconfig.NMO_I_Behaviour.length = 1;
	usim_data.nasconfig.NMO_I_Behaviour.value[0] = 0x00;
	usim_data.nasconfig.AttachWithImsi.type = USIM_ATTACH_WITH_IMSI_TAG;
	usim_data.nasconfig.AttachWithImsi.length = 1;
374
#if defined(START_WITH_GUTI)
Cedric Roux's avatar
 
Cedric Roux committed
375
	usim_data.nasconfig.AttachWithImsi.value[0] = 0x00;
376 377 378
#else
    usim_data.nasconfig.AttachWithImsi.value[0] = 0x01;
#endif
Cedric Roux's avatar
 
Cedric Roux committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
	usim_data.nasconfig.MinimumPeriodicSearchTimer.type = USIM_MINIMUM_PERIODIC_SEARCH_TIMER_TAG;
	usim_data.nasconfig.MinimumPeriodicSearchTimer.length = 1;
	usim_data.nasconfig.MinimumPeriodicSearchTimer.value[0] = 0x00;
	usim_data.nasconfig.ExtendedAccessBarring.type = USIM_EXTENDED_ACCESS_BARRING_TAG;
	usim_data.nasconfig.ExtendedAccessBarring.length = 1;
	usim_data.nasconfig.ExtendedAccessBarring.value[0] = 0x00;
	usim_data.nasconfig.Timer_T3245_Behaviour.type = USIM_TIMER_T3245_BEHAVIOUR_TAG;
	usim_data.nasconfig.Timer_T3245_Behaviour.length = 1;
	usim_data.nasconfig.Timer_T3245_Behaviour.value[0] = 0x00;

	/*
	 * Write USIM application data
	 */
	rc = usim_api_write(&usim_data);
	if (rc != RETURNok) {
	    perror("ERROR\t: usim_api_write() failed");
	    exit(EXIT_FAILURE);
	}
    }

    /*
     * Read USIM application data
     */
    memset(&usim_data, 0, sizeof(usim_data_t));
    rc = usim_api_read(&usim_data);
    if (rc != RETURNok) {
	perror("ERROR\t: usim_api_read() failed");
	exit(EXIT_FAILURE);
    }

    /*
     * Display USIM application data
     */
    printf("\nUSIM data:\n\n");
    _display_usim_data(&usim_data);

    /*
     * Display USIM file location
     */
    char* path = memory_get_path("USIM_DIR", ".usim.nvram");
    printf("\nUSIM data file: %s\n", path);
    free(path);

    exit(EXIT_SUCCESS);
}

/****************************************************************************/
/*********************  L O C A L    F U N C T I O N S  *********************/
/****************************************************************************/

/*
 * Displays command line usage
 */
static void _display_usage(const char* command)
{
    fprintf(stderr, "usage: %s [OPTION]\n", command);
    fprintf(stderr, "\t[--gen|-g]\tGenerate the USIM data file\n");
    fprintf(stderr, "\t[--print|-p]\tDisplay the content of the USIM data file\n");
    fprintf(stderr, "\t[--help|-h]\tDisplay this usage\n");
    const char* path = getenv("USIM_DIR");
    if (path != NULL) {
	fprintf(stderr, "USIM_DIR = %s\n", path);
    }
    else {
	fprintf(stderr, "USIM_DIR environment variable is not defined\n");
    }
}

/*
 * Displays USIM application data
 */
static void _display_usim_data(const usim_data_t* data)
{
winckel's avatar
winckel committed
452 453
    int digits;

Cedric Roux's avatar
 
Cedric Roux committed
454 455 456 457 458
    printf("Administrative Data:\n");
    printf("\tUE_Operation_Mode\t= 0x%.2x\n", data->ad.UE_Operation_Mode);
    printf("\tAdditional_Info\t\t= 0x%.4x\n", data->ad.Additional_Info);
    printf("\tMNC_Length\t\t= %d\n\n", data->ad.MNC_Length);

winckel's avatar
winckel committed
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
    printf("IMSI:\n");
    printf("\tlength\t= %d\n", data->imsi.length);
    printf("\tparity\t= %s\n", data->imsi.u.num.parity == EVEN_PARITY ? "Even" : "Odd");
    digits = (data->imsi.length * 2) - 1 - (data->imsi.u.num.parity == EVEN_PARITY ? 1 : 0);
    printf("\tdigits\t= %d\n", digits);
    printf("\tdigits\t= %u%u%u%u%u%x%u%u%u%u",
           data->imsi.u.num.digit1, // MCC digit 1
           data->imsi.u.num.digit2, // MCC digit 2
           data->imsi.u.num.digit3, // MCC digit 3
           data->imsi.u.num.digit4, // MNC digit 1
           data->imsi.u.num.digit5, // MNC digit 2
           data->imsi.u.num.digit6, // MNC digit 3
           data->imsi.u.num.digit7,
           data->imsi.u.num.digit8,
           data->imsi.u.num.digit9,
           data->imsi.u.num.digit10);
    if (digits >= 11)
        printf("%x", data->imsi.u.num.digit11);
    if (digits >= 12)
        printf("%x", data->imsi.u.num.digit12);
    if (digits >= 13)
        printf("%x", data->imsi.u.num.digit13);
    if (digits >= 14)
        printf("%x", data->imsi.u.num.digit14);
    if (digits >= 15)
        printf("%x", data->imsi.u.num.digit15);
    printf("\n\n");
Cedric Roux's avatar
 
Cedric Roux committed
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570

    printf("Ciphering and Integrity Keys:\n");
    printf("\tKSI\t: 0x%.2x\n", data->keys.ksi);
    char key[USIM_CK_SIZE+1];
    key[USIM_CK_SIZE] = '\0';
    memcpy(key, data->keys.ck, USIM_CK_SIZE);
    printf("\tCK\t: \"%s\"\n", key);
    memcpy(key, data->keys.ik, USIM_IK_SIZE);
    printf("\tIK\t: \"%s\"\n", key);

    printf("EPS NAS security context:\n");
    printf("\tKSIasme\t: 0x%.2x\n", data->securityctx.KSIasme.value[0]);
    char kasme[USIM_K_ASME_SIZE+1];
    kasme[USIM_K_ASME_SIZE] = '\0';
    memcpy(kasme, data->securityctx.Kasme.value, USIM_K_ASME_SIZE);
    printf("\tKasme\t: \"%s\"\n", kasme);
    printf("\tulNAScount\t: 0x%.8x\n",
	   *(UInt32_t*)data->securityctx.ulNAScount.value);
    printf("\tdlNAScount\t: 0x%.8x\n",
	   *(UInt32_t*)data->securityctx.dlNAScount.value);
    printf("\talgorithmID\t: 0x%.2x\n\n",
	   data->securityctx.algorithmID.value[0]);

    printf("MSISDN\t= %u%u%u %u%u%u%u %u%u%u%u\n\n",
	   data->msisdn.number.digit[0].msb,
	   data->msisdn.number.digit[0].lsb,
	   data->msisdn.number.digit[1].msb,
	   data->msisdn.number.digit[1].lsb,
	   data->msisdn.number.digit[2].msb,
	   data->msisdn.number.digit[2].lsb,
	   data->msisdn.number.digit[3].msb,
	   data->msisdn.number.digit[3].lsb,
	   data->msisdn.number.digit[4].msb,
	   data->msisdn.number.digit[4].lsb,
	   data->msisdn.number.digit[5].msb);

    for (int i = 0; i < USIM_PNN_MAX; i++) {
	printf("PNN[%d]\t= {%s, %s}\n", i,
	       data->pnn[i].fullname.value, data->pnn[i].shortname.value);
    }
    printf("\n");

    for (int i = 0; i < USIM_OPL_MAX; i++) {
	printf("OPL[%d]\t= ", i); PRINT_PLMN(data->opl[i].plmn);
	printf(", TAC = [%.4x - %.4x], record_id = %d\n",
	   data->opl[i].start, data->opl[i].end, data->opl[i].record_id);
    }
    printf("\n");

    printf("HPLMN\t\t= "); PRINT_PLMN(data->hplmn.plmn);
    printf(", AcT = 0x%x\n\n", data->hplmn.AcT);

    for (int i = 0; i < USIM_FPLMN_MAX; i++) {
	printf("FPLMN[%d]\t= ", i); PRINT_PLMN(data->fplmn[i]);
	printf("\n");
    }
    printf("\n");

    for (int i = 0; i < USIM_EHPLMN_MAX; i++) {
	printf("EHPLMN[%d]\t= ", i); PRINT_PLMN(data->ehplmn[i]);
	printf("\n");
    }
    printf("\n");

    for (int i = 0; i < USIM_PLMN_MAX; i++) {
	printf("PLMN[%d]\t\t= ", i); PRINT_PLMN(data->plmn[i].plmn);
	printf(", AcTPLMN = 0x%x", data->plmn[i].AcT);
	printf("\n");
    }
    printf("\n");

    for (int i = 0; i < USIM_OPLMN_MAX; i++) {
	printf("OPLMN[%d]\t= ", i); PRINT_PLMN(data->oplmn[i].plmn);
	printf(", AcTPLMN = 0x%x", data->oplmn[i].AcT);
	printf("\n");
    }
    printf("\n");

    printf("HPPLMN\t\t= 0x%.2x (%d minutes)\n\n", data->hpplmn, data->hpplmn);

    printf("LOCI:\n");
    printf("\tTMSI = 0x%.4x\n", data->loci.tmsi);
    printf("\tLAI\t: PLMN = "); PRINT_PLMN(data->loci.lai.plmn);
    printf(", LAC = 0x%.2x\n", data->loci.lai.lac);
    printf("\tstatus\t= %d\n\n", data->loci.status);
571

Cedric Roux's avatar
 
Cedric Roux committed
572 573 574 575 576 577 578 579 580 581
    printf("PSLOCI:\n");
    printf("\tP-TMSI = 0x%.4x\n", data->psloci.p_tmsi);
    printf("\tsignature = 0x%x 0x%x 0x%x\n",
	   data->psloci.signature[0],
	   data->psloci.signature[1],
	   data->psloci.signature[2]);
    printf("\tRAI\t: PLMN = "); PRINT_PLMN(data->psloci.rai.plmn);
    printf(", LAC = 0x%.2x, RAC = 0x%.1x\n",
	   data->psloci.rai.lac, data->psloci.rai.rac);
    printf("\tstatus\t= %d\n\n", data->psloci.status);
582

Cedric Roux's avatar
 
Cedric Roux committed
583 584 585 586 587 588 589 590
    printf("EPSLOCI:\n");
    printf("\tGUTI\t: GUMMEI\t: (PLMN = ");
    PRINT_PLMN(data->epsloci.guti.gummei.plmn);
    printf(", MMEgid = 0x%.2x, MMEcode = 0x%.1x)",
	   data->epsloci.guti.gummei.MMEgid,
	   data->epsloci.guti.gummei.MMEcode);
    printf(", M-TMSI = 0x%.4x\n", data->epsloci.guti.m_tmsi);
    printf("\tTAI\t: PLMN = ");
591
    PRINT_PLMN(data->epsloci.tai.plmn);
Cedric Roux's avatar
 
Cedric Roux committed
592 593 594
    printf(", TAC = 0x%.2x\n",
	   data->epsloci.tai.tac);
    printf("\tstatus\t= %d\n\n", data->epsloci.status);
595

Cedric Roux's avatar
 
Cedric Roux committed
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
    printf("NASCONFIG:\n");
    printf("\tNAS_SignallingPriority\t\t: 0x%.2x\n",
	   data->nasconfig.NAS_SignallingPriority.value[0]);
    printf("\tNMO_I_Behaviour\t\t\t: 0x%.2x\n",
	   data->nasconfig.NMO_I_Behaviour.value[0]);
    printf("\tAttachWithImsi\t\t\t: 0x%.2x\n",
	   data->nasconfig.AttachWithImsi.value[0]);
    printf("\tMinimumPeriodicSearchTimer\t: 0x%.2x\n",
	   data->nasconfig.MinimumPeriodicSearchTimer.value[0]);
    printf("\tExtendedAccessBarring\t\t: 0x%.2x\n",
	   data->nasconfig.ExtendedAccessBarring.value[0]);
    printf("\tTimer_T3245_Behaviour\t\t: 0x%.2x\n",
	   data->nasconfig.Timer_T3245_Behaviour.value[0]);
}