anjana_sreekumar@infosys.com | 991c206 | 2020-01-08 11:42:57 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2019, Infosys Ltd. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include <string> |
| 17 | #include <sstream> |
| 18 | #include <cstring> |
| 19 | #include <iomanip> |
| 20 | #include "structs.h" |
| 21 | #include "log.h" |
| 22 | |
| 23 | using namespace std; |
| 24 | |
| 25 | uint8_t ASCII_TO_BCD(uint8_t left, uint8_t right) |
| 26 | { |
| 27 | uint8_t bcd_value; |
| 28 | |
| 29 | if(left >= '0' && left <= '9') // 0-9 range |
| 30 | { |
| 31 | bcd_value = ( left - 0x30) << 4 ; // 48 for '0' ASCII offset |
| 32 | } |
| 33 | else |
| 34 | { |
| 35 | bcd_value = 0x0f << 4; // filler 1111 |
| 36 | } |
| 37 | |
| 38 | if(right >= '0' && right <= '9') // 0-9 range |
| 39 | { |
| 40 | bcd_value |= ( right - 0x30); // 48 for '0' ASCII offset |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | bcd_value |= 0x0f; // filler 1111 |
| 45 | } |
| 46 | |
| 47 | return bcd_value; |
| 48 | } |
| 49 | |
| 50 | /******************************************************* |
| 51 | *TAI |
| 52 | ********************************************************/ |
| 53 | Tai::Tai() |
| 54 | { |
| 55 | memset( &tai_m, 0, sizeof( tai_m )); |
| 56 | } |
| 57 | |
| 58 | Tai::Tai( const TAI& tai_i ) |
| 59 | { |
| 60 | memset( &tai_m, 0, sizeof( tai_m )); |
| 61 | memcpy( &tai_m, &tai_i, sizeof( tai_i )); |
| 62 | } |
| 63 | |
| 64 | Tai::~Tai() |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | void Tai::operator = ( const Tai& tai_i ) |
| 69 | { |
| 70 | memcpy( &tai_m, &(tai_i.tai_m), sizeof( tai_i.tai_m )); |
| 71 | } |
| 72 | |
| 73 | /******************************************************* |
| 74 | *CGI |
| 75 | ********************************************************/ |
| 76 | Cgi::Cgi() |
| 77 | { |
| 78 | memset( &cgi_m, 0, sizeof( cgi_m )); |
| 79 | } |
| 80 | |
| 81 | Cgi::Cgi( const CGI& cgi_i ) |
| 82 | { |
| 83 | memset( &cgi_m, 0, sizeof( cgi_m )); |
| 84 | memcpy( &cgi_m, &cgi_i, sizeof(cgi_i)); |
| 85 | } |
| 86 | |
| 87 | Cgi::~Cgi() |
| 88 | { |
| 89 | } |
| 90 | |
| 91 | void Cgi::operator = ( const Cgi& cgi_i ) |
| 92 | { |
| 93 | memcpy( &cgi_m, &(cgi_i.cgi_m), sizeof(cgi_i.cgi_m)); |
| 94 | } |
| 95 | |
| 96 | /******************************************************* |
| 97 | *STMSI |
| 98 | ********************************************************/ |
| 99 | Stmsi::Stmsi() |
| 100 | { |
| 101 | memset( &stmsi_m, 0, sizeof( stmsi_m )); |
| 102 | } |
| 103 | |
| 104 | Stmsi::Stmsi( const STMSI& stmsi_i ) |
| 105 | { |
| 106 | memset( &stmsi_m, 0, sizeof( stmsi_m )); |
| 107 | memcpy( &stmsi_m, &stmsi_i, sizeof( stmsi_i )); |
| 108 | } |
| 109 | |
| 110 | Stmsi::~Stmsi() |
| 111 | { |
| 112 | } |
| 113 | |
| 114 | void Stmsi::operator = ( const Stmsi& stmsi_i ) |
| 115 | { |
| 116 | memcpy( &stmsi_m, &(stmsi_i.stmsi_m), sizeof( stmsi_i.stmsi_m )); |
| 117 | } |
| 118 | |
| 119 | /******************************************************* |
| 120 | *ARP |
| 121 | ********************************************************/ |
| 122 | Arp::Arp() |
| 123 | { |
| 124 | memset( &arp_m, 0, sizeof( arp_m )); |
| 125 | } |
| 126 | |
| 127 | Arp::Arp( const ARP& arp_i ) |
| 128 | { |
| 129 | memset( &arp_m, 0, sizeof( arp_m )); |
| 130 | memcpy( &arp_m, &arp_i, sizeof( arp_i )); |
| 131 | } |
| 132 | |
| 133 | Arp::~Arp() |
| 134 | { |
| 135 | } |
| 136 | |
| 137 | void Arp::operator = ( const Arp& arp_i ) |
| 138 | { |
| 139 | memcpy( &arp_m, &(arp_i.arp_m), sizeof( arp_i.arp_m )); |
| 140 | } |
| 141 | |
| 142 | |
| 143 | /******************************************************* |
| 144 | *Ms_net_capab |
| 145 | ********************************************************/ |
| 146 | Ms_net_capab::Ms_net_capab() |
| 147 | { |
| 148 | memset( &ms_net_capab_m, 0, sizeof( ms_net_capab_m )); |
| 149 | } |
| 150 | |
| 151 | Ms_net_capab::Ms_net_capab( const MS_net_capab& net_cap_i ) |
| 152 | { |
| 153 | memset( &ms_net_capab_m, 0, sizeof( ms_net_capab_m )); |
| 154 | memcpy( &ms_net_capab_m, &net_cap_i, sizeof( net_cap_i )); |
| 155 | } |
| 156 | |
| 157 | Ms_net_capab::~Ms_net_capab() |
| 158 | { |
| 159 | } |
| 160 | |
| 161 | void Ms_net_capab::operator = ( const Ms_net_capab& net_cap_i ) |
| 162 | { |
| 163 | memcpy( &ms_net_capab_m, &(net_cap_i.ms_net_capab_m), sizeof( net_cap_i.ms_net_capab_m )); |
| 164 | } |
| 165 | |
| 166 | /******************************************************* |
| 167 | *Ue_net_capab |
| 168 | ********************************************************/ |
| 169 | Ue_net_capab::Ue_net_capab() |
| 170 | { |
| 171 | memset( &ue_net_capab_m, 0, sizeof( ue_net_capab_m )); |
| 172 | } |
| 173 | |
| 174 | Ue_net_capab::Ue_net_capab( const UE_net_capab& net_cap_i ) |
| 175 | { |
| 176 | memset( &ue_net_capab_m, 0, sizeof( ue_net_capab_m )); |
| 177 | memcpy( &ue_net_capab_m, &net_cap_i, sizeof( net_cap_i )); |
| 178 | } |
| 179 | |
| 180 | Ue_net_capab::~Ue_net_capab() |
| 181 | { |
| 182 | } |
| 183 | |
| 184 | void Ue_net_capab::operator = ( const Ue_net_capab& net_cap_i ) |
| 185 | { |
| 186 | memcpy( &ue_net_capab_m, &(net_cap_i.ue_net_capab_m), sizeof( net_cap_i.ue_net_capab_m )); |
| 187 | } |
| 188 | |
| 189 | /******************************************************* |
| 190 | *Secinfo |
| 191 | ********************************************************/ |
| 192 | Secinfo::Secinfo() |
| 193 | { |
| 194 | memset( &secinfo_m, 0, sizeof( secinfo_m )); |
| 195 | } |
| 196 | |
| 197 | Secinfo::Secinfo( const secinfo& sec_i ) |
| 198 | { |
| 199 | memset( &secinfo_m, 0, sizeof( secinfo_m )); |
| 200 | memcpy( &secinfo_m, &sec_i, sizeof( sec_i )); |
| 201 | } |
| 202 | |
| 203 | Secinfo::~Secinfo() |
| 204 | { |
| 205 | } |
| 206 | |
| 207 | void Secinfo::operator = ( const Secinfo& sec_i ) |
| 208 | { |
| 209 | memcpy( &secinfo_m, &(sec_i.secinfo_m), sizeof( sec_i.secinfo_m )); |
| 210 | } |
| 211 | |
| 212 | /******************************************************* |
| 213 | *Ambr |
| 214 | ********************************************************/ |
| 215 | Ambr::Ambr() |
| 216 | { |
| 217 | memset( &ambr_m, 0, sizeof( ambr_m )); |
| 218 | } |
| 219 | |
| 220 | Ambr::Ambr( const AMBR& ambr_i ) |
| 221 | { |
| 222 | memset( &ambr_m, 0, sizeof( ambr_m )); |
| 223 | memcpy( &ambr_m, &ambr_i, sizeof( ambr_i )); |
| 224 | } |
| 225 | |
| 226 | Ambr::~Ambr() |
| 227 | { |
| 228 | } |
| 229 | |
| 230 | void Ambr::operator = ( const Ambr& ambr_i ) |
| 231 | { |
| 232 | memcpy( &ambr_m, &(ambr_i.ambr_m), sizeof( ambr_i.ambr_m )); |
| 233 | } |
| 234 | |
| 235 | /******************************************************* |
| 236 | *E_utran_sec_vector |
| 237 | ********************************************************/ |
| 238 | E_utran_sec_vector::E_utran_sec_vector():AiaSecInfo_mp( NULL ) |
| 239 | { |
| 240 | AiaSecInfo_mp = (struct E_UTRAN_sec_vector*)calloc(sizeof(struct E_UTRAN_sec_vector), 1); |
| 241 | } |
| 242 | |
| 243 | E_utran_sec_vector::E_utran_sec_vector( const E_UTRAN_sec_vector& secinfo_i ) |
| 244 | { |
| 245 | AiaSecInfo_mp = (struct E_UTRAN_sec_vector*)calloc(sizeof(struct E_UTRAN_sec_vector), 1); |
| 246 | memcpy( AiaSecInfo_mp, &secinfo_i, sizeof( E_UTRAN_sec_vector )); |
| 247 | } |
| 248 | |
| 249 | E_utran_sec_vector::~E_utran_sec_vector() |
| 250 | { |
| 251 | free(AiaSecInfo_mp); |
| 252 | } |
| 253 | |
| 254 | void E_utran_sec_vector::operator = ( const E_utran_sec_vector& secinfo_i ) |
| 255 | { |
| 256 | if( NULL != secinfo_i.AiaSecInfo_mp ) |
| 257 | { |
| 258 | memcpy( AiaSecInfo_mp, secinfo_i.AiaSecInfo_mp, sizeof( E_UTRAN_sec_vector )); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | std::ostream& operator << ( std::ostream& os, const E_utran_sec_vector& data_i ) |
| 263 | { |
| 264 | os << "RAND "; |
| 265 | for ( uint32_t i = 0; i < data_i.AiaSecInfo_mp->rand.len; i++) |
| 266 | { |
| 267 | os << setfill('0') << setw(2) << std::hex << |
| 268 | static_cast<uint32_t>(data_i.AiaSecInfo_mp->rand.val[i]); |
| 269 | } |
| 270 | os << std::endl; |
| 271 | |
| 272 | os << "RES "; |
| 273 | for ( uint32_t i = 0; i < data_i.AiaSecInfo_mp->xres.len; i++) |
| 274 | { |
| 275 | os << setfill('0') << setw(2) << std::hex << |
| 276 | static_cast<uint32_t>(data_i.AiaSecInfo_mp->xres.val[i]); |
| 277 | } |
| 278 | os << std::endl; |
| 279 | |
| 280 | os << "AUTN "; |
| 281 | for ( uint32_t i = 0; i < data_i.AiaSecInfo_mp->autn.len; i++) |
| 282 | { |
| 283 | os << setfill('0') << setw(2) << std::hex << |
| 284 | static_cast<uint32_t>(data_i.AiaSecInfo_mp->autn.val[i]); |
| 285 | } |
| 286 | os << std::endl; |
| 287 | |
| 288 | os << "KASME "; |
| 289 | for ( uint32_t i = 0; i < data_i.AiaSecInfo_mp->kasme.len; i++) |
| 290 | { |
| 291 | os << setfill('0') << setw(2) << std::hex << |
| 292 | static_cast<uint32_t>(data_i.AiaSecInfo_mp->kasme.val[i]); |
| 293 | } |
| 294 | os << std::endl; |
| 295 | |
| 296 | return os; |
| 297 | } |
| 298 | |
| 299 | /******************************************************* |
| 300 | *Fteid |
| 301 | ********************************************************/ |
| 302 | Fteid::Fteid() |
| 303 | { |
| 304 | memset( &fteid_m, 0, sizeof( fteid_m )); |
| 305 | } |
| 306 | |
| 307 | Fteid::Fteid( const fteid& fteid_i ) |
| 308 | { |
| 309 | memset( &fteid_m, 0, sizeof( fteid_m )); |
| 310 | memcpy( &fteid_m, &fteid_i, sizeof( fteid_i )); |
| 311 | } |
| 312 | |
| 313 | Fteid::~Fteid() |
| 314 | { |
| 315 | } |
| 316 | |
| 317 | void Fteid::operator = ( const Fteid& fteid_i ) |
| 318 | { |
| 319 | memcpy( &fteid_m, &(fteid_i.fteid_m), sizeof( fteid_i.fteid_m )); |
| 320 | } |
| 321 | |
| 322 | /******************************************************* |
| 323 | *Paa |
| 324 | ********************************************************/ |
| 325 | Paa::Paa() |
| 326 | { |
| 327 | memset( &paa_m, 0, sizeof( paa_m )); |
| 328 | } |
| 329 | |
| 330 | Paa::Paa( const PAA& paa_i ) |
| 331 | { |
| 332 | memset( &paa_m, 0, sizeof( paa_m )); |
| 333 | memcpy( &paa_m, &paa_i, sizeof( paa_i )); |
| 334 | } |
| 335 | |
| 336 | Paa::~Paa() |
| 337 | { |
| 338 | } |
| 339 | |
| 340 | void Paa::operator = ( const Paa& paa_i ) |
| 341 | { |
| 342 | memcpy( &paa_m, &(paa_i.paa_m), sizeof( paa_i.paa_m )); |
| 343 | } |
| 344 | |
| 345 | /******************************************************* |
| 346 | *Apn_name |
| 347 | ********************************************************/ |
| 348 | Apn_name::Apn_name() |
| 349 | { |
| 350 | memset( &apnname_m, 0, sizeof( apnname_m )); |
| 351 | } |
| 352 | |
| 353 | Apn_name::Apn_name( const apn_name& apn_name_i ) |
| 354 | { |
| 355 | memset( &apnname_m, 0, sizeof( apnname_m )); |
| 356 | memcpy( &apnname_m, &apn_name_i, sizeof( apn_name_i )); |
| 357 | } |
| 358 | |
| 359 | Apn_name::~Apn_name() |
| 360 | { |
| 361 | } |
| 362 | |
| 363 | void Apn_name::operator = ( const Apn_name& apn_name_i ) |
| 364 | { |
| 365 | memcpy( &apnname_m, &(apn_name_i.apnname_m), sizeof( apn_name_i.apnname_m )); |
| 366 | } |
| 367 | |
| 368 | /******************************************************* |
| 369 | *DigitRegister15 |
| 370 | ********************************************************/ |
| 371 | DigitRegister15::DigitRegister15() |
| 372 | { |
| 373 | memset(&digitsArray,0,15); |
| 374 | } |
| 375 | |
| 376 | void DigitRegister15::convertToBcdArray( uint8_t * arrayOut ) const |
| 377 | { |
| 378 | for( int i=0; i < 7; i++ ) |
| 379 | { |
| 380 | arrayOut[i] = ASCII_TO_BCD(digitsArray[2*i+1],digitsArray[2*i]); |
| 381 | } |
| 382 | arrayOut[7] = ASCII_TO_BCD(0x0f,digitsArray[14]); |
| 383 | } |
| 384 | |
| 385 | void DigitRegister15::convertFromBcdArray( const uint8_t* bcdArrayIn ) |
| 386 | { |
| 387 | // For the imsi value upper nibble of first octect should only be considered |
| 388 | if(( bcdArrayIn[0] & 0x0f ) == 0x0f ) |
| 389 | { |
| 390 | digitsArray[0] = (uint8_t)(((bcdArrayIn[0] >> 4) & 0x0f ) + 0x30); |
| 391 | for( int i = 1; i < 8; i++ ) |
| 392 | { |
| 393 | digitsArray[2*i] = (uint8_t)(((bcdArrayIn[i] >> 4) & 0x0f) + 0x30); |
| 394 | digitsArray[2*i-1] = (uint8_t)((bcdArrayIn[i] & 0x0f) + 0x30); |
| 395 | } |
| 396 | } |
| 397 | else |
| 398 | { |
| 399 | for( int i = 0; i < 7; i++ ) |
| 400 | { |
| 401 | digitsArray[2*i+1] = (uint8_t)(((bcdArrayIn[i] >> 4) & 0x0f) + 0x30); |
| 402 | digitsArray[2*i] = (uint8_t)((bcdArrayIn[i] & 0x0f) + 0x30); |
| 403 | } |
| 404 | digitsArray[7] = (uint8_t)(((bcdArrayIn[7] >> 4) & 0x0f) + 0x30); |
| 405 | } |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | |
| 410 | void DigitRegister15::setImsiDigits( uint8_t* digitsArrayIn ) |
| 411 | { |
| 412 | memcpy( digitsArray, digitsArrayIn, 15); |
| 413 | } |
| 414 | |
| 415 | void DigitRegister15::getImsiDigits( uint8_t* digitsArrayIn ) const |
| 416 | { |
| 417 | memcpy( digitsArrayIn, digitsArray, 15); |
| 418 | } |
| 419 | |
| 420 | bool DigitRegister15::isValid() const |
| 421 | { |
| 422 | bool rc = false; |
| 423 | for (uint32_t i = 0; i < 15; i++) |
| 424 | { |
| 425 | if (digitsArray[i] != 0) |
| 426 | { |
| 427 | rc = true; |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | return rc; |
| 432 | } |
| 433 | |
| 434 | void DigitRegister15::operator = ( const DigitRegister15& data_i ) |
| 435 | { |
| 436 | memcpy( digitsArray, data_i.digitsArray, sizeof( data_i.digitsArray )); |
| 437 | } |
| 438 | |
| 439 | bool DigitRegister15::operator == ( const DigitRegister15& data_i )const |
| 440 | { |
| 441 | int data_cmp = memcmp(digitsArray, data_i.digitsArray, sizeof( data_i.digitsArray)); |
| 442 | bool rc = false; |
| 443 | if(data_cmp == 0) |
| 444 | rc = true; |
| 445 | return rc; |
| 446 | } |
| 447 | |
| 448 | bool DigitRegister15::operator < ( const DigitRegister15& data_i )const |
| 449 | { |
| 450 | bool rc = true; |
| 451 | if(*this == data_i) |
| 452 | rc = false; |
| 453 | else |
| 454 | { |
| 455 | for(int i=0; i<15; i++) |
| 456 | { |
| 457 | if(digitsArray[i] > data_i.digitsArray[i]) |
| 458 | { |
| 459 | rc = false; |
| 460 | break; |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | return rc; |
| 465 | } |
| 466 | |
| 467 | std::ostream& operator << ( std::ostream& os, const DigitRegister15& data_i ) |
| 468 | { |
| 469 | for( auto x : data_i.digitsArray ) |
| 470 | { |
| 471 | if( x != 0x0f ) |
| 472 | os << x - 0x30; |
| 473 | } |
| 474 | os << "\0"; |
| 475 | return os; |
| 476 | } |
| 477 | |