Harald Welte | ac35980 | 2017-04-12 12:13:44 +0200 | [diff] [blame] | 1 | /////////////////////////////////////////////////////////////////////////////// |
| 2 | // // |
| 3 | // Copyright Test Competence Center (TCC) ETH 2012 // |
| 4 | // // |
| 5 | // The copyright to the computer program(s) herein is the property of TCC. // |
| 6 | // The program(s) may be used and/or copied only with the written permission // |
| 7 | // of TCC or in accordance with the terms and conditions stipulated in the // |
| 8 | // agreement/contract under which the program(s) have been supplied // |
| 9 | // // |
| 10 | /////////////////////////////////////////////////////////////////////////////// |
| 11 | // |
| 12 | // File: MTP3asp_PT.cc |
| 13 | // Description: Implementation of port MTP3asp_PT |
| 14 | // This test port is written to connect TTCN-3 to SEA according |
| 15 | // to specification ITU-T SS7 MTP3, ANSI, TCC, IETF, MPT |
| 16 | // Reference: ITU-T Recommendation Q.704, RFC3332 |
| 17 | // Rev: R11A01 |
| 18 | // Prodnr: CNL 113 337 |
| 19 | // Updated: 2012-05-24 |
| 20 | // Contact: http://ttcn.ericsson.se |
| 21 | |
| 22 | // IMPORTANT MODIFICATION: |
| 23 | // mtp3_ttc uses ALWAYS 16 bits long SPCs, regardless of mtp3_ni sio |
| 24 | |
| 25 | #include "MTP3asp_PT.hh" |
| 26 | |
| 27 | #include "MTP3asp_Types.hh" |
| 28 | #include "MTP3asp_PortType.hh" |
| 29 | |
| 30 | #include <stdio.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <unistd.h> |
| 33 | #include <poll.h> |
| 34 | #include <errno.h> |
| 35 | #include <stdarg.h> |
| 36 | #include <string.h> |
| 37 | |
| 38 | |
| 39 | // Constans for M3UA, see rfc 3332 and 2/1056-FCPW 101 86/P-1 |
| 40 | // Constants for decoding M3UA common headers |
| 41 | #define M3UA_VER_OFFS 0 |
| 42 | #define M3UA_CLS_OFFS 2 |
| 43 | #define M3UA_TYP_OFFS 3 |
| 44 | #define M3UA_LGT_OFFS 4 |
| 45 | #define M3UA_MSG_OFFS 8 |
| 46 | #define M3UA_MSG_LENGTH_LENGTH 4 |
| 47 | |
| 48 | // Constants for M3UA protocol |
| 49 | //Msg classes |
| 50 | #define M3UA_MSG_CLS_MGMT 0x00 |
| 51 | #define M3UA_MSG_CLS_TRNSFM 0x01 |
| 52 | #define M3UA_MSG_CLS_SSNM 0x02 |
| 53 | #define M3UA_MSG_CLS_ASPSM 0x03 |
| 54 | #define M3UA_MSG_CLS_ASPTM 0x04 |
| 55 | #define M3UA_MSG_CLS_RKM 0x09 |
| 56 | //Msg types |
| 57 | #define M3UA_MSG_TYP_MGMT_ERR 0x00 |
| 58 | #define M3UA_MSG_TYP_MGMT_NTFY 0x01 |
| 59 | |
| 60 | #define M3UA_MSG_TYP_TRSNFM_DATA 0x01 |
| 61 | |
| 62 | #define M3UA_MSG_TYP_SSNM_DUNA 0x01 |
| 63 | #define M3UA_MSG_TYP_SSNM_DAVA 0x02 |
| 64 | #define M3UA_MSG_TYP_SSNM_DAUD 0x03 |
| 65 | #define M3UA_MSG_TYP_SSNM_SCON 0x04 |
| 66 | #define M3UA_MSG_TYP_SSNM_DUPU 0x05 |
| 67 | #define M3UA_MSG_TYP_SSNM_DRST 0x06 |
| 68 | |
| 69 | #define M3UA_MSG_TYP_ASPSM_ASPUP 0x01 |
| 70 | #define M3UA_MSG_TYP_ASPSM_ASPDN 0x02 |
| 71 | #define M3UA_MSG_TYP_ASPSM_BEAT 0x03 |
| 72 | #define M3UA_MSG_TYP_ASPSM_ASPUPAck 0x04 |
| 73 | #define M3UA_MSG_TYP_ASPSM_ASPDNAck 0x05 |
| 74 | #define M3UA_MSG_TYP_ASPSM_BEATAck 0x06 |
| 75 | |
| 76 | #define M3UA_MSG_TYP_ASPTM_ASPAC 0x01 |
| 77 | #define M3UA_MSG_TYP_ASPTM_ASPIA 0x02 |
| 78 | #define M3UA_MSG_TYP_ASPTM_ASPACAck 0x03 |
| 79 | #define M3UA_MSG_TYP_ASPTM_ASPIAAck 0x04 |
| 80 | |
| 81 | #define M3UA_MSG_TYP_RKM_REGREQ 0x01 |
| 82 | #define M3UA_MSG_TYP_RKM_REGRSP 0x02 |
| 83 | #define M3UA_MSG_TYP_RKM_DEREGREQ 0x03 |
| 84 | #define M3UA_MSG_TYP_RKM_DEREGRESP 0x04 |
| 85 | |
| 86 | //parameters |
| 87 | //common for all adaptation layer |
| 88 | #define PAR_PREFIX_COMMON 0x00 |
| 89 | #define PAR_INFO_STR 0x04 |
| 90 | #define PAR_ROUTING_CTX 0x06 |
| 91 | #define PAR_DIAG_INFO 0x07 |
| 92 | #define PAR_HEART_BEAT 0x09 |
| 93 | #define PAR_TRAFFMODE_T 0x0b |
| 94 | #define PAR_ERROR_CODE 0x0c |
| 95 | #define PAR_STATUS 0x0d |
| 96 | #define PAR_ASP_ID 0x11 |
| 97 | #define PAR_AFFECTED_PC 0x12 |
| 98 | #define PAR_CORREL_ID 0x13 |
| 99 | |
| 100 | //M3UA specific |
| 101 | #define PAR_PREFIX_M3UA 0x02 |
| 102 | #define PAR_NETW_APP 0x00 |
| 103 | #define PAR_USR_O_CAUSE 0x04 |
| 104 | #define PAR_CNGST_IND 0x05 |
| 105 | #define PAR_CNCRD_IND 0x06 |
| 106 | #define PAR_ROUTING_KEY 0x07 |
| 107 | #define PAR_REG_RSLT 0x08 |
| 108 | #define PAR_DEREG_RSLT 0x09 |
| 109 | #define PAR_LOC_RK_ID 0x0a |
| 110 | #define PAR_DPC 0x0b |
| 111 | #define PAR_SI 0x0c |
| 112 | #define PAR_OPC_LIST 0x0e |
| 113 | #define PAR_CIRC_RNG 0x0f |
| 114 | #define PAR_PROT_DATA 0x10 |
| 115 | #define PAR_REG_STAT 0x12 |
| 116 | #define PAR_DEREG_STAT 0x13 |
| 117 | |
| 118 | // error codes: |
| 119 | #define PAR_ERRC_IVER 0x01 |
| 120 | #define PAR_ERRC_UNSMC 0x03 |
| 121 | #define PAR_ERRC_UNSMT 0x04 |
| 122 | #define PAR_ERRC_UNTMT 0x05 |
| 123 | #define PAR_ERRC_UNEM 0x06 |
| 124 | #define PAR_ERRC_PERR 0x07 |
| 125 | #define PAR_ERRC_ISI 0x09 |
| 126 | #define PAR_ERRC_RMB 0x0D |
| 127 | #define PAR_ERRC_ASPIDR 0x0E |
| 128 | #define PAR_ERRC_IASPID 0x0F |
| 129 | #define PAR_ERRC_IPARV 0x11 |
| 130 | #define PAR_ERRC_PARFE 0x12 |
| 131 | #define PAR_ERRC_UPAR 0x13 |
| 132 | #define PAR_ERRC_DSU 0x14 |
| 133 | #define PAR_ERRC_INA 0x15 |
| 134 | #define PAR_ERRC_MP 0x16 |
| 135 | #define PAR_ERRC_IRC 0x19 |
| 136 | #define PAR_ERRC_NCFAS 0x1A |
| 137 | |
| 138 | |
| 139 | // -------------------------- |
| 140 | // Basic Test Port functions |
| 141 | // -------------------------- |
| 142 | using namespace MTP3asp__Types; |
| 143 | namespace MTP3asp__PortType { |
| 144 | |
| 145 | //external functions |
| 146 | //########################################################## |
| 147 | |
| 148 | //f__MTP3__SEA__connect (for MTP3asp_PT) |
| 149 | BOOLEAN f__MTP3__SEA__connect(MTP3asp__PT& portRef, |
| 150 | const CHARSTRING& Hostname,const INTEGER& Port,const CHARSTRING& EntityName,const BOOLEAN& Http) |
| 151 | { |
| 152 | return f__MTP3__SEA__connect__extern(portRef,Hostname,Port,EntityName,Http); |
| 153 | } |
| 154 | //------------ |
| 155 | |
| 156 | //f__MTP3__SEA__disconnect (for MTP3asp_PT) |
| 157 | BOOLEAN f__MTP3__SEA__disconnect(MTP3asp__PT& portRef) |
| 158 | { |
| 159 | return f__MTP3__SEA__disconnect__extern(portRef); |
| 160 | } |
| 161 | //------------ |
| 162 | |
| 163 | //f__MTP3__SEA__connect__extern |
| 164 | BOOLEAN f__MTP3__SEA__connect__extern(MTP3asp__PT_PROVIDER& portRef, |
| 165 | const CHARSTRING& Hostname,const INTEGER& Port,const CHARSTRING& EntityName,const BOOLEAN& Http) |
| 166 | { |
| 167 | #ifndef TARGET_TEST |
| 168 | if (portRef.dynamicConnection && (!(portRef.connectionUp))) |
| 169 | { |
| 170 | delete [] portRef.hostname; |
| 171 | int len = strlen(Hostname); |
| 172 | portRef.hostname = new char[len + 1]; |
| 173 | memcpy(portRef.hostname, Hostname, len + 1); |
| 174 | |
| 175 | portRef.httpport = Port; |
| 176 | |
| 177 | delete [] portRef.entityname; |
| 178 | len = strlen(EntityName); |
| 179 | portRef.entityname = new char[len + 1]; |
| 180 | memcpy(portRef.entityname, EntityName, len + 1); |
| 181 | |
| 182 | if(Http) |
| 183 | portRef.MTP3_open_channel(TRUE); |
| 184 | else |
| 185 | portRef.MTP3_open_channel(FALSE); |
| 186 | |
| 187 | if(portRef.wait_for_open()) |
| 188 | { |
| 189 | portRef.user_connect(); |
| 190 | portRef.connectionUp = TRUE; |
| 191 | return TRUE; |
| 192 | } |
| 193 | } |
| 194 | else |
| 195 | #endif |
| 196 | portRef.log("Dynamic connection feature is not active or already connected."); |
| 197 | return FALSE; |
| 198 | } |
| 199 | //------------ |
| 200 | |
| 201 | //f__MTP3__SEA__disconnect__extern |
| 202 | BOOLEAN f__MTP3__SEA__disconnect__extern(MTP3asp__PT_PROVIDER& portRef) |
| 203 | { |
| 204 | #ifndef TARGET_TEST |
| 205 | if (portRef.connectionUp) |
| 206 | { |
| 207 | portRef.MTP3_close_connection(); |
| 208 | portRef.connectionUp = FALSE; |
| 209 | return TRUE; |
| 210 | } |
| 211 | #endif |
| 212 | return FALSE; |
| 213 | } |
| 214 | //------------ |
| 215 | |
| 216 | // Test Port constructor |
| 217 | MTP3asp__PT_PROVIDER::MTP3asp__PT_PROVIDER(const char *par_port_name) |
| 218 | : PORT(par_port_name) |
| 219 | { |
| 220 | MTP_fd=-1; |
| 221 | httpport=-1; |
| 222 | hostname=NULL; |
| 223 | destinationname = NULL; |
| 224 | dynamicConnection = FALSE; |
| 225 | |
| 226 | const char *str="b303d76a-266c-11d4-b8f5-08002090d3da"; |
| 227 | int len = strlen(str); |
| 228 | iid_string= new char[len + 1]; |
| 229 | memcpy(iid_string, str, len + 1); |
| 230 | |
| 231 | entityname=NULL; |
| 232 | Filter=Loop=-1; |
| 233 | Sut_Pc=Tester_Pc=-1; |
| 234 | Ni_is_set = FALSE; |
| 235 | MTPServiceType = MTP3itu; |
| 236 | M3UA_version = 1; |
| 237 | M3UAState = AssocDown; // unnecessary... |
| 238 | mtp3_ni=0; |
| 239 | #ifndef TARGET_TEST |
| 240 | user_map_p = &MTP3asp__PT_PROVIDER::MTP3_user_map; |
| 241 | user_unmap_p = &MTP3asp__PT_PROVIDER::MTP3_user_unmap; |
| 242 | interpreter = &MTP3asp__PT_PROVIDER::MTP3_interpreter; |
| 243 | #endif |
| 244 | forward_pause = FALSE; |
| 245 | forward_resume = FALSE; |
| 246 | forward_status = FALSE; |
| 247 | } |
| 248 | //------------ |
| 249 | |
| 250 | // Test Port destructor |
| 251 | MTP3asp__PT_PROVIDER::~MTP3asp__PT_PROVIDER() |
| 252 | { |
| 253 | delete [] hostname; |
| 254 | delete [] entityname; |
| 255 | delete [] iid_string; |
| 256 | } |
| 257 | //------------ |
| 258 | |
| 259 | // set_parameter |
| 260 | void MTP3asp__PT_PROVIDER::set_parameter(const char *parameter_name, |
| 261 | const char *parameter_value) |
| 262 | { |
| 263 | log("set_parameter: %s = %s",parameter_name,parameter_value); |
| 264 | if (!strcmp(parameter_name,"Hostname")) |
| 265 | { |
| 266 | delete [] hostname; |
| 267 | int len = strlen(parameter_value); |
| 268 | hostname = new char[len + 1]; |
| 269 | memcpy(hostname, parameter_value, len + 1); |
| 270 | } |
| 271 | else if (!strcmp(parameter_name, "HttpPort")) |
| 272 | { |
| 273 | httpport = atoi(parameter_value); |
| 274 | } |
| 275 | else if (!strcmp(parameter_name,"EntityName")) |
| 276 | { |
| 277 | delete [] entityname; |
| 278 | int len = strlen(parameter_value); |
| 279 | entityname= new char[len + 1]; |
| 280 | memcpy(entityname, parameter_value, len + 1); |
| 281 | } |
| 282 | else if (!strcmp(parameter_name,"DestinationName")) |
| 283 | { |
| 284 | delete [] destinationname; |
| 285 | int len = strlen(parameter_value); |
| 286 | destinationname= new char[len + 1]; |
| 287 | memcpy(destinationname, parameter_value, len + 1); |
| 288 | } |
| 289 | else if (!strcmp(parameter_name,"Filter")) |
| 290 | { |
| 291 | if (!strcmp(parameter_value,"ON")) Filter = MTP3_ON; |
| 292 | else Filter = MTP3_OFF; |
| 293 | } |
| 294 | else if (!strcmp(parameter_name,"Loop")) |
| 295 | { |
| 296 | if (!strcmp(parameter_value,"ON")) Loop = MTP3_ON; |
| 297 | else Loop = MTP3_OFF; |
| 298 | } |
| 299 | else if (!strcmp(parameter_name,"NI")) |
| 300 | { |
| 301 | Ni_is_set = TRUE; |
| 302 | mtp3_ni = atoi(parameter_value); |
| 303 | debuglog("Network indicator is set to %i",mtp3_ni); |
| 304 | } |
| 305 | else if (!strcmp(parameter_name,"SUT_Pc")) |
| 306 | { |
| 307 | Sut_Pc = atoi(parameter_value); |
| 308 | } |
| 309 | else if (!strcmp(parameter_name,"TESTER_Pc")) |
| 310 | { |
| 311 | Tester_Pc = atoi(parameter_value); |
| 312 | } |
| 313 | else if (!strcmp(parameter_name,"M3UA_version")) |
| 314 | { |
| 315 | M3UA_version = atoi(parameter_value); |
| 316 | debuglog("%d",M3UA_version); |
| 317 | } |
| 318 | #ifndef TARGET_TEST |
| 319 | else if (!strcmp(parameter_name,"DynamicConnection")) |
| 320 | { |
| 321 | if (!strcasecmp(parameter_value,"ON")) |
| 322 | { |
| 323 | dynamicConnection = TRUE; |
| 324 | } |
| 325 | } |
| 326 | #endif |
| 327 | else if (!strcmp(parameter_name,"MTP3ServiceType")) |
| 328 | { |
| 329 | if (!strcmp(parameter_value,"TargetM3UA")) |
| 330 | { |
| 331 | #ifndef TARGET_TEST |
| 332 | error("TargetM3UA not supported, since TARGET_TEST not in Makefile"); |
| 333 | #else |
| 334 | log("MTP3ServiceType is set to TargetM3UA"); |
| 335 | user_map_p = &MTP3asp__PT_PROVIDER::Target_user_map; |
| 336 | user_unmap_p = &MTP3asp__PT_PROVIDER::Target_user_unmap; |
| 337 | MTPServiceType = TargetM3UA; |
| 338 | #endif |
| 339 | } |
| 340 | else if (!strcmp(parameter_value,"TargetSTC")) |
| 341 | { |
| 342 | #ifndef TARGET_TEST |
| 343 | error("TargetSTC not supported, since TARGET_TEST not in Makefile"); |
| 344 | #else |
| 345 | log("MTP3ServiceType is set to TargetSTC"); |
| 346 | user_map_p = &MTP3asp__PT_PROVIDER::TargetSTC_user_map; |
| 347 | user_unmap_p = &MTP3asp__PT_PROVIDER::Target_user_unmap; //Same as by Target M3UA |
| 348 | MTPServiceType = TargetSTC; |
| 349 | #endif |
| 350 | } |
| 351 | #ifndef TARGET_TEST |
| 352 | else if (!strcmp(parameter_value,"M3UA")) |
| 353 | { //M3UA |
| 354 | log("MTP3ServiceType is set to M3UA"); |
| 355 | interpreter = &MTP3asp__PT_PROVIDER::M3UA_interpreter; |
| 356 | user_map_p = &MTP3asp__PT_PROVIDER::M3UA_user_map; |
| 357 | user_connect_p = &MTP3asp__PT_PROVIDER::M3UA_user_connect; |
| 358 | user_unmap_p = &MTP3asp__PT_PROVIDER::M3UA_user_unmap; |
| 359 | MTPServiceType = M3UA; |
| 360 | } |
| 361 | else if (!strcmp(parameter_value,"MTP3itu")) |
| 362 | { |
| 363 | log("MTP3ServiceType is set to MTP3itu"); |
| 364 | interpreter = &MTP3asp__PT_PROVIDER::MTP3_interpreter; |
| 365 | user_map_p = &MTP3asp__PT_PROVIDER::MTP3_user_map; |
| 366 | user_connect_p = &MTP3asp__PT_PROVIDER::MTP3_user_connect; |
| 367 | user_unmap_p = &MTP3asp__PT_PROVIDER::MTP3_user_unmap; |
| 368 | MTPServiceType = MTP3itu; |
| 369 | } |
| 370 | else if ( !strcmp(parameter_value,"MTP3ansi")) |
| 371 | { |
| 372 | log("MTP3ServiceType is set to MTP3ansi"); |
| 373 | interpreter = &MTP3asp__PT_PROVIDER::MTP3_interpreter; |
| 374 | user_map_p = &MTP3asp__PT_PROVIDER::MTP3_user_map; |
| 375 | user_connect_p = &MTP3asp__PT_PROVIDER::MTP3_user_connect; |
| 376 | user_unmap_p = &MTP3asp__PT_PROVIDER::MTP3_user_unmap; |
| 377 | MTPServiceType = MTP3ansi; |
| 378 | } |
| 379 | else if ( !strcmp(parameter_value,"MTP3ttc")) |
| 380 | { |
| 381 | log("MTP3ServiceType is set to MTP3ttc"); |
| 382 | interpreter = &MTP3asp__PT_PROVIDER::MTP3_interpreter; |
| 383 | user_map_p = &MTP3asp__PT_PROVIDER::MTP3_user_map; |
| 384 | user_connect_p = &MTP3asp__PT_PROVIDER::MTP3_user_connect; |
| 385 | user_unmap_p = &MTP3asp__PT_PROVIDER::MTP3_user_unmap; |
| 386 | MTPServiceType = MTP3ttc; |
| 387 | } |
| 388 | else if ( !strcmp(parameter_value,"MTP3mpt")) |
| 389 | { |
| 390 | log("MTP3ServiceType is set to MTP3mpt"); |
| 391 | interpreter = &MTP3asp__PT_PROVIDER::MTP3_interpreter; |
| 392 | user_map_p = &MTP3asp__PT_PROVIDER::MTP3_user_map; |
| 393 | user_connect_p = &MTP3asp__PT_PROVIDER::MTP3_user_connect; |
| 394 | user_unmap_p = &MTP3asp__PT_PROVIDER::MTP3_user_unmap; |
| 395 | MTPServiceType = MTP3mpt; |
| 396 | } |
| 397 | else if ( !strcmp(parameter_value,"MTP3bttc")) |
| 398 | { |
| 399 | log("MTP3ServiceType is set to MTP3bttc"); |
| 400 | interpreter = &MTP3asp__PT_PROVIDER::MTP3_interpreter; |
| 401 | user_map_p = &MTP3asp__PT_PROVIDER::MTP3_user_map; |
| 402 | user_connect_p = &MTP3asp__PT_PROVIDER::MTP3_user_connect; |
| 403 | user_unmap_p = &MTP3asp__PT_PROVIDER::MTP3_user_unmap; |
| 404 | MTPServiceType = MTP3bttc; |
| 405 | } |
| 406 | else if ( !strcmp(parameter_value,"MTP3iup")) |
| 407 | { |
| 408 | log("MTP3ServiceType is set to MTP3iup"); |
| 409 | interpreter = &MTP3asp__PT_PROVIDER::MTP3_interpreter; |
| 410 | user_map_p = &MTP3asp__PT_PROVIDER::MTP3_user_map; |
| 411 | user_connect_p = &MTP3asp__PT_PROVIDER::MTP3_user_connect; |
| 412 | user_unmap_p = &MTP3asp__PT_PROVIDER::MTP3_user_unmap; |
| 413 | MTPServiceType = MTP3iup; |
| 414 | } |
| 415 | else if ( !strcmp(parameter_value,"STC")) |
| 416 | { |
| 417 | log("MTP3ServiceType is set to STC"); |
| 418 | interpreter = &MTP3asp__PT_PROVIDER::STC_interpreter; |
| 419 | user_map_p = &MTP3asp__PT_PROVIDER::STC_user_map; |
| 420 | user_connect_p = &MTP3asp__PT_PROVIDER::STC_user_connect; |
| 421 | user_unmap_p = &MTP3asp__PT_PROVIDER::STC_user_unmap; |
| 422 | MTPServiceType = STC; |
| 423 | } |
| 424 | #endif |
| 425 | else |
| 426 | { |
| 427 | log("Unsupported MTP3ServiceType: %s, falling back to MTP3itu", |
| 428 | parameter_value); |
| 429 | } |
| 430 | } |
| 431 | else if(strcasecmp(parameter_name, "forward_pause") == 0) |
| 432 | { |
| 433 | if (strcasecmp(parameter_value,"forward") == 0) |
| 434 | forward_pause = TRUE; |
| 435 | else if(strcasecmp(parameter_value,"ignore") == 0) |
| 436 | forward_pause = FALSE; |
| 437 | else |
| 438 | error("set_parameter(): Invalid parameter value: %s for parameter %s. Only forward and ignore can be used!" , |
| 439 | parameter_value, parameter_name); |
| 440 | } |
| 441 | else if(strcasecmp(parameter_name, "forward_resume") == 0) |
| 442 | { |
| 443 | if (strcasecmp(parameter_value,"forward") == 0) |
| 444 | forward_resume = TRUE; |
| 445 | else if(strcasecmp(parameter_value,"ignore") == 0) |
| 446 | forward_resume = FALSE; |
| 447 | else |
| 448 | error("set_parameter(): Invalid parameter value: %s for parameter %s. Only forward and ignore can be used!" , |
| 449 | parameter_value, parameter_name); |
| 450 | } |
| 451 | else if(strcasecmp(parameter_name, "forward_status") == 0) |
| 452 | { |
| 453 | if (strcasecmp(parameter_value,"forward") == 0) |
| 454 | forward_status = TRUE; |
| 455 | else if(strcasecmp(parameter_value,"ignore") == 0) |
| 456 | forward_status = FALSE; |
| 457 | else |
| 458 | error("set_parameter(): Invalid parameter value: %s for parameter %s. Only forward and ignore can be used!" , |
| 459 | parameter_value, parameter_name); |
| 460 | } |
| 461 | else |
| 462 | #ifdef TARGET_TEST |
| 463 | if(!parameter_set(parameter_name ,parameter_value)) //TCP parameters |
| 464 | #endif |
| 465 | log("Unsupported parameter: %s", parameter_name); |
| 466 | } |
| 467 | //------------ |
| 468 | |
| 469 | // User map |
| 470 | void MTP3asp__PT_PROVIDER::user_map(const char *system_port) |
| 471 | { |
| 472 | if (user_map_p == NULL) |
| 473 | error("Parameter MTP3ServiceType should be set to TargetM3UA in TARGET_TEST mode!"); |
| 474 | |
| 475 | (this->*user_map_p)(system_port); |
| 476 | } |
| 477 | //------------ |
| 478 | |
| 479 | // User unmap |
| 480 | void MTP3asp__PT_PROVIDER::user_unmap(const char *system_port) |
| 481 | { |
| 482 | (this->*user_unmap_p)(system_port); |
| 483 | } |
| 484 | //------------ |
| 485 | |
| 486 | #ifndef TARGET_TEST |
| 487 | // User connect |
| 488 | void MTP3asp__PT_PROVIDER::user_connect() |
| 489 | { |
| 490 | (this->*user_connect_p)(); |
| 491 | } |
| 492 | //------------ |
| 493 | #endif |
| 494 | |
| 495 | //User start |
| 496 | void MTP3asp__PT_PROVIDER::user_start() |
| 497 | { debuglog("user start ordered"); |
| 498 | } |
| 499 | //------------ |
| 500 | |
| 501 | //User stop |
| 502 | void MTP3asp__PT_PROVIDER::user_stop() |
| 503 | { debuglog("User stop ordered"); |
| 504 | } |
| 505 | //------------ |
| 506 | |
| 507 | //Event Handler |
| 508 | void MTP3asp__PT_PROVIDER::Handle_Fd_Event(int fd, |
| 509 | boolean is_readable, boolean is_writable, boolean is_error) |
| 510 | { |
| 511 | if (MTPServiceType == TargetM3UA ) |
| 512 | { |
| 513 | #ifdef TARGET_TEST |
| 514 | //In case of target Abstract Socket handles the received message |
| 515 | Handle_Socket_Event(fd, is_readable, is_writable, is_error); |
| 516 | #endif |
| 517 | } |
| 518 | #ifndef TARGET_TEST |
| 519 | else |
| 520 | { |
| 521 | int result; |
| 522 | |
| 523 | result = MPH_ProcessConnection(myConnection); |
| 524 | |
| 525 | if (result <= 0) |
| 526 | { |
| 527 | MPH_CloseConnection(myConnection); |
| 528 | if (result == 0) log("Connection closed by peer."); |
| 529 | else log("Error in incoming message."); |
| 530 | } |
| 531 | } |
| 532 | #endif |
| 533 | } |
| 534 | |
| 535 | void MTP3asp__PT_PROVIDER::Handle_Timeout(double time_since_last_call) |
| 536 | { |
| 537 | #ifdef TARGET_TEST |
| 538 | Handle_Timeout_Event(time_since_last_call); |
| 539 | #endif |
| 540 | } |
| 541 | //------------ |
| 542 | |
| 543 | //Outgoing send |
| 544 | void MTP3asp__PT_PROVIDER::outgoing_send(const ASP__MTP3__TRANSFERreq& send_par) |
| 545 | { |
| 546 | MTP3__Field__sio sio_field = send_par.sio(); |
| 547 | #ifndef TARGET_TEST |
| 548 | int si=bit2int(sio_field.si()); |
| 549 | #endif |
| 550 | |
| 551 | OCTETSTRING sio_oct = bit2oct(sio_field.ni()+sio_field.prio()+sio_field.si()); |
| 552 | OCTETSTRING bttc_oct = int2oct(stored_bttc_octet, 1); // additional octet for MTP3bttc |
| 553 | |
| 554 | //Message sending by testing on Target |
| 555 | if (MTPServiceType == TargetM3UA) |
| 556 | { |
| 557 | #ifdef TARGET_TEST |
| 558 | OCTETSTRING tcpData = int2oct(1,1); //Message type |
| 559 | tcpData = tcpData + int2oct(send_par.data().lengthof()+15,4); //Length |
| 560 | tcpData = tcpData + sio_oct; |
| 561 | tcpData = tcpData + int2oct(send_par.opc(),4); |
| 562 | tcpData = tcpData + int2oct(send_par.dpc(),4); |
| 563 | tcpData = tcpData + int2oct(send_par.sls(),1); |
| 564 | tcpData = tcpData + send_par.data(); |
| 565 | send_outgoing((const unsigned char*)tcpData,tcpData.lengthof()); |
| 566 | |
| 567 | TTCN_Logger::begin_event(TTCN_DEBUG); |
| 568 | TTCN_Logger::log_event("MTP3 Test Port (%s): ", get_name()); |
| 569 | TTCN_Logger::log_event_str("Transfer Req message sent: "); |
| 570 | tcpData.log(); |
| 571 | TTCN_Logger::end_event(); |
| 572 | #endif |
| 573 | return; |
| 574 | } |
| 575 | //Message sending by testing on Target |
| 576 | if (MTPServiceType == TargetSTC) |
| 577 | { |
| 578 | #ifdef TARGET_TEST |
| 579 | OCTETSTRING tcpData = int2oct(1,1); //Message type |
| 580 | tcpData = tcpData + int2oct(send_par.data().lengthof()+15,4); //Length |
| 581 | tcpData = tcpData + int2oct(0,1); |
| 582 | tcpData = tcpData + int2oct(0,4); |
| 583 | tcpData = tcpData + int2oct(0,4); |
| 584 | tcpData = tcpData + int2oct(0,1); |
| 585 | tcpData = tcpData + send_par.data(); |
| 586 | send_outgoing((const unsigned char*)tcpData,tcpData.lengthof()); |
| 587 | |
| 588 | TTCN_Logger::begin_event(TTCN_DEBUG); |
| 589 | TTCN_Logger::log_event("MTP3 Test Port (%s): ", get_name()); |
| 590 | TTCN_Logger::log_event_str("Transfer Req (STC) message sent: "); |
| 591 | tcpData.log(); |
| 592 | TTCN_Logger::end_event(); |
| 593 | #endif |
| 594 | return; |
| 595 | } |
| 596 | #ifndef TARGET_TEST |
| 597 | if (dynamicConnection &&(!connectionUp)) |
| 598 | { |
| 599 | warn("Connection was not activated via function f_M3UA_SEA_connect."); |
| 600 | return; |
| 601 | } |
| 602 | |
| 603 | unsigned int offset; |
| 604 | int MSU_length = send_par.data().lengthof(); |
| 605 | int M3UA_par_length; |
| 606 | int length; |
| 607 | int labellen; // sio+routinglabel length |
| 608 | |
| 609 | switch ( MTPServiceType) |
| 610 | { |
| 611 | case STC: |
| 612 | length = MSU_length; |
| 613 | memcpy(buffer, send_par.data(), send_par.data().lengthof()); |
| 614 | break; |
| 615 | case MTP3iup: |
| 616 | if(si==4) |
| 617 | { |
| 618 | offset = 0; |
| 619 | labellen=6; //ITU-T:sio(1byte) + standard telephony label(5byte) |
| 620 | length = MSU_length+labellen; |
| 621 | buffer[0] = *((const unsigned char*)sio_oct); |
| 622 | SetPointCodesIUP(send_par.sls(), send_par.opc(), send_par.dpc(), |
| 623 | buffer + offset + 1); |
| 624 | memcpy(buffer + offset + labellen, send_par.data(), send_par.data().lengthof()); |
| 625 | } |
| 626 | else |
| 627 | { |
| 628 | offset = 0; |
| 629 | labellen=5; //ITU-T:sio(1byte) + routing label(4byte) see /Q.704/15.4.1 |
| 630 | length = MSU_length + labellen; //SIF+SIO ; |
| 631 | //append MTP3 MSU |
| 632 | buffer[offset] = *((const unsigned char*)sio_oct); |
| 633 | SetPointCodes(send_par.sls(), send_par.opc(), send_par.dpc(), |
| 634 | buffer + offset + 1); |
| 635 | memcpy(buffer + offset + labellen, send_par.data(), send_par.data().lengthof()); |
| 636 | } |
| 637 | break; |
| 638 | case MTP3itu: |
| 639 | offset = 0; |
| 640 | labellen=5; //ITU-T:sio(1byte) + routing label(4byte) see /Q.704/15.4.1 |
| 641 | length = MSU_length + labellen; //SIF+SIO ; |
| 642 | //append MTP3 MSU |
| 643 | buffer[offset] = *((const unsigned char*)sio_oct); |
| 644 | SetPointCodes(send_par.sls(), send_par.opc(), send_par.dpc(), |
| 645 | buffer + offset + 1); |
| 646 | memcpy(buffer + offset + labellen, send_par.data(), send_par.data().lengthof()); |
| 647 | break; |
| 648 | case MTP3ansi: |
| 649 | offset = 0; |
| 650 | labellen=8; //ANSI: sio(1byte) +routing label(7byte) see T1.111.4 |
| 651 | length = MSU_length + labellen; //SIF+SIO ; |
| 652 | //append MTP3 MSU |
| 653 | buffer[offset] = *((const unsigned char*)sio_oct); |
| 654 | SetPointCodes(send_par.sls(), send_par.opc(), send_par.dpc(), |
| 655 | buffer + offset + 1); |
| 656 | memcpy(buffer + offset + labellen, send_par.data(), send_par.data().lengthof()); |
| 657 | break; |
| 658 | case MTP3ttc: |
| 659 | offset = 0; |
| 660 | //if (mtp3_ni==0){ labellen=5;} |
| 661 | //else { |
| 662 | labellen=6; |
| 663 | //} //TTC: sio(1byte) +routing label(6byte) see ... |
| 664 | length = MSU_length + labellen; //SIF+SIO ; |
| 665 | //append MTP3 MSU |
| 666 | buffer[offset] = *((const unsigned char*)sio_oct); |
| 667 | SetPointCodes(send_par.sls(), send_par.opc(), send_par.dpc(), |
| 668 | buffer + offset + 1); |
| 669 | memcpy(buffer + offset + labellen, send_par.data(), send_par.data().lengthof()); |
| 670 | break; |
| 671 | case MTP3bttc: |
| 672 | offset = 0; |
| 673 | buffer[offset] = *((const unsigned char*)bttc_oct); |
| 674 | offset += 1; |
| 675 | labellen=7; //routing label(7byte) |
| 676 | length = 1 + MSU_length + labellen; //SIF+SIO ; |
| 677 | //append MTP3 MSU |
| 678 | buffer[offset] = *((const unsigned char*)sio_oct); |
| 679 | SetPointCodes(send_par.sls(), send_par.opc(), send_par.dpc(), |
| 680 | buffer + offset + 1); |
| 681 | memcpy(buffer + offset + labellen, send_par.data(), send_par.data().lengthof()); |
| 682 | break; |
| 683 | case MTP3mpt: |
| 684 | offset = 0; |
| 685 | if (mtp3_ni==2) |
| 686 | { labellen=8;} //MPT national: sio(1byte) +routing label(7byte) |
| 687 | else |
| 688 | { labellen=5;} //MPT international: sio(1byte) +routing label(4byte) |
| 689 | length = MSU_length + labellen; //SIF+SIO ; |
| 690 | //append MTP3 MSU |
| 691 | buffer[offset] = *((const unsigned char*)sio_oct); |
| 692 | SetPointCodes(send_par.sls(), send_par.opc(), send_par.dpc(), |
| 693 | buffer + offset + 1); |
| 694 | memcpy(buffer + offset + labellen, |
| 695 | send_par.data(), send_par.data().lengthof()); |
| 696 | break; |
| 697 | case M3UA : |
| 698 | TTCN_Logger::begin_event(TTCN_DEBUG); |
| 699 | TTCN_Logger::log_event("MTP3 test port debug: Message to be encoded is: {"); |
| 700 | send_par.data().log(); |
| 701 | TTCN_Logger::log_event(" "); |
| 702 | if( M3UAState != AssocActive ) |
| 703 | { |
| 704 | TTCN_Logger::log_event(" M3UAState is not ready to send data. Its state code: %d",AssocActive); |
| 705 | TTCN_Logger::log_event("}"); |
| 706 | TTCN_Logger::end_event(); |
| 707 | return; |
| 708 | } |
| 709 | //calculating lengths |
| 710 | M3UA_par_length = MSU_length + 16; // ProtocolData parameter |
| 711 | // header length=16 <== see f |
| 712 | TTCN_Logger::log_event(", Adjusted M3UA_par_length to %d to support 16 octets M3UA param header",M3UA_par_length); |
| 713 | length = 8 + M3UA_par_length; //msg length = header+par |
| 714 | TTCN_Logger::log_event(", M3UA MSU_length is %d ==> there should be %d padding octets", MSU_length, 4-(MSU_length%4)); |
| 715 | if (MSU_length%4) { //should be padded to be multiple of 4 octets |
| 716 | length += 4 - (MSU_length%4); //padding shall be counted in msg |
| 717 | //length, but not in par_length |
| 718 | } |
| 719 | TTCN_Logger::log_event(", Set msg length (which includes 8 octets M3UA hdr) to %d ",length); |
| 720 | |
| 721 | //filling the first part of the buffer |
| 722 | //common msg hdr ====================================== |
| 723 | buffer[0] = M3UA_version; |
| 724 | buffer[1] = 0x00; //spare |
| 725 | buffer[2] = M3UA_MSG_CLS_TRNSFM; // msg class |
| 726 | buffer[3] = M3UA_MSG_TYP_TRSNFM_DATA; // msg type |
| 727 | encode_32b_int(buffer+4, length); //msg length, 4 bytes |
| 728 | //ProtocolData parameter header========================= |
| 729 | //tag |
| 730 | buffer[M3UA_MSG_OFFS] = PAR_PREFIX_M3UA; //par. tag 1st octet |
| 731 | buffer[M3UA_MSG_OFFS+1] = PAR_PROT_DATA; // par tag 2nd octet |
| 732 | //length, NOTE: should not contain the padding bytes! |
| 733 | encode_16b_int(buffer+M3UA_MSG_OFFS+2,M3UA_par_length); |
| 734 | //OPC,DPC |
| 735 | encode_32b_int(buffer+M3UA_MSG_OFFS+4,send_par.opc()); |
| 736 | encode_32b_int(buffer+M3UA_MSG_OFFS+8,send_par.dpc()); |
| 737 | //SI, NI, MP, SLS |
| 738 | buffer[M3UA_MSG_OFFS+12] = bit2int(sio_field.si()); // SI LSb aligned |
| 739 | buffer[M3UA_MSG_OFFS+13] = bit2int(sio_field.ni()); // NI LSb aligned |
| 740 | buffer[M3UA_MSG_OFFS+14] = bit2int(sio_field.prio()); //MP LSb |
| 741 | //aligned |
| 742 | buffer[M3UA_MSG_OFFS+15] = 0xFF & send_par.sls(); //SLS |
| 743 | // finally the MTP3 MSU itself.... |
| 744 | offset = M3UA_MSG_OFFS + 16; |
| 745 | TTCN_Logger::log_event(", buffer offset is now set to %d", offset); |
| 746 | TTCN_Logger::log_event("}"); |
| 747 | TTCN_Logger::end_event(); |
| 748 | //append MTP3 MSU |
| 749 | memcpy(buffer + offset, send_par.data(), send_par.data().lengthof()); |
| 750 | |
| 751 | //padding |
| 752 | for (int ii = 0; ii< (MSU_length%4); ++ii) buffer[offset+MSU_length+ii]= 0x00; |
| 753 | break; |
| 754 | default: |
| 755 | error("Invalid MTP3ServiceType setting!"); |
| 756 | } |
| 757 | if (TTCN_Logger::log_this_event(TTCN_DEBUG)) |
| 758 | { |
| 759 | TTCN_Logger::begin_event(TTCN_DEBUG); |
| 760 | TTCN_Logger::log_event("The encoded buffer is: {"); |
| 761 | OCTETSTRING(length, buffer).log(); |
| 762 | TTCN_Logger::log_event("}"); |
| 763 | TTCN_Logger::end_event(); |
| 764 | } |
| 765 | send_msg(buffer, length); |
| 766 | #endif |
| 767 | } |
| 768 | //------------ |
| 769 | |
| 770 | void MTP3asp__PT_PROVIDER::log(const char *msg, ...) |
| 771 | { |
| 772 | TTCN_Logger::begin_event(TTCN_PORTEVENT); |
| 773 | TTCN_Logger::log_event("MTP3 Test Port (%s): ", get_name()); |
| 774 | va_list ap; |
| 775 | va_start(ap, msg); |
| 776 | TTCN_Logger::log_event_va_list(msg, ap); |
| 777 | va_end(ap); |
| 778 | TTCN_Logger::end_event(); |
| 779 | } |
| 780 | //------------ |
| 781 | |
| 782 | void MTP3asp__PT_PROVIDER::warn(const char *msg, ...) |
| 783 | { |
| 784 | TTCN_Logger::begin_event(TTCN_WARNING); |
| 785 | TTCN_Logger::log_event("MTP3 Test Port (%s): ", get_name()); |
| 786 | va_list ap; |
| 787 | va_start(ap, msg); |
| 788 | TTCN_Logger::log_event_va_list(msg, ap); |
| 789 | va_end(ap); |
| 790 | TTCN_Logger::end_event(); |
| 791 | } |
| 792 | //------------ |
| 793 | |
| 794 | void MTP3asp__PT_PROVIDER::debuglog(const char *msg, ...) |
| 795 | { |
| 796 | TTCN_Logger::begin_event(TTCN_DEBUG); |
| 797 | TTCN_Logger::log_event("MTP3 Test Port (%s): ", get_name()); |
| 798 | va_list ap; |
| 799 | va_start(ap, msg); |
| 800 | TTCN_Logger::log_event_va_list(msg, ap); |
| 801 | va_end(ap); |
| 802 | TTCN_Logger::end_event(); |
| 803 | } |
| 804 | //------------ |
| 805 | |
| 806 | void MTP3asp__PT_PROVIDER::error(const char *msg, ...) |
| 807 | { |
| 808 | TTCN_Logger::begin_event(TTCN_ERROR); |
| 809 | TTCN_Logger::log_event("MTP3 Test Port (%s): ", get_name()); |
| 810 | va_list ap; |
| 811 | va_start(ap, msg); |
| 812 | TTCN_Logger::log_event_va_list(msg, ap); |
| 813 | va_end(ap); |
| 814 | TTCN_Logger::end_event(); |
| 815 | TTCN_error("Fatal error in MTP3 Test Port %s.", get_name()); |
| 816 | } |
| 817 | //------------ |
| 818 | |
| 819 | void MTP3asp__PT_PROVIDER::close_log_event() |
| 820 | { |
| 821 | TTCN_Logger::log_event("}"); |
| 822 | TTCN_Logger::end_event(); |
| 823 | } |
| 824 | //------------ |
| 825 | |
| 826 | |
| 827 | #ifndef TARGET_TEST |
| 828 | // -------------------------------------------- |
| 829 | // Functions and definitions for test with SEA |
| 830 | // -------------------------------------------- |
| 831 | |
| 832 | // Functions of MPH toolkit |
| 833 | // --------------------------- |
| 834 | void connectCallback(CONNECTION* con, int channel, void *clientData) |
| 835 | { |
| 836 | ((MTP3asp__PT_PROVIDER *)clientData)->log("Opening channel succeeded " |
| 837 | "(channel number is %u)", channel); |
| 838 | ((MTP3asp__PT_PROVIDER *)clientData)->set_channel(channel); |
| 839 | if(((MTP3asp__PT_PROVIDER *)clientData)->dynamicConnection) |
| 840 | ((MTP3asp__PT_PROVIDER *)clientData)->conn_state = 1; |
| 841 | } |
| 842 | |
| 843 | void messageCallback(CONNECTION* con, int channel, int length, |
| 844 | unsigned char *msg, void *clientData) |
| 845 | { |
| 846 | ((MTP3asp__PT_PROVIDER *)clientData)->log("Incoming message from channel: %d",channel); |
| 847 | ((MTP3asp__PT_PROVIDER *)clientData)->doInterpret(msg,length,channel,con); |
| 848 | } |
| 849 | |
| 850 | void closeCallback(CONNECTION* con, int channel, void *clientData) |
| 851 | { |
| 852 | ((MTP3asp__PT_PROVIDER *)clientData)->log("Closed channel: %d", channel); |
| 853 | } |
| 854 | |
| 855 | void errorCallback(CONNECTION* con, char *name, char *errorMessage, |
| 856 | void *clientData) |
| 857 | { |
| 858 | if(((MTP3asp__PT_PROVIDER *)clientData)->dynamicConnection) |
| 859 | { |
| 860 | ((MTP3asp__PT_PROVIDER *)clientData)->log("Opening channel %s failed: %s", name, errorMessage); |
| 861 | ((MTP3asp__PT_PROVIDER *)clientData)->conn_state = 2; |
| 862 | } |
| 863 | else |
| 864 | ((MTP3asp__PT_PROVIDER *)clientData)->error("Opening channel %s failed: %s", |
| 865 | name, errorMessage); |
| 866 | } |
| 867 | //------------ |
| 868 | |
| 869 | //MTP3_open_channel |
| 870 | void MTP3asp__PT_PROVIDER::MTP3_open_channel(boolean http) |
| 871 | { |
| 872 | int result; |
| 873 | int Mphport; |
| 874 | char *perrorString; |
| 875 | if( Loop == MTP3_ON ) |
| 876 | { |
| 877 | MTP_fd=-1; |
| 878 | myConnection = NULL; |
| 879 | log("MTP3_open_channel finished for LOOP"); |
| 880 | return; |
| 881 | } |
| 882 | |
| 883 | if(http) |
| 884 | { |
| 885 | Mphport = MPH_GetMphPort(hostname,httpport,&perrorString); |
| 886 | } |
| 887 | else |
| 888 | { |
| 889 | Mphport = httpport; |
| 890 | } |
| 891 | |
| 892 | if (Mphport == -1) |
| 893 | error("GetMphPort failed: %s", *perrorString); |
| 894 | |
| 895 | result = MPH_StringToIid(iid_string, &iid); |
| 896 | if (result == -1) |
| 897 | error("Converting %s to MPH_IID failed.", iid_string); |
| 898 | |
| 899 | myConnection = MPH_OpenConnection(hostname, Mphport); |
| 900 | if (myConnection == NULL) |
| 901 | error("Opening connection to %s:%d failed.", hostname, Mphport); |
| 902 | |
| 903 | MPH_OpenChannel(myConnection, |
| 904 | entityname, |
| 905 | &iid, |
| 906 | connectCallback, |
| 907 | messageCallback, |
| 908 | closeCallback, |
| 909 | errorCallback, |
| 910 | this); |
| 911 | |
| 912 | MTP_fd = MPH_GetConnectionFd(myConnection); |
| 913 | if (MTP_fd != -1) |
| 914 | Handler_Add_Fd_Read(MTP_fd); |
| 915 | else |
| 916 | error("Incorrect file descriptor: %d.", MTP_fd); |
| 917 | } |
| 918 | //------------ |
| 919 | |
| 920 | // MTP3_close_connection |
| 921 | void MTP3asp__PT_PROVIDER::MTP3_close_connection() |
| 922 | { |
| 923 | MPH_CloseConnection(myConnection); |
| 924 | Handler_Remove_Fd_Read(MTP_fd); |
| 925 | close( MTP_fd ); |
| 926 | //Uninstall_Handler(); // Unnecessary if only socket MTP_fd is in use |
| 927 | } |
| 928 | //------------ |
| 929 | |
| 930 | // wait_for_open |
| 931 | boolean MTP3asp__PT_PROVIDER::wait_for_open() |
| 932 | { |
| 933 | conn_state = 0; |
| 934 | while(conn_state==0) |
| 935 | { |
| 936 | pollfd pollFd = { MTP_fd, POLLIN, 0 }; |
| 937 | int nEvents = poll(&pollFd, 1, 3000 /* ms */); |
| 938 | if (nEvents == 0) { |
| 939 | log("MPH channel opening time out"); |
| 940 | return FALSE; |
| 941 | } |
| 942 | if (nEvents < 0 || (pollFd.revents & (POLLIN | POLLHUP)) == 0) { |
| 943 | log("MPH channel opening error (%d)", (nEvents < 0) ? errno : 0); |
| 944 | return FALSE; |
| 945 | } |
| 946 | Handle_Fd_Event(MTP_fd, TRUE, FALSE, FALSE); |
| 947 | } |
| 948 | if(conn_state == 1) //connectCallback received |
| 949 | { |
| 950 | conn_state = 0; |
| 951 | return TRUE; |
| 952 | } |
| 953 | else //errorCallback received |
| 954 | { |
| 955 | conn_state = 0; |
| 956 | return FALSE; |
| 957 | } |
| 958 | } |
| 959 | //------------ |
| 960 | |
| 961 | //send msg |
| 962 | void MTP3asp__PT_PROVIDER::send_msg(unsigned char *outbuff, int length) |
| 963 | { |
| 964 | OCTETSTRING buff(length,outbuff); |
| 965 | TTCN_Logger::begin_event(TTCN_DEBUG); |
| 966 | TTCN_Logger::log_event("MTP3/M3UA Test Port (%s): {", get_name()); |
| 967 | TTCN_Logger::log_event("outgoing buffer= "); |
| 968 | buff.log(); |
| 969 | TTCN_Logger::log_event("}"); |
| 970 | TTCN_Logger::end_event(); |
| 971 | if (Loop == MTP3_ON) |
| 972 | { |
| 973 | log("Message looped back"); |
| 974 | doInterpret(outbuff, length, channel, myConnection); |
| 975 | } else |
| 976 | { |
| 977 | MPH_SendMessage(myConnection,channel,length,outbuff); |
| 978 | log("Message sent on channel %d", channel); |
| 979 | } |
| 980 | } |
| 981 | //------------ |
| 982 | |
| 983 | //Check TestPortVariables |
| 984 | void MTP3asp__PT_PROVIDER::Check_TestPort_Variables() |
| 985 | { |
| 986 | if(!dynamicConnection) |
| 987 | { |
| 988 | if (httpport==-1) error("Parameter HttpPort is not set."); |
| 989 | if (hostname==NULL) error("Parameter Hostname is not set."); |
| 990 | if (entityname==NULL) error("Parameter EntityName is not set."); |
| 991 | } |
| 992 | if (Filter==-1) error("Parameter Filter is not set."); |
| 993 | if (Loop==-1) error("Parameter Loop is not set."); |
| 994 | if (Sut_Pc==-1) error("Parameter SUT_Pc is not set."); |
| 995 | if (Tester_Pc==-1) error("Parameter TESTER_Pc is not set."); |
| 996 | if (!Ni_is_set) error("Parameter NI is not set."); |
| 997 | } |
| 998 | //------------ |
| 999 | |
| 1000 | // ------------------------------------------------- |
| 1001 | // STC Functions and definitions for test with SEA |
| 1002 | // ------------------------------------------------- |
| 1003 | void MTP3asp__PT_PROVIDER::Check_TestPort_Variables_STC() |
| 1004 | { |
| 1005 | if(!dynamicConnection) |
| 1006 | { |
| 1007 | if (httpport==-1) error("Parameter HttpPort is not set."); |
| 1008 | if (hostname==NULL) error("Parameter Hostname is not set."); |
| 1009 | if (entityname==NULL) error("Parameter EntityName is not set."); |
| 1010 | } |
| 1011 | } |
| 1012 | //------------ |
| 1013 | |
| 1014 | //STC user map |
| 1015 | void MTP3asp__PT_PROVIDER::STC_user_map(const char *system_port) |
| 1016 | { |
| 1017 | debuglog("Function STC_user_map started"); |
| 1018 | Check_TestPort_Variables_STC(); |
| 1019 | if(dynamicConnection) |
| 1020 | { |
| 1021 | connectionUp = FALSE; |
| 1022 | } |
| 1023 | else |
| 1024 | { |
| 1025 | MTP3_open_channel(TRUE); |
| 1026 | STC_user_connect(); |
| 1027 | } |
| 1028 | } |
| 1029 | //------------ |
| 1030 | |
| 1031 | //STC user connect |
| 1032 | void MTP3asp__PT_PROVIDER::STC_user_connect() |
| 1033 | { |
| 1034 | } |
| 1035 | |
| 1036 | //STC user unmap |
| 1037 | void MTP3asp__PT_PROVIDER::STC_user_unmap(const char *system_port) |
| 1038 | { |
| 1039 | MTP3_close_connection(); |
| 1040 | dynamicConnection = FALSE; |
| 1041 | } |
| 1042 | //------------ |
| 1043 | |
| 1044 | //STC interpreter |
| 1045 | void MTP3asp__PT_PROVIDER::STC_interpreter(unsigned char* inbuffer,int length,int from_channel,CONNECTION* con) |
| 1046 | { |
| 1047 | if ((length==0) || (inbuffer==NULL)) |
| 1048 | { |
| 1049 | log("0 byte long message received -> packet dropped."); |
| 1050 | return; |
| 1051 | } |
| 1052 | |
| 1053 | if (length==1) |
| 1054 | { |
| 1055 | log("1 byte long internal SEA message received -> packet dropped."); |
| 1056 | return; |
| 1057 | } |
| 1058 | |
| 1059 | if ( !strcmp((const char*)inbuffer,"start") ) |
| 1060 | { |
| 1061 | log("start message received from SEA"); |
| 1062 | return; |
| 1063 | } |
| 1064 | else if (!strcmp((const char*)inbuffer,"stop")) |
| 1065 | { |
| 1066 | log("stop message received from SEA"); |
| 1067 | return; |
| 1068 | } |
| 1069 | |
| 1070 | // writing out the contents of the buffer |
| 1071 | OCTETSTRING buff(length,inbuffer); |
| 1072 | TTCN_Logger::begin_event(TTCN_PORTEVENT); |
| 1073 | TTCN_Logger::log_event("incoming buffer: "); |
| 1074 | buff.log(); |
| 1075 | TTCN_Logger::end_event(); |
| 1076 | |
| 1077 | ASP__MTP3__TRANSFERind recv_msg; |
| 1078 | MTP3__Field__sio recv_sio; |
| 1079 | recv_sio.ni()= int2bit(0,2); |
| 1080 | recv_sio.prio()= int2bit(0,2); |
| 1081 | recv_sio.si()= int2bit(0,4); |
| 1082 | recv_msg.sio() = recv_sio; |
| 1083 | recv_msg.sls() = 0; |
| 1084 | recv_msg.opc() = 0; |
| 1085 | recv_msg.dpc() = 0; |
| 1086 | recv_msg.data() = OCTETSTRING(length, &inbuffer[0]); |
| 1087 | incoming_message( recv_msg ); |
| 1088 | } |
| 1089 | |
| 1090 | // ------------------------------------------------- |
| 1091 | // MTP3 Functions and definitions for test with SEA |
| 1092 | // ------------------------------------------------- |
| 1093 | |
| 1094 | // SLTM messages for MTP3 |
| 1095 | // ----------------------- |
| 1096 | unsigned char ttcn_in_sltm[] = { |
| 1097 | 'T','T','C','N','-','3',' ','E','x','e','c','u','t','o','r'}; |
| 1098 | |
| 1099 | const int sizeof_ttcn_in_sltm=15; |
| 1100 | |
| 1101 | // ITU: |
| 1102 | unsigned char sltm_msg_itu[] = |
| 1103 | { |
| 1104 | 0x1, //SIO /'test & maint' see Q.704 /14.2.1 => 0x81 suggested !!! |
| 1105 | 0x0, 0x0, 0x0, 0x0, //4 bytes for label (dpc, opc,sls) |
| 1106 | 0x11, //Heading code ITU, see Q.707/5.4 |
| 1107 | 0xF0, //spare+Length of the following string: |
| 1108 | 'T', 'T', 'C', 'N', '-', '3', ' ', 'E', 'x', 'e', 'c', 'u', 't', 'o', 'r' |
| 1109 | }; |
| 1110 | const int sizeof_sltm_msg_itu=7+15; |
| 1111 | |
| 1112 | // ANSI: |
| 1113 | unsigned char sltm_msg_ansi[]= |
| 1114 | { |
| 1115 | 0xB1, //SIO |
| 1116 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0, // 7 bytes for label |
| 1117 | 0x11, // Heading Code ANSI T1.111.7-2001 |
| 1118 | 0xF0, // SLC(is 0 OK???)+Length in bytes of the following string: |
| 1119 | 'T', 'T', 'C', 'N', '-', '3', ' ', 'E', 'x', 'e', 'c', 'u', 't', 'o', 'r' |
| 1120 | }; |
| 1121 | const int sizeof_sltm_ansi=10+15; |
| 1122 | |
| 1123 | // TTC: |
| 1124 | unsigned char sltm_msg_ttc_national[]= |
| 1125 | { |
| 1126 | 0x81, //SIO |
| 1127 | 0x0,0x0,0x0,0x0,0x0,0x0, // 6 bytes for label TO BE CONT!!! |
| 1128 | 0x11, // Heading Code |
| 1129 | 0xF0, // SLC(is 0 OK???)+Length in bytes of the following string: |
| 1130 | 'T', 'T', 'C', 'N', '-', '3', ' ', 'E', 'x', 'e', 'c', 'u', 't', 'o', 'r' |
| 1131 | }; |
| 1132 | const int sizeof_sltm_msg_ttc_national=9+15; |
| 1133 | |
| 1134 | // BTTC: |
| 1135 | unsigned char sltm_msg_bttc_national[]= |
| 1136 | { |
| 1137 | 0x0, // extra octet, ignored |
| 1138 | 0x81, //SIO |
| 1139 | 0x0,0x0,0x0,0x0,0x0,0x0, // 6 bytes for label TO BE CONT!!! |
| 1140 | 0x23, // Heading Code |
| 1141 | 'T', 'T' |
| 1142 | }; |
| 1143 | const int sizeof_sltm_msg_bttc_national=1+8+2; |
| 1144 | |
| 1145 | // MPT: |
| 1146 | unsigned char sltm_msg_mpt_national[]= |
| 1147 | { |
| 1148 | 0x81, //SIO |
| 1149 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0, // 7 bytes for label |
| 1150 | 0x11, // Heading Code |
| 1151 | 0xF0, // SLC(is 0 OK???)+Length in bytes of the following string: |
| 1152 | 'T', 'T', 'C', 'N', '-', '3', ' ', 'E', 'x', 'e', 'c', 'u', 't', 'o', 'r' |
| 1153 | }; |
| 1154 | const int sizeof_sltm_msg_mpt_national=10+15; |
| 1155 | //------------ |
| 1156 | |
| 1157 | |
| 1158 | // coder functions for MTP3 |
| 1159 | // ------------------------- |
| 1160 | // unsigned int<-> unsigned char array |
| 1161 | // Integer encode/decode functions that will encode/decode from/to |
| 1162 | // Result: Least Significant Byte first (in lowest address) = LSB = Little Endian |
| 1163 | void MTP3asp__PT_PROVIDER::encode_56bLSB_int(unsigned char *to, unsigned long long int from) |
| 1164 | { |
| 1165 | to[0] = from & 0xFF; |
| 1166 | from >>= 8; |
| 1167 | to[1] = from & 0xFF; |
| 1168 | from >>= 8; |
| 1169 | to[2] = from & 0xFF; |
| 1170 | from >>= 8; |
| 1171 | to[3] = from & 0xFF; |
| 1172 | from >>= 8; |
| 1173 | to[4] = from & 0xFF; |
| 1174 | from >>= 8; |
| 1175 | to[5] = from & 0xFF; |
| 1176 | from >>= 8; |
| 1177 | to[6] = from & 0xFF; |
| 1178 | } |
| 1179 | //------------ |
| 1180 | |
| 1181 | unsigned long long int MTP3asp__PT_PROVIDER::decode_56bLSB_int(const unsigned char *from) |
| 1182 | { |
| 1183 | typedef unsigned long long int ull; |
| 1184 | return ((ull) from[0]) | |
| 1185 | ((ull) from[1] <<8)| |
| 1186 | ((ull) from[2] << 16)| |
| 1187 | ((ull) from[3] << 24)| |
| 1188 | ((ull) from[4] << 32)| |
| 1189 | ((ull) from[5] << 40)| |
| 1190 | ((ull) from[6] << 48); |
| 1191 | } |
| 1192 | //------------ |
| 1193 | |
| 1194 | void MTP3asp__PT_PROVIDER::encode_48bLSB_int(unsigned char *to, unsigned long long int from) |
| 1195 | { |
| 1196 | to[0] = from & 0xFF; |
| 1197 | from >>= 8; |
| 1198 | to[1] = from & 0xFF; |
| 1199 | from >>= 8; |
| 1200 | to[2] = from & 0xFF; |
| 1201 | from >>= 8; |
| 1202 | to[3] = from & 0xFF; |
| 1203 | from >>= 8; |
| 1204 | to[4] = from & 0xFF; |
| 1205 | from >>= 8; |
| 1206 | to[5] = from & 0xFF; |
| 1207 | } |
| 1208 | //------------ |
| 1209 | |
| 1210 | unsigned long long int MTP3asp__PT_PROVIDER::decode_48bLSB_int(const unsigned char *from) |
| 1211 | { |
| 1212 | typedef unsigned long long int ull; |
| 1213 | return ((ull) from[0]) | |
| 1214 | ((ull) from[1] <<8)| |
| 1215 | ((ull) from[2] << 16)| |
| 1216 | ((ull) from[3] << 24)| |
| 1217 | ((ull) from[4] << 32)| |
| 1218 | ((ull) from[5] << 40); |
| 1219 | } |
| 1220 | //------------ |
| 1221 | |
| 1222 | void MTP3asp__PT_PROVIDER::encode_40bLSB_int(unsigned char *to, unsigned long long int from) |
| 1223 | { |
| 1224 | to[0] = from & 0xFF; |
| 1225 | from >>= 8; |
| 1226 | to[1] = from & 0xFF; |
| 1227 | from >>= 8; |
| 1228 | to[2] = from & 0xFF; |
| 1229 | from >>= 8; |
| 1230 | to[3] = from & 0xFF; |
| 1231 | from >>= 8; |
| 1232 | to[4] = from & 0xFF; |
| 1233 | } |
| 1234 | //------------ |
| 1235 | |
| 1236 | unsigned long long int MTP3asp__PT_PROVIDER::decode_40bLSB_int(const unsigned char *from) |
| 1237 | { |
| 1238 | typedef unsigned long long int ull; |
| 1239 | return ((ull) from[0]) | |
| 1240 | ((ull) from[1] <<8)| |
| 1241 | ((ull) from[2] << 16)| |
| 1242 | ((ull) from[3] << 24)| |
| 1243 | ((ull) from[4] << 32); |
| 1244 | } |
| 1245 | //------------ |
| 1246 | |
| 1247 | void MTP3asp__PT_PROVIDER::encode_32bLSB_int(unsigned char *to, unsigned int from) |
| 1248 | { |
| 1249 | to[0] = from & 0xFF; |
| 1250 | from >>= 8; |
| 1251 | to[1] = from & 0xFF; |
| 1252 | from >>= 8; |
| 1253 | to[2] = from & 0xFF; |
| 1254 | from >>= 8; |
| 1255 | to[3] = from & 0xFF; |
| 1256 | } |
| 1257 | //------------ |
| 1258 | |
| 1259 | unsigned int MTP3asp__PT_PROVIDER::decode_32bLSB_int(const unsigned char *from) |
| 1260 | { |
| 1261 | return from[0] | (from[1] << 8) | (from[2] << 16) | (from[3] << 24); |
| 1262 | } |
| 1263 | //------------ |
| 1264 | |
| 1265 | void MTP3asp__PT_PROVIDER::encode_24bLSB_int(unsigned char *to, int from) |
| 1266 | { |
| 1267 | to[0] = from & 0xFF; |
| 1268 | from >>= 8; |
| 1269 | to[1] = from & 0xFF; |
| 1270 | from >>= 8; |
| 1271 | to[2] = from & 0xFF; |
| 1272 | } |
| 1273 | //------------ |
| 1274 | |
| 1275 | unsigned int MTP3asp__PT_PROVIDER::decode_24bLSB_int(const unsigned char *from) |
| 1276 | { |
| 1277 | return from[0] | (from[1] << 8) | (from[2] << 16); |
| 1278 | } |
| 1279 | //------------ |
| 1280 | |
| 1281 | void MTP3asp__PT_PROVIDER::encode_16bLSB_int(unsigned char *to, int from) |
| 1282 | { |
| 1283 | to[0] = from & 0xFF; |
| 1284 | from >>= 8; |
| 1285 | to[1] = from & 0xFF; |
| 1286 | } |
| 1287 | //------------ |
| 1288 | |
| 1289 | unsigned int MTP3asp__PT_PROVIDER::decode_16bLSB_int(const unsigned char *from) |
| 1290 | { |
| 1291 | return from[0] | (from[1] << 8); |
| 1292 | } |
| 1293 | //------------ |
| 1294 | |
| 1295 | //MTP3 user map |
| 1296 | void MTP3asp__PT_PROVIDER::MTP3_user_map(const char *system_port) |
| 1297 | { |
| 1298 | debuglog("Function MTP3_user_map started"); |
| 1299 | Check_TestPort_Variables(); |
| 1300 | if(dynamicConnection) |
| 1301 | { |
| 1302 | connectionUp = FALSE; |
| 1303 | } |
| 1304 | else |
| 1305 | { |
| 1306 | MTP3_open_channel(TRUE); |
| 1307 | MTP3_user_connect(); |
| 1308 | } |
| 1309 | debuglog("Function MTP3_user_map finished"); |
| 1310 | } |
| 1311 | //------------ |
| 1312 | |
| 1313 | //MTP3 user connect |
| 1314 | void MTP3asp__PT_PROVIDER::MTP3_user_connect() |
| 1315 | { |
| 1316 | // Sending out an SLTM message: |
| 1317 | unsigned char * sltm_msg; |
| 1318 | unsigned int offset = 0; |
| 1319 | int sizeof_msg; |
| 1320 | switch( MTPServiceType) |
| 1321 | { |
| 1322 | case MTP3itu: |
| 1323 | case MTP3iup: |
| 1324 | sltm_msg=sltm_msg_itu; |
| 1325 | sizeof_msg=sizeof_sltm_msg_itu; |
| 1326 | break; |
| 1327 | case MTP3ansi: |
| 1328 | sltm_msg=sltm_msg_ansi; |
| 1329 | sizeof_msg=sizeof_sltm_ansi; |
| 1330 | break; |
| 1331 | case MTP3ttc: |
| 1332 | /* if (mtp3_ni == 0){ |
| 1333 | sltm_msg=sltm_msg_itu; |
| 1334 | sizeof_msg=sizeof_sltm_msg_itu; |
| 1335 | } |
| 1336 | else { |
| 1337 | */ |
| 1338 | sltm_msg=sltm_msg_ttc_national; |
| 1339 | sizeof_msg=sizeof_sltm_msg_ttc_national; |
| 1340 | // } |
| 1341 | break; |
| 1342 | case MTP3bttc: |
| 1343 | sltm_msg=sltm_msg_bttc_national; |
| 1344 | sizeof_msg=sizeof_sltm_msg_bttc_national; |
| 1345 | offset = 1; |
| 1346 | break; |
| 1347 | case MTP3mpt: |
| 1348 | if (mtp3_ni == 2) |
| 1349 | { |
| 1350 | sltm_msg = sltm_msg_mpt_national; |
| 1351 | sizeof_msg = sizeof_sltm_msg_mpt_national; |
| 1352 | } else |
| 1353 | { |
| 1354 | sltm_msg = sltm_msg_itu; |
| 1355 | sizeof_msg = sizeof_sltm_msg_itu; |
| 1356 | } |
| 1357 | break; |
| 1358 | default: |
| 1359 | sltm_msg=sltm_msg_itu; |
| 1360 | sizeof_msg=sizeof_sltm_msg_itu; |
| 1361 | break; |
| 1362 | } |
| 1363 | stored_bttc_octet = 0; |
| 1364 | unsigned char sio = ((unsigned char) mtp3_ni) << 6; |
| 1365 | |
| 1366 | if (Ni_is_set) |
| 1367 | { sltm_msg[0+offset] = sio | 0x1; } |
| 1368 | else |
| 1369 | { sltm_msg[0+offset] = 0x1; };//SIO /'test & maint' see Q.704 /14.2.1 => 0x81 suggested !!! |
| 1370 | |
| 1371 | SetPointCodes(0, Tester_Pc, Sut_Pc, sltm_msg + 1 +offset); // common for ITU, ANSI and TTC |
| 1372 | log("MTP3/SLTM message sending..."); |
| 1373 | send_msg(sltm_msg, sizeof_msg); |
| 1374 | } |
| 1375 | //MTP3 user unmap |
| 1376 | void MTP3asp__PT_PROVIDER::MTP3_user_unmap(const char *system_port) |
| 1377 | { |
| 1378 | MTP3_close_connection(); |
| 1379 | dynamicConnection = FALSE; |
| 1380 | } |
| 1381 | |
| 1382 | //MTP3 interpreter |
| 1383 | void MTP3asp__PT_PROVIDER::MTP3_interpreter(unsigned char* inbuffer,int length,int from_channel,CONNECTION* con) |
| 1384 | { |
| 1385 | if ((length==0) || (inbuffer==NULL)) |
| 1386 | { |
| 1387 | log("0 byte long message received -> packet dropped."); |
| 1388 | return; |
| 1389 | } |
| 1390 | |
| 1391 | if (length==1) |
| 1392 | { |
| 1393 | log("1 byte long internal SEA message received -> packet dropped."); |
| 1394 | return; |
| 1395 | } |
| 1396 | |
| 1397 | if ( !strcmp((const char*)inbuffer,"start") ) |
| 1398 | { |
| 1399 | log("start message received from SEA"); |
| 1400 | return; |
| 1401 | } |
| 1402 | else if (!strcmp((const char*)inbuffer,"stop")) |
| 1403 | { |
| 1404 | log("stop message received from SEA"); |
| 1405 | return; |
| 1406 | } |
| 1407 | |
| 1408 | // writing out the contents of the buffer |
| 1409 | OCTETSTRING buff(length,inbuffer); |
| 1410 | TTCN_Logger::begin_event(TTCN_PORTEVENT); |
| 1411 | TTCN_Logger::log_event("incoming buffer: "); |
| 1412 | buff.log(); |
| 1413 | TTCN_Logger::end_event(); |
| 1414 | |
| 1415 | unsigned int offset = 0; |
| 1416 | if ( MTPServiceType==MTP3bttc ) |
| 1417 | { |
| 1418 | stored_bttc_octet = inbuffer[0]; |
| 1419 | offset = 1; |
| 1420 | } |
| 1421 | int labellen; // sio+routinglabel length |
| 1422 | int rec_ni = (inbuffer[offset]) >> 6; //network indicator |
| 1423 | if (rec_ni != mtp3_ni) |
| 1424 | error("Received NI is different from sent NI."); |
| 1425 | |
| 1426 | unsigned char sio = inbuffer[offset]; |
| 1427 | unsigned int si = sio&0x0F; |
| 1428 | |
| 1429 | if ( MTPServiceType==MTP3itu ) |
| 1430 | { labellen=5; //ITU-T:sio(1byte) + routing label(4byte) see /Q.704/15.4.1 |
| 1431 | } |
| 1432 | else if ( MTPServiceType==MTP3iup ) |
| 1433 | { |
| 1434 | if(si==4) |
| 1435 | labellen=6; //ITU-T:sio(1byte) + standard telephony label(5byte) |
| 1436 | else |
| 1437 | labellen=5; //ITU-T:sio(1byte) + routing label(4byte) see /Q.704/15.4.1 |
| 1438 | } |
| 1439 | else if ( MTPServiceType==MTP3ansi ) |
| 1440 | { labellen=8; //ANSI: sio(1byte) +routing label(7byte) see T1.111.4 |
| 1441 | } |
| 1442 | else if (MTPServiceType==MTP3ttc) |
| 1443 | { labellen=6; //new (2004-03-02): 6= sio(1byte)+ routing label(5bytes) |
| 1444 | } |
| 1445 | else if (MTPServiceType==MTP3mpt) |
| 1446 | { |
| 1447 | if ( mtp3_ni == 2) |
| 1448 | {labellen=8;} //MPT national: sio(1byte) +routing label(7byte) |
| 1449 | else |
| 1450 | {labellen=5;} //MPT international: sio(1byte) +routing label(4byte) |
| 1451 | } |
| 1452 | else if (MTPServiceType==MTP3bttc) |
| 1453 | { labellen=7; //7= sio(1byte)+ routing label(6bytes) |
| 1454 | } |
| 1455 | else |
| 1456 | { log("incorrect MTPServiceType - programming error-> packet dropped"); |
| 1457 | return; |
| 1458 | } |
| 1459 | |
| 1460 | // checking SIO field (first incoming byte) - management or test message |
| 1461 | switch (si) |
| 1462 | { |
| 1463 | case 0: processing_MTP3_management_msg(inbuffer+offset,length-offset); |
| 1464 | return; |
| 1465 | case 1: //MTP3itu |
| 1466 | case 2: processing_MTP3_test_msg(inbuffer+offset,length-offset); //MTP3ansi |
| 1467 | return; |
| 1468 | default: |
| 1469 | break; |
| 1470 | } |
| 1471 | |
| 1472 | // filling up TTCN structure |
| 1473 | if ((Loop==MTP3_ON) || (!Filter) || (Filter&&Check_PcMatch(Sut_Pc,Tester_Pc,&inbuffer[offset+1]))) |
| 1474 | { |
| 1475 | ASP__MTP3__TRANSFERind recv_msg; |
| 1476 | MTP3__Field__sio recv_sio; |
| 1477 | BITSTRING sio_bit = oct2bit(OCTETSTRING(1,inbuffer+offset)); |
| 1478 | recv_sio.ni()= substr(sio_bit,0,2); |
| 1479 | recv_sio.prio()= substr(sio_bit,2,2); |
| 1480 | recv_sio.si()= substr(sio_bit,4,4); |
| 1481 | recv_msg.sio() = recv_sio; |
| 1482 | unsigned int sls,opc,dpc; |
| 1483 | if ( (MTPServiceType==MTP3iup) && (si==4) ) |
| 1484 | GetPointCodesIUP(sls,opc,dpc,&inbuffer[1]); |
| 1485 | else |
| 1486 | GetPointCodes(sls,opc,dpc,&inbuffer[offset+1]); |
| 1487 | recv_msg.sls() = sls; |
| 1488 | recv_msg.opc() = opc; |
| 1489 | recv_msg.dpc() = dpc; |
| 1490 | int len; |
| 1491 | len= length-labellen-offset; //len= length-labellen; |
| 1492 | recv_msg.data() = OCTETSTRING(len, &inbuffer[offset+labellen]); |
| 1493 | incoming_message( recv_msg ); |
| 1494 | } |
| 1495 | else |
| 1496 | { log("The rooting label (OPC, DPC) not matched with the filter setting -> packet dropped."); |
| 1497 | return; |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | void MTP3asp__PT_PROVIDER::processing_MTP3_management_msg(unsigned char* inbuff,int len) |
| 1502 | { |
| 1503 | int outlen=0; |
| 1504 | int labellen; // sio+routinglabel length |
| 1505 | int chm_addlen; // (Changeback) additional length = Heading Code + SLC+ (changeback codes) |
| 1506 | int mim_addlen; // (MIM) -"- |
| 1507 | unsigned int offset = 0; |
| 1508 | OCTETSTRING bttc_oct = int2oct(stored_bttc_octet, 1); // additional octet for MTP3bttc |
| 1509 | |
| 1510 | if ( MTPServiceType==MTP3itu || MTPServiceType==MTP3iup) |
| 1511 | { labellen=5; //ITU-T:sio(1byte) + routing label(4byte) see /Q.704/15.4.1 |
| 1512 | chm_addlen = 2; |
| 1513 | mim_addlen = 1; |
| 1514 | } |
| 1515 | else if ( MTPServiceType==MTP3ansi ) |
| 1516 | { labellen=8; //ANSI: sio(1byte) +routing label(7byte) see T.1.111.4 |
| 1517 | chm_addlen = 3; |
| 1518 | mim_addlen = 2; |
| 1519 | } |
| 1520 | else if (MTPServiceType==MTP3ttc) |
| 1521 | { //if ( mtp3_ni == 0 ) { labellen=5;} //ITU-T:sio(1byte) + routing label(4byte) see /Q.704/15.4.1 |
| 1522 | //else { |
| 1523 | labellen=6; |
| 1524 | //} //sio(1byte)+ routing label(6bytes) see 3/15517-FAY 112 011/2 or jt-q704. |
| 1525 | } |
| 1526 | else if (MTPServiceType==MTP3mpt) |
| 1527 | { if ( mtp3_ni == 2 ) { labellen=8; } |
| 1528 | else { labellen=5; } |
| 1529 | chm_addlen = 2; |
| 1530 | mim_addlen = 1; |
| 1531 | } |
| 1532 | else if (MTPServiceType==MTP3bttc) |
| 1533 | { labellen=7;//sio(1byte)+routing label(6bytes) see 3/15517-FAY 112 011/2 or jt-q704 |
| 1534 | offset = 1; |
| 1535 | } |
| 1536 | else |
| 1537 | { log("incorrect MTPServiceType- programming error-> packet dropped"); |
| 1538 | return; |
| 1539 | } |
| 1540 | |
| 1541 | if (MTPServiceType==MTP3bttc) |
| 1542 | { |
| 1543 | buffer[0]=*((const unsigned char*)bttc_oct); //additional stored octet in front |
| 1544 | buffer[1]=inbuff[0]; //SIO |
| 1545 | if (!ChangePointCodes(&buffer[2],&inbuff[1],len)) |
| 1546 | { log("incorrect incoming management message -> packet dropped."); |
| 1547 | return; |
| 1548 | } |
| 1549 | } |
| 1550 | else |
| 1551 | { |
| 1552 | buffer[0]=inbuff[0]; //SIO |
| 1553 | if (!ChangePointCodes(&buffer[1],&inbuff[1],len)) |
| 1554 | { log("incorrect incoming management message -> packet dropped."); |
| 1555 | return; |
| 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | // Changeover & changeback(CHM) see ITU: Q.704/15.4.1 ANSI: T.1.111.4/15.2-4 |
| 1560 | if (inbuff[labellen]==0x51) //CBD |
| 1561 | { |
| 1562 | outlen=labellen+chm_addlen; |
| 1563 | if (len<outlen) |
| 1564 | { log("incorrect incoming CHM message -> packet dropped."); |
| 1565 | return; |
| 1566 | } |
| 1567 | else |
| 1568 | { buffer[offset + labellen]= 0x61; // Heading Code <- CBA |
| 1569 | memcpy(&buffer[offset + labellen+1],&inbuff[labellen+1],len-labellen-1); |
| 1570 | outlen = len; |
| 1571 | } |
| 1572 | } |
| 1573 | else if (inbuff[labellen]==0x16) //MIM H0=6=Mgmt inhibit msg, H1=1=LIN |
| 1574 | { |
| 1575 | outlen=labellen+mim_addlen; |
| 1576 | if (len<outlen) |
| 1577 | { log("incorrect incoming MIM message -> packet dropped."); |
| 1578 | return; |
| 1579 | } |
| 1580 | else |
| 1581 | { |
| 1582 | buffer[offset + labellen]= 0x56; // LIN -> LID ; LID = link inhibit denied |
| 1583 | memcpy(&buffer[offset + labellen+1],&inbuff[labellen+1],(len-labellen-1)); //SLC+spare+... |
| 1584 | outlen = len; |
| 1585 | } |
| 1586 | } |
| 1587 | else if (inbuff[labellen]==0x17 && (MTPServiceType==MTP3iup)) |
| 1588 | { |
| 1589 | if(forward_resume) incoming_message(ASP__MTP3__RESUME(NULL_VALUE)); |
| 1590 | return; |
| 1591 | } |
| 1592 | |
| 1593 | /* else if (inbuff[labellen]==0x17 && (MTPServiceType==MTP3iup)) //TRM H0=7, H1=1 : TRA |
| 1594 | { |
| 1595 | outlen=labellen+1; |
| 1596 | if (len<outlen) |
| 1597 | { log("incorrect incoming TRA message -> packet dropped."); |
| 1598 | return; |
| 1599 | } |
| 1600 | else |
| 1601 | { |
| 1602 | outlen = len; |
| 1603 | } |
| 1604 | }*/ |
| 1605 | else |
| 1606 | { log("This management message type is not supported -> packet dropped."); |
| 1607 | return; |
| 1608 | } |
| 1609 | |
| 1610 | // send message |
| 1611 | log("function processing_MTP3_management_msg sends a msg"); |
| 1612 | send_msg(buffer, outlen+offset); |
| 1613 | } |
| 1614 | |
| 1615 | // processing MTP3 test msg |
| 1616 | // Signalling link test message handling according to Q.707 (ITU) and T1.111.7-2001 (ANSI) |
| 1617 | void MTP3asp__PT_PROVIDER::processing_MTP3_test_msg(unsigned char* inbuff,int len) |
| 1618 | { |
| 1619 | int outlen=0; |
| 1620 | int labellen; // sio+routinglabel length |
| 1621 | int addlen; //Heading Code+length indicator |
| 1622 | //unsigned int ni; //network indicator |
| 1623 | OCTETSTRING bttc_oct = int2oct(stored_bttc_octet, 1); // additional octet for MTP3bttc |
| 1624 | unsigned int offset = 0; |
| 1625 | if ( MTPServiceType==MTP3itu || MTPServiceType==MTP3iup) |
| 1626 | { |
| 1627 | labellen=5; //ITU-T:sio(1byte) + routing label(4byte) see /Q.704/15.4.1 |
| 1628 | addlen = 2; //HC(1 byte)+length ind(1 byte) see Q.707/5.8 |
| 1629 | } |
| 1630 | else if ( MTPServiceType==MTP3ansi ) |
| 1631 | { |
| 1632 | labellen=8; //ANSI: sio(1byte) +routing label(7byte) see T1.111.4 |
| 1633 | addlen = 2; //HC(1byte) +(length ind+SLC(1byte)) see T1.111.7-2001/5 |
| 1634 | } |
| 1635 | else if (MTPServiceType==MTP3ttc) |
| 1636 | { |
| 1637 | /* if (mtp3_ni == 0) { |
| 1638 | debuglog("processing_MTP3_test_msg/TTC (Japanese) international"); |
| 1639 | labellen=5; //TTC (Japanese) international |
| 1640 | addlen=2; |
| 1641 | } else { |
| 1642 | */ |
| 1643 | labellen=6; // previously 7 |
| 1644 | // TTC national [ 56bits=sio(1byte)+routing label ] |
| 1645 | // r.label= dpc(2bytes)+opc(2bytes)+sls(4bit)+12bits (?) |
| 1646 | addlen=2; |
| 1647 | //} |
| 1648 | } |
| 1649 | else if (MTPServiceType==MTP3mpt) |
| 1650 | { |
| 1651 | if (mtp3_ni == 2) |
| 1652 | { labellen=8; //MPT national |
| 1653 | addlen=2; |
| 1654 | } |
| 1655 | else |
| 1656 | { labellen=5; // MPT international |
| 1657 | addlen=2; |
| 1658 | } |
| 1659 | } |
| 1660 | else if (MTPServiceType==MTP3bttc) |
| 1661 | { |
| 1662 | labellen=7; |
| 1663 | addlen=2; |
| 1664 | offset = 1; |
| 1665 | } |
| 1666 | else |
| 1667 | { log("incorrect MTPServiceType - programming error-> packet dropped"); |
| 1668 | return; |
| 1669 | } |
| 1670 | |
| 1671 | if (MTPServiceType==MTP3bttc) |
| 1672 | { |
| 1673 | buffer[0]=*((const unsigned char*)bttc_oct); //additional stored octet in front |
| 1674 | buffer[1]=inbuff[0]; //SIO |
| 1675 | if (!ChangePointCodes(&buffer[2],&inbuff[1],len)) |
| 1676 | { |
| 1677 | log("incorrect incoming test message -> packet dropped."); |
| 1678 | return; |
| 1679 | } |
| 1680 | } |
| 1681 | else |
| 1682 | { |
| 1683 | buffer[0]=inbuff[0]; //SIO |
| 1684 | if (!ChangePointCodes(&buffer[1],&inbuff[1],len)) |
| 1685 | { |
| 1686 | log("incorrect incoming test message -> packet dropped."); |
| 1687 | return; |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | // Test message handling: SLTM->SLTA, SRT->SRA, SLTA->TRA, others only logged |
| 1692 | debuglog("\n==>Test message handling: msg type:%x\n", inbuff[labellen] ); // temporary |
| 1693 | switch( inbuff[labellen] ) |
| 1694 | { |
| 1695 | case 0x11: //SLTM |
| 1696 | log("MTP3/SLTM message received"); |
| 1697 | outlen=labellen+addlen; |
| 1698 | if (len<outlen ) |
| 1699 | { log("incorrect incoming MTP3/SLTM message -> packet dropped."); |
| 1700 | return; |
| 1701 | } |
| 1702 | else |
| 1703 | { buffer[offset + labellen]= 0x21; // SLTA |
| 1704 | memcpy(&buffer[offset + labellen+1],&inbuff[labellen+1],(len-labellen-1)); |
| 1705 | outlen = len; |
| 1706 | } |
| 1707 | break; |
| 1708 | case 0x21: //SLTA |
| 1709 | if(!strncmp((const char *)(inbuff+labellen+addlen),(const char *)ttcn_in_sltm,sizeof_ttcn_in_sltm)) |
| 1710 | { |
| 1711 | log("MTP3/SLTA message received for SLTM sent by Test Port-> TRA message sent"); |
| 1712 | buffer[offset]--; |
| 1713 | buffer[offset + labellen]= 0x17; // TRA |
| 1714 | outlen = labellen+1; |
| 1715 | return; |
| 1716 | // if(forward_resume) incoming_message(ASP__MTP3__RESUME(NULL_VALUE)); |
| 1717 | } |
| 1718 | else |
| 1719 | { |
| 1720 | log("MTP3/SLTA message received -> packet dropped"); |
| 1721 | return; |
| 1722 | } |
| 1723 | break; |
| 1724 | case 0x23: // TTC (Japanese) SRT (Signalling Routing Test signal) |
| 1725 | log("MTP3ttc/SRT message received"); |
| 1726 | outlen=labellen+addlen; |
| 1727 | if (len<outlen ) |
| 1728 | { log("incorrect incoming MTP3ttc/SRT message (length error)-> packet dropped."); |
| 1729 | return; |
| 1730 | } |
| 1731 | else |
| 1732 | { buffer[offset + labellen]= 0x84; // TTC (Japanese) SRA |
| 1733 | memcpy(&buffer[offset + labellen+1],&inbuff[labellen+1],(len-labellen-1)); |
| 1734 | outlen = len; |
| 1735 | } |
| 1736 | break; |
| 1737 | case 0x84: // TTC (Japanese) SRA (Signalling Routing test Ack signal) |
| 1738 | log("MTP3ttc/SRA message received -> packet dropped"); |
| 1739 | return; |
| 1740 | default: |
| 1741 | log("This management message type is not supported -> packet dropped "); |
| 1742 | return; |
| 1743 | } |
| 1744 | |
| 1745 | // send message |
| 1746 | log("function processing_MTP3_test_msg sends a message"); |
| 1747 | send_msg( buffer,outlen+offset); |
| 1748 | } |
| 1749 | |
| 1750 | // Point Code Manipulation (Get/Set/Change) |
| 1751 | // ------------------------------------------------- |
| 1752 | void MTP3asp__PT_PROVIDER::GetPointCodes(unsigned int &sls,unsigned int &opc,unsigned int &dpc, unsigned char* msg) |
| 1753 | { |
| 1754 | unsigned int label; |
| 1755 | sls=0; opc=0; dpc=0; |
| 1756 | unsigned long long int Label; |
| 1757 | |
| 1758 | switch( MTPServiceType) |
| 1759 | { |
| 1760 | case MTP3itu: |
| 1761 | label= decode_32bLSB_int(msg); |
| 1762 | sls = (label>>28)&0xF; //sls = (label&0xF0000000)>>28; |
| 1763 | opc = (label>>14)&0x3FFF; //opc = (label&0x0FFFC000)>>14; |
| 1764 | dpc = label&0x3FFF; //dpc = (label&0x00003FFF); |
| 1765 | debuglog("Function GetPointCodes called for service type MTP3itu"); |
| 1766 | break; |
| 1767 | case MTP3iup: |
| 1768 | label= decode_32bLSB_int(msg); |
| 1769 | sls = (label>>28)&0xF; //sls = (label&0xF0000000)>>28; |
| 1770 | opc = (label>>14)&0x3FFF; //opc = (label&0x0FFFC000)>>14; |
| 1771 | dpc = label&0x3FFF; //dpc = (label&0x00003FFF); |
| 1772 | debuglog("Function GetPointCodes called for service type MTP3iup"); |
| 1773 | break; |
| 1774 | case MTP3ansi: |
| 1775 | Label=decode_56bLSB_int(msg); |
| 1776 | sls = (Label >> 48) & 0xFF; //sls = (Label&0x00FF000000000000)>>48; |
| 1777 | opc = (Label >> 24) & 0xFFFFFF;//opc = (Label&0x0000FFFFFF000000)>>24; |
| 1778 | dpc = Label & 0xFFFFFF; //dpc = (Label&0x0000000000FFFFFF); |
| 1779 | debuglog("Function GetPointCodes called for service type MTP3ansi"); |
| 1780 | break; |
| 1781 | case MTP3ttc: |
| 1782 | /* |
| 1783 | if( mtp3_ni == 0) |
| 1784 | { |
| 1785 | label= decode_32bLSB_int(msg); |
| 1786 | sls = (label>>28)&0xF; //sls = (label&0xF0000000)>>28; |
| 1787 | opc = (label>>14)&0x3FFF; //opc = (label&0x0FFFC000)>>14; |
| 1788 | dpc = label&0x3FFF; |
| 1789 | debuglog("Function GetPointCodes called for service type MTP3ttc/international"); |
| 1790 | } else |
| 1791 | {*/ |
| 1792 | Label=decode_48bLSB_int(msg); //0x010203040506 |
| 1793 | sls = (Label>>32)&0xF; // sls = (Label&0x000F00000000)>>32; // only 4 bits!!! |
| 1794 | opc = (Label>>16)&0xFFFF;//opc = (Label&0x0000FFFF0000)>>16; |
| 1795 | dpc = Label&0xFFFF; //dpc = (Label&0x00000000FFFF); |
| 1796 | debuglog("Function GetPointCodes called for service type MTP3ttc/national"); |
| 1797 | //} |
| 1798 | break; |
| 1799 | case MTP3bttc: |
| 1800 | Label=decode_48bLSB_int(msg); |
| 1801 | sls = (Label>>32)&0xF; // sls = (Label&0x000F00000000)>>32; // only 4 bits!!! |
| 1802 | opc = (Label>>16)&0xFFFF;//opc = (Label&0x0000FFFF0000)>>16; |
| 1803 | dpc = Label&0xFFFF; //dpc = (Label&0x00000000FFFF); |
| 1804 | debuglog("Function GetPointCodes called for service type MTP3bttc/national"); |
| 1805 | break; |
| 1806 | case MTP3mpt: |
| 1807 | if( mtp3_ni == 2) |
| 1808 | { |
| 1809 | Label=decode_56bLSB_int(msg); |
| 1810 | sls = (Label >> 48) & 0xFF; //sls = (Label&0x00FF000000000000)>>48; |
| 1811 | opc = (Label >> 24) & 0xFFFFFF;//opc = (Label&0x0000FFFFFF000000)>>24; |
| 1812 | dpc = Label & 0xFFFFFF; //dpc = (Label&0x0000000000FFFFFF); |
| 1813 | debuglog("Function GetPointCodes called for service type MTP3mpt(nat)"); |
| 1814 | } |
| 1815 | else |
| 1816 | { |
| 1817 | label= decode_32bLSB_int(msg); |
| 1818 | sls = (label>>28)&0xF; //sls = (label&0xF0000000)>>28; |
| 1819 | opc = (label>>14)&0x3FFF; //opc = (label&0x0FFFC000)>>14; |
| 1820 | dpc = label&0x3FFF; //dpc = (label&0x00003FFF); |
| 1821 | debuglog("Function GetPointCodes called for service type MTP3mpt(int)"); |
| 1822 | } |
| 1823 | break; |
| 1824 | default: |
| 1825 | break; |
| 1826 | } |
| 1827 | debuglog("sls:%u opc:%u, dpc:%u",sls,opc,dpc); |
| 1828 | } |
| 1829 | //------------ |
| 1830 | |
| 1831 | void MTP3asp__PT_PROVIDER::GetPointCodesIUP(unsigned int &cic,unsigned int &opc,unsigned int &dpc, unsigned char* msg) |
| 1832 | { |
| 1833 | debuglog("Function GetPointCodesIUP called"); |
| 1834 | cic=0; opc=0; dpc=0; |
| 1835 | unsigned long long int Label; |
| 1836 | Label=decode_40bLSB_int(msg); //0x0102030405 |
| 1837 | cic = (Label>>28)&0xFFF; //cic = (label&0xFFF0000000)>>28; |
| 1838 | opc = (Label>>14)&0x3FFF; //opc = (label&0x000FFFC000)>>14; |
| 1839 | dpc = Label&0x3FFF; //dpc = (label&0x0000003FFF); |
| 1840 | debuglog("cic:%u opc:%u, dpc:%u",cic,opc,dpc); |
| 1841 | } |
| 1842 | |
| 1843 | void MTP3asp__PT_PROVIDER::SetPointCodes(unsigned int sls,unsigned int opc,unsigned int dpc, unsigned char* msg) |
| 1844 | { |
| 1845 | unsigned long long int Sls,Opc,Dpc; |
| 1846 | |
| 1847 | switch( MTPServiceType) |
| 1848 | { |
| 1849 | case MTP3itu: |
| 1850 | encode_32bLSB_int( msg, ((sls<<28)|(opc<<14)|dpc )); |
| 1851 | debuglog("Function SetPointCodes called for service type MTP3itu"); |
| 1852 | break; |
| 1853 | case MTP3iup: |
| 1854 | encode_32bLSB_int( msg, ((sls<<28)|(opc<<14)|dpc )); |
| 1855 | debuglog("Function SetPointCodes called for service type MTP3iup"); |
| 1856 | break; |
| 1857 | case MTP3ansi: |
| 1858 | Sls=sls; Opc=opc; Dpc=dpc; |
| 1859 | encode_56bLSB_int( msg, ((Sls<<48)|(Opc<<24)|Dpc)); |
| 1860 | debuglog("Function SetPointCodes called for service type MTP3ansi"); |
| 1861 | break; |
| 1862 | case MTP3ttc: |
| 1863 | /* if ( mtp3_ni == 0 ){ |
| 1864 | encode_32bLSB_int( msg, ((sls<<28)|(opc<<14)|dpc )); |
| 1865 | debuglog("Function SetPointCodes called for service type MTP3ttc/international"); |
| 1866 | } else { |
| 1867 | */ |
| 1868 | Sls=sls; Opc=opc; Dpc=dpc; |
| 1869 | encode_48bLSB_int( msg, ((Sls<<32)|(Opc<<16)|Dpc)); |
| 1870 | debuglog("Function SetPointCodes called for service type MTP3ttc/national"); |
| 1871 | //} |
| 1872 | break; |
| 1873 | case MTP3bttc: |
| 1874 | Sls=sls; Opc=opc; Dpc=dpc; |
| 1875 | encode_48bLSB_int( msg, ((Sls<<32)|(Opc<<16)|Dpc)); |
| 1876 | debuglog("Function SetPointCodes called for service type MTP3bttc/national"); |
| 1877 | break; |
| 1878 | case MTP3mpt: |
| 1879 | if ( mtp3_ni == 2 ) |
| 1880 | { Sls=sls; Opc=opc; Dpc=dpc; |
| 1881 | encode_56bLSB_int( msg, ((Sls<<48)|(Opc<<24)|Dpc)); |
| 1882 | debuglog("Function SetPointCodes called for service type MTP3mpt(nat)"); |
| 1883 | } |
| 1884 | else |
| 1885 | { encode_32bLSB_int( msg, ((sls<<28)|(opc<<14)|dpc )); |
| 1886 | debuglog("Function SetPointCodes called for service type MTP3mpt(int)"); |
| 1887 | } |
| 1888 | break; |
| 1889 | default: |
| 1890 | break; |
| 1891 | } |
| 1892 | } |
| 1893 | //------------ |
| 1894 | |
| 1895 | void MTP3asp__PT_PROVIDER::SetPointCodesIUP(unsigned int cic,unsigned int opc,unsigned int dpc, unsigned char* msg) |
| 1896 | { |
| 1897 | unsigned long long int Cic,Opc,Dpc; |
| 1898 | Cic=cic; Opc=opc; Dpc=dpc; |
| 1899 | debuglog("Function SetPointCodesIUP called"); |
| 1900 | encode_40bLSB_int( msg, ((Cic<<28)|(Opc<<14)|Dpc )); |
| 1901 | } |
| 1902 | |
| 1903 | //Changes the Point codes: dpc<->opc ie. destination <->orig |
| 1904 | // inbuff starts from dpc i.e doesn't contain sio !!!! |
| 1905 | int MTP3asp__PT_PROVIDER::ChangePointCodes(unsigned char* outbuff, unsigned char *inbuff, int len) |
| 1906 | { |
| 1907 | switch( MTPServiceType) |
| 1908 | { |
| 1909 | case MTP3itu: |
| 1910 | case MTP3iup: |
| 1911 | if (len<5) |
| 1912 | { warn("MTP3itu:len<5. Too short message!"); return 0; }; |
| 1913 | break; |
| 1914 | case MTP3ansi: |
| 1915 | if (len<9 ) return 0; |
| 1916 | break; |
| 1917 | case MTP3ttc: |
| 1918 | //if ( mtp3_ni == 0 && len<5) |
| 1919 | //{ warn("MTP3ttc:len<5. Too short message!"); return 0; } |
| 1920 | //else |
| 1921 | if (len<6) |
| 1922 | { warn("MTP3ttc:len<6. Too short message!"); return 0; } |
| 1923 | break; |
| 1924 | case MTP3bttc: |
| 1925 | if (len<7) |
| 1926 | { warn("MTP3bttc:len<7. Too short message!"); return 0; } |
| 1927 | break; |
| 1928 | case MTP3mpt: |
| 1929 | if ( mtp3_ni == 2 && len<8) |
| 1930 | { warn("MTP3mpt:len<8. Too short message!"); return 0; } |
| 1931 | else if (len<5) |
| 1932 | { warn("MTP3mpt:len<5. Too short message!"); return 0; } |
| 1933 | break; |
| 1934 | default: |
| 1935 | warn("Unknown MTPServiceType!!!"); |
| 1936 | break; |
| 1937 | } |
| 1938 | unsigned int sls,opc,dpc; |
| 1939 | GetPointCodes(sls,opc,dpc,inbuff); |
| 1940 | SetPointCodes(sls,dpc,opc,outbuff); |
| 1941 | return 1; |
| 1942 | } |
| 1943 | //------------ |
| 1944 | |
| 1945 | int MTP3asp__PT_PROVIDER::Check_PcMatch(unsigned int opc, unsigned int dpc, unsigned char *buff) |
| 1946 | { |
| 1947 | unsigned int temp_opc,temp_dpc,temp_sls; |
| 1948 | |
| 1949 | GetPointCodes(temp_sls,temp_opc,temp_dpc,buff); |
| 1950 | if ( (temp_opc == opc) && (temp_dpc == dpc) ) return 1; |
| 1951 | return 0; |
| 1952 | } |
| 1953 | //------------ |
| 1954 | |
| 1955 | |
| 1956 | // ------------------------------------------------- |
| 1957 | // M3UA Functions and definitions for test with SEA |
| 1958 | // ------------------------------------------------- |
| 1959 | |
| 1960 | // Structures for M3UA |
| 1961 | static unsigned char aspup_msg[] = |
| 1962 | { |
| 1963 | //common MsUA msg hdr, see M3UA PS |
| 1964 | //Doc no. 1/1056-FCP 103 3571/F Uen, RevA |
| 1965 | 0x01, //Release Version |
| 1966 | 0x00, //reserved |
| 1967 | M3UA_MSG_CLS_ASPSM, //Msg class: ASPSM |
| 1968 | M3UA_MSG_TYP_ASPSM_ASPUP, //Msg type: ASPUP |
| 1969 | 0x00, //Msg length begins (4 octets) |
| 1970 | 0x00, // |
| 1971 | 0x00, // |
| 1972 | 0x08 // length ends = 8 octets |
| 1973 | // ,PAR_PREFIX_COMMON, //optional Info string tag, in included, then msg |
| 1974 | // PAR_INFO_STR //msg length should be +20, that is 28=0x1c |
| 1975 | // 0x00,0x0f, // length: "TTCN-3 Executor" is 15 chars |
| 1976 | // 'T', 'T', 'C', 'N', |
| 1977 | // '-', '3', ' ', 'E', |
| 1978 | // 'x', 'e', 'c', 'u', |
| 1979 | // 't', 'o', 'r', 0x00 //las octet is padding |
| 1980 | }; |
| 1981 | const int sizeof_aspup_msg = 8; |
| 1982 | |
| 1983 | static unsigned char aspupack_msg[] = |
| 1984 | { |
| 1985 | //common MsUA msg hdr, see M3UA PS |
| 1986 | //Doc no. 1/1056-FCP 103 3571/F Uen, RevA |
| 1987 | 0x01, //Release Version |
| 1988 | 0x00, //reserved |
| 1989 | M3UA_MSG_CLS_ASPSM, //Msg class: ASPSM |
| 1990 | M3UA_MSG_TYP_ASPSM_ASPUPAck, //Msg type: ASPUP |
| 1991 | 0x00, //Msg length begins (4 octets) |
| 1992 | 0x00, // |
| 1993 | 0x00, // |
| 1994 | 0x08 // length ends = 8 octets |
| 1995 | }; |
| 1996 | const int sizeof_aspupack_msg = 8; |
| 1997 | |
| 1998 | static unsigned char aspac_msg[] = |
| 1999 | { |
| 2000 | //common MsUA msg hdr, see M3UA PS |
| 2001 | //Doc no. 1/1056-FCP 103 3571/F Uen, RevA |
| 2002 | 0x01, //Release Version: 01 |
| 2003 | 0x00, //reserved |
| 2004 | M3UA_MSG_CLS_ASPTM, //Msg class |
| 2005 | M3UA_MSG_TYP_ASPTM_ASPAC, //Msg type |
| 2006 | 0x00, //Msg length begins (4 octets) |
| 2007 | 0x00, // |
| 2008 | 0x00, // |
| 2009 | 0x08 // length ends = 8 octets |
| 2010 | }; |
| 2011 | const int sizeof_aspac_msg = 8; |
| 2012 | |
| 2013 | // ASP Active Acknowledge msg: |
| 2014 | static unsigned char aspac_ack_msg[] = |
| 2015 | { |
| 2016 | //common MsUA msg hdr, see M3UA PS |
| 2017 | //Doc no. 1/1056-FCP 103 3571/F Uen, RevA |
| 2018 | 0x01, //Release Version: 01 |
| 2019 | 0x00, //reserved |
| 2020 | M3UA_MSG_CLS_ASPTM, //Msg class |
| 2021 | M3UA_MSG_TYP_ASPTM_ASPACAck, //Msg type |
| 2022 | 0x00, //Msg length begins (4 octets) |
| 2023 | 0x00, // |
| 2024 | 0x00, // |
| 2025 | 0x08 // length ends = 8 octets |
| 2026 | }; |
| 2027 | const int sizeof_aspac_ack_msg = 8; |
| 2028 | |
| 2029 | static unsigned char aspia_ack_msg[] = |
| 2030 | { |
| 2031 | //common MsUA msg hdr, see M3UA PS |
| 2032 | //Doc no. 1/1056-FCP 103 3571/F Uen, RevA |
| 2033 | 0x01, //Release Version: 01 |
| 2034 | 0x00, //reserved |
| 2035 | M3UA_MSG_CLS_ASPTM, //Msg class |
| 2036 | M3UA_MSG_TYP_ASPTM_ASPIAAck, //Msg type |
| 2037 | 0x00, //Msg length begins (4 octets) |
| 2038 | 0x00, // |
| 2039 | 0x00, // |
| 2040 | 0x08 // length ends = 8 octets |
| 2041 | }; |
| 2042 | const int sizeof_aspia_ack_msg = 8; |
| 2043 | |
| 2044 | // ASP DOWN Acknowledge msg: |
| 2045 | static unsigned char aspdn_ack_msg[] = |
| 2046 | { |
| 2047 | //common MsUA msg hdr, see M3UA PS |
| 2048 | //Doc no. 1/1056-FCP 103 3571/F Uen, RevA |
| 2049 | 0x01, //Release Version: 01 |
| 2050 | 0x00, //reserved |
| 2051 | M3UA_MSG_CLS_ASPSM, //Msg class |
| 2052 | M3UA_MSG_TYP_ASPSM_ASPDNAck, //Msg type |
| 2053 | 0x00, //Msg length begins (4 octets) |
| 2054 | 0x00, // |
| 2055 | 0x00, // |
| 2056 | 0x08 // length ends = 8 octets |
| 2057 | }; |
| 2058 | const int sizeof_aspdn_ack_msg = 8; |
| 2059 | |
| 2060 | //ASP Destination Available msg: |
| 2061 | static unsigned char dava_1apc_msg[] = |
| 2062 | { |
| 2063 | //common MsUA msg hdr, see M3UA PS |
| 2064 | //Doc no. 1/1056-FCP 103 3571/F Uen, RevA |
| 2065 | //or updated doc 2/1056-FCPW 101 86/P-1 |
| 2066 | 0x01, //Release Version: 01 |
| 2067 | 0x00, //reserved |
| 2068 | M3UA_MSG_CLS_SSNM, //Msg class |
| 2069 | M3UA_MSG_TYP_SSNM_DAVA, //Msg type |
| 2070 | 0x00, //Msg length begins (4 octets) |
| 2071 | 0x00, // |
| 2072 | 0x00, // |
| 2073 | 0x10, // length ends, 16 octets |
| 2074 | //Affected point code |
| 2075 | PAR_PREFIX_COMMON, |
| 2076 | PAR_AFFECTED_PC, |
| 2077 | 0x00, //par length begins (2 octets) |
| 2078 | 0x08, //length ends, 8 octets |
| 2079 | 0x00, // point code placeholder begins |
| 2080 | 0x00, // |
| 2081 | 0x00, // |
| 2082 | 0x00 // point code placeholder ends |
| 2083 | }; |
| 2084 | const int sizeof_dava_1apc_msg = 16; |
| 2085 | |
| 2086 | static unsigned char duna_1apc_msg[] = |
| 2087 | { |
| 2088 | //common MsUA msg hdr, see M3UA PS |
| 2089 | //Doc no. 1/1056-FCP 103 3571/F Uen, RevA |
| 2090 | 0x01, //Release Version: 01 |
| 2091 | 0x00, //reserved |
| 2092 | M3UA_MSG_CLS_SSNM, //Msg class |
| 2093 | M3UA_MSG_TYP_SSNM_DUNA, //Msg type |
| 2094 | 0x00, //Msg length begins (4 octets) |
| 2095 | 0x00, // |
| 2096 | 0x00, // |
| 2097 | 0x10, // length ends, 16 octets |
| 2098 | //Affected point code |
| 2099 | PAR_PREFIX_COMMON, |
| 2100 | PAR_AFFECTED_PC, |
| 2101 | 0x00, //par length begins (2 octets) |
| 2102 | 0x08, //length ends, 8 octets |
| 2103 | 0x00, // point code placeholder begins |
| 2104 | 0x00, // |
| 2105 | 0x00, // |
| 2106 | 0x00 // point code placeholder ends |
| 2107 | }; |
| 2108 | const int sizeof_duna_1apc_msg = 16; |
| 2109 | |
| 2110 | static unsigned char error_msg[] = |
| 2111 | { |
| 2112 | //common MsUA msg hdr, see M3UA PS |
| 2113 | //Doc no. 1/1056-FCP 103 3571/F Uen, RevA |
| 2114 | 0x01, //Release Version: 01 |
| 2115 | 0x00, //reserved |
| 2116 | M3UA_MSG_CLS_MGMT, //Msg class |
| 2117 | M3UA_MSG_TYP_MGMT_ERR, //Msg type |
| 2118 | 0x00, //Msg length begins (4 octets) |
| 2119 | 0x00, // |
| 2120 | 0x00, // |
| 2121 | 0x18, // length ends, 16+8 octets |
| 2122 | // Error code field: |
| 2123 | PAR_PREFIX_COMMON, |
| 2124 | PAR_ERROR_CODE, |
| 2125 | 0x00, //par length begins (2 octets) |
| 2126 | 0x08, //length ends, 8 octets |
| 2127 | 0x00, // error code placeholder begins (M3UA_MSG_OFFS+4) |
| 2128 | 0x00, // |
| 2129 | 0x00, // |
| 2130 | 0x00, // error code placeholder ends |
| 2131 | // additional field: |
| 2132 | 0x00, // M3UA_MSG_OFFS+8 |
| 2133 | 0x00, // Routing context or Network Appearanance or APC or DI = error_code_id |
| 2134 | 0x00, // par length begins (2 octets) |
| 2135 | 0x08, // length ends, 8 octets |
| 2136 | 0x00, // value placeholder begins M3UA_MSG_OFFS+12 |
| 2137 | 0x00, // |
| 2138 | 0x00, // |
| 2139 | 0x00 // value place holder ends |
| 2140 | }; |
| 2141 | const int sizeof_error_msg = 24; |
| 2142 | |
| 2143 | void MTP3asp__PT_PROVIDER::M3UA_user_unmap(const char *system_port) |
| 2144 | { |
| 2145 | MTP3_close_connection(); |
| 2146 | dynamicConnection = FALSE; |
| 2147 | } |
| 2148 | //------------ |
| 2149 | |
| 2150 | void MTP3asp__PT_PROVIDER::M3UA_user_map(const char *system_port) |
| 2151 | { |
| 2152 | M3UAState = AssocDown; |
| 2153 | Check_TestPort_Variables(); |
| 2154 | if(dynamicConnection) |
| 2155 | { |
| 2156 | connectionUp = FALSE; |
| 2157 | } |
| 2158 | else |
| 2159 | { |
| 2160 | MTP3_open_channel(TRUE); |
| 2161 | M3UA_user_connect(); |
| 2162 | } |
| 2163 | } |
| 2164 | //------------ |
| 2165 | |
| 2166 | void MTP3asp__PT_PROVIDER::M3UA_user_connect() |
| 2167 | { |
| 2168 | M3UAState = AssocEstabl; |
| 2169 | // Sending out an ASPUP message |
| 2170 | log("Message ASPUP will be sent"); |
| 2171 | send_msg(aspup_msg, sizeof_aspup_msg); |
| 2172 | // NOTE: the ASPUPAck will be handled by M3UA_interpreter, which |
| 2173 | // also will take care of sending ASPAC upon receiving the ASPUPAck |
| 2174 | } |
| 2175 | //------------ |
| 2176 | |
| 2177 | // M3UA_interpreter |
| 2178 | void MTP3asp__PT_PROVIDER::M3UA_interpreter(unsigned char* inbuffer,int length,int from_channel,CONNECTION* con) |
| 2179 | { |
| 2180 | if ((length==0) || (inbuffer==NULL)) |
| 2181 | { warn("0 byte long message received -> packet dropped."); |
| 2182 | return; |
| 2183 | } |
| 2184 | |
| 2185 | if (length==1) |
| 2186 | { |
| 2187 | log("1 byte long internal SEA message received -> packet dropped."); |
| 2188 | return; |
| 2189 | } |
| 2190 | |
| 2191 | if ( !strcmp((const char*)inbuffer,"start") ) |
| 2192 | { log("start message received from SEA"); |
| 2193 | return; |
| 2194 | } |
| 2195 | else if (!strcmp((const char*)inbuffer,"stop")) |
| 2196 | { log("stop message received from SEA"); |
| 2197 | return; |
| 2198 | } |
| 2199 | |
| 2200 | // writing out the contents of the buffer |
| 2201 | OCTETSTRING buff(length,inbuffer); |
| 2202 | TTCN_Logger::begin_event(TTCN_PORTEVENT); |
| 2203 | TTCN_Logger::log_event("incoming buffer: "); |
| 2204 | buff.log(); |
| 2205 | TTCN_Logger::end_event(); |
| 2206 | |
| 2207 | // version checking |
| 2208 | if ( inbuffer[M3UA_VER_OFFS] != M3UA_version ) |
| 2209 | { warn("Incompatible M3UA protocol version in header -> packet dropped"); |
| 2210 | return; |
| 2211 | } |
| 2212 | |
| 2213 | //length checking |
| 2214 | unsigned int indicated_length = decode_32b_int(inbuffer + M3UA_LGT_OFFS ); |
| 2215 | if ( indicated_length != (unsigned)length) |
| 2216 | warn("Length in common header (%d) mismatches received buffer length (%d)," |
| 2217 | "Assuming that it is because of the omission of final parameter padding" |
| 2218 | "in indicated length",indicated_length, length); |
| 2219 | |
| 2220 | // checking MSG class |
| 2221 | int unprocessed_chars = 0; |
| 2222 | switch (inbuffer[M3UA_CLS_OFFS]) |
| 2223 | { |
| 2224 | case M3UA_MSG_CLS_MGMT: |
| 2225 | unprocessed_chars = processing_M3UA_MGMT_msg(inbuffer, length); |
| 2226 | break; |
| 2227 | case M3UA_MSG_CLS_TRNSFM : |
| 2228 | unprocessed_chars = processing_M3UA_Transfer_msg(inbuffer, length); |
| 2229 | break; |
| 2230 | case M3UA_MSG_CLS_SSNM : |
| 2231 | unprocessed_chars = processing_M3UA_SSNM_msg(inbuffer, length); |
| 2232 | break; |
| 2233 | case M3UA_MSG_CLS_ASPSM : |
| 2234 | unprocessed_chars = processing_M3UA_ASPSM_msg(inbuffer, length); |
| 2235 | break; |
| 2236 | case M3UA_MSG_CLS_ASPTM : |
| 2237 | unprocessed_chars = processing_M3UA_ASPTM_msg(inbuffer, length); |
| 2238 | break; |
| 2239 | case M3UA_MSG_CLS_RKM : |
| 2240 | unprocessed_chars = processing_M3UA_RKM_msg(inbuffer, length); |
| 2241 | break; |
| 2242 | default: |
| 2243 | unprocessed_chars = processing_M3UA_unsupported_msg_class(inbuffer, length); |
| 2244 | break; |
| 2245 | } |
| 2246 | debuglog("%d chars remained unprocessed (might be due to padding)", unprocessed_chars); |
| 2247 | } |
| 2248 | //------------ |
| 2249 | |
| 2250 | //processing M3UA MGMT msg |
| 2251 | int MTP3asp__PT_PROVIDER::processing_M3UA_MGMT_msg(unsigned char* inbuffer,int length) |
| 2252 | { |
| 2253 | debuglog("Entering function:processing_MGMT_msg"); |
| 2254 | int offset = M3UA_MSG_OFFS; //pointer for processing |
| 2255 | |
| 2256 | TTCN_Logger::begin_event(TTCN_DEBUG); |
| 2257 | TTCN_Logger::log_event("MTP3 Test Port (%s): {", get_name()); |
| 2258 | TTCN_Logger::log_event("decoded msg class: Mgmt, "); |
| 2259 | switch (inbuffer[M3UA_TYP_OFFS])//msg type |
| 2260 | { |
| 2261 | case M3UA_MSG_TYP_MGMT_ERR: |
| 2262 | TTCN_Logger::log_event("type: ERROR-> ignored"); |
| 2263 | TTCN_Logger::log_event("}"); |
| 2264 | TTCN_Logger::end_event(); |
| 2265 | break; |
| 2266 | case M3UA_MSG_TYP_MGMT_NTFY: |
| 2267 | TTCN_Logger::log_event("type: NOTIFY -> ignored"); |
| 2268 | TTCN_Logger::log_event("}"); |
| 2269 | TTCN_Logger::end_event(); |
| 2270 | break; |
| 2271 | default: |
| 2272 | send_M3UA_error_msg( PAR_ERRC_UNSMT, inbuffer[M3UA_TYP_OFFS]); |
| 2273 | TTCN_Logger::log_event("Unsupported M3UA msg type %x of class MGMT -> packet dropped.", inbuffer[M3UA_TYP_OFFS]); |
| 2274 | TTCN_Logger::log_event("}"); |
| 2275 | TTCN_Logger::end_event(); |
| 2276 | break; |
| 2277 | } |
| 2278 | return length - offset; |
| 2279 | } |
| 2280 | //------------ |
| 2281 | |
| 2282 | //processing M3UA SSNM msg |
| 2283 | int MTP3asp__PT_PROVIDER::processing_M3UA_SSNM_msg(unsigned char* inbuffer,int length) |
| 2284 | { |
| 2285 | debuglog("Entering function:processing_SSNM_msg"); |
| 2286 | TTCN_Logger::begin_event(TTCN_PORTEVENT); |
| 2287 | TTCN_Logger::log_event("MTP3 Test Port (%s): {", get_name()); |
| 2288 | TTCN_Logger::log_event("decoded msg class: SSNM, "); |
| 2289 | int offset = M3UA_MSG_OFFS; //pointer for processing |
| 2290 | |
| 2291 | switch (inbuffer[M3UA_TYP_OFFS]) |
| 2292 | { |
| 2293 | case M3UA_MSG_TYP_SSNM_DAUD: |
| 2294 | while (offset <= length-8 ) //processing potential params |
| 2295 | { |
| 2296 | switch (inbuffer[offset++]) //1st octet of tag |
| 2297 | { |
| 2298 | case PAR_PREFIX_COMMON: |
| 2299 | TTCN_Logger::log_event (" DAUD: COMMON parameter "); |
| 2300 | switch (inbuffer[offset++]) //2nd octet of COMMON tag |
| 2301 | { |
| 2302 | case PAR_ROUTING_CTX: |
| 2303 | TTCN_Logger::log_event ("Routing Context (unsupported par) -> skipped), "); |
| 2304 | skip_par_after_tag(inbuffer, offset); |
| 2305 | break; |
| 2306 | case PAR_INFO_STR: |
| 2307 | TTCN_Logger::log_event ("Info String (unsupported par) -> skipped), "); |
| 2308 | skip_par_after_tag(inbuffer, offset); |
| 2309 | break; |
| 2310 | case PAR_AFFECTED_PC: |
| 2311 | TTCN_Logger::log_event ("Affected Point Code -> will send DUNA/DAVA, "); |
| 2312 | TTCN_Logger::log_event("will ignore remainder parameters after APC}"); |
| 2313 | TTCN_Logger::end_event(); |
| 2314 | Send_DAVA_DUNA_to_APCinDAUD(Tester_Pc, inbuffer, offset); |
| 2315 | return length-offset; |
| 2316 | default: |
| 2317 | TTCN_Logger::log_event ("invalid COMMON param tag:0x%02x%02x-> skipped", PAR_PREFIX_COMMON, inbuffer[offset-1]); |
| 2318 | send_M3UA_error_msg( PAR_ERRC_PARFE, inbuffer[offset-1]); |
| 2319 | skip_par_after_tag(inbuffer, offset); |
| 2320 | break; |
| 2321 | } |
| 2322 | break; |
| 2323 | case PAR_PREFIX_M3UA: |
| 2324 | TTCN_Logger::log_event ("DAUD: M3UA parameter: "); |
| 2325 | switch (inbuffer[offset++]) //2nd octet of M3UA tag |
| 2326 | { |
| 2327 | case PAR_NETW_APP: |
| 2328 | TTCN_Logger::log_event ("Network Appearance (unsupported par) -> skipped), "); |
| 2329 | skip_par_after_tag(inbuffer, offset); |
| 2330 | break; |
| 2331 | default: |
| 2332 | TTCN_Logger::log_event ("invalid M3UA param tag:0x%02x%02x-> skipped", |
| 2333 | PAR_PREFIX_M3UA, inbuffer[offset-1]); |
| 2334 | send_M3UA_error_msg( PAR_ERRC_PARFE, inbuffer[offset-1]); |
| 2335 | skip_par_after_tag(inbuffer, offset); |
| 2336 | } |
| 2337 | break; |
| 2338 | default: //1st octet of tag |
| 2339 | TTCN_Logger::log_event ("invalid 1st octet param tag:0x%02x in DATA (packet dropped)",inbuffer[offset-1]); |
| 2340 | close_log_event(); |
| 2341 | return length -offset; |
| 2342 | break; |
| 2343 | } |
| 2344 | } |
| 2345 | break; |
| 2346 | case M3UA_MSG_TYP_SSNM_DAVA: // Destination Available // Notification to the user part ????? |
| 2347 | TTCN_Logger::log_event("type: SSNM_DAVA -> ignored"); |
| 2348 | close_log_event(); |
| 2349 | break; |
| 2350 | case M3UA_MSG_TYP_SSNM_DUNA: // Destination Unavailable // Notification to the user part ????? |
| 2351 | TTCN_Logger::log_event("type: SSNM_DUNA -> ignored"); |
| 2352 | close_log_event(); |
| 2353 | break; |
| 2354 | case M3UA_MSG_TYP_SSNM_SCON: // Signalling Congestion // Notification to the user part ????? |
| 2355 | TTCN_Logger::log_event("type: SSNM_SCON -> ignored"); |
| 2356 | close_log_event(); |
| 2357 | break; |
| 2358 | case M3UA_MSG_TYP_SSNM_DUPU: //Destinationn User Part Unavailable // Notification to the user part ????? |
| 2359 | TTCN_Logger::log_event("type: SSNM_DUPU -> ignored"); |
| 2360 | close_log_event(); |
| 2361 | break; |
| 2362 | case M3UA_MSG_TYP_SSNM_DRST: //Destination Restricted // Notification to the user part ????? |
| 2363 | TTCN_Logger::log_event("type: SSNM_DRST -> ignored"); |
| 2364 | close_log_event(); |
| 2365 | break; |
| 2366 | default: //msg type |
| 2367 | send_M3UA_error_msg( PAR_ERRC_UNSMT, inbuffer[M3UA_TYP_OFFS]); |
| 2368 | TTCN_Logger::log_event("Unsupported M3UA msg type -> packet dropped."); |
| 2369 | close_log_event(); |
| 2370 | break; |
| 2371 | } |
| 2372 | return length - offset; |
| 2373 | } |
| 2374 | //------------ |
| 2375 | |
| 2376 | //processing M3UA ASPSM msg |
| 2377 | int MTP3asp__PT_PROVIDER::processing_M3UA_ASPSM_msg(unsigned char* inbuffer,int length) |
| 2378 | { |
| 2379 | debuglog("Entering function:processing_ASPSM_msg"); |
| 2380 | TTCN_Logger::begin_event(TTCN_PORTEVENT); |
| 2381 | TTCN_Logger::log_event("MTP3 Test Port (%s): {", get_name()); |
| 2382 | TTCN_Logger::log_event("decoded msg class: ASPSM, "); |
| 2383 | |
| 2384 | int offset = M3UA_MSG_OFFS; //pointer for processing |
| 2385 | switch (inbuffer[M3UA_TYP_OFFS]) |
| 2386 | { |
| 2387 | case M3UA_MSG_TYP_ASPSM_ASPUP: |
| 2388 | TTCN_Logger::log_event("type: ASPSM_ASPUP -> ASPUPAck will be sent"); |
| 2389 | close_log_event(); |
| 2390 | send_msg(aspupack_msg, sizeof_aspupack_msg); |
| 2391 | break; |
| 2392 | case M3UA_MSG_TYP_ASPSM_ASPDN: |
| 2393 | TTCN_Logger::log_event("type: ASPSM_ASPDN -> ASPDNAck will be sent"); |
| 2394 | close_log_event(); |
| 2395 | send_msg(aspdn_ack_msg, sizeof_aspdn_ack_msg); |
| 2396 | break; |
| 2397 | case M3UA_MSG_TYP_ASPSM_BEAT: |
| 2398 | TTCN_Logger::log_event("type: ASPSM_BEAT -> ASPSM_BEATAck will be sent"); |
| 2399 | close_log_event(); |
| 2400 | //Sending back the packet as acknowledge: |
| 2401 | inbuffer[M3UA_TYP_OFFS]= M3UA_MSG_TYP_ASPSM_BEATAck; |
| 2402 | send_msg(inbuffer, length); |
| 2403 | break; |
| 2404 | case M3UA_MSG_TYP_ASPSM_ASPUPAck: |
| 2405 | TTCN_Logger::log_event("type: ASPSM_ASPUPAck -> ASPAC will be sent"); |
| 2406 | M3UAState = AssocInac; |
| 2407 | TTCN_Logger::log_event(" M3UAState's been changed to AssocInac"); |
| 2408 | close_log_event(); |
| 2409 | send_msg(aspac_msg, sizeof_aspac_msg ); |
| 2410 | break; |
| 2411 | case M3UA_MSG_TYP_ASPSM_ASPDNAck: |
| 2412 | M3UAState = AssocDown; |
| 2413 | TTCN_Logger::log_event(" M3UAState's been changed to AssocDown"); |
| 2414 | TTCN_Logger::log_event("type: ASPSM_ASPDNAck -> nothing will be sent"); |
| 2415 | close_log_event(); |
| 2416 | break; |
| 2417 | case M3UA_MSG_TYP_ASPSM_BEATAck: |
| 2418 | TTCN_Logger::log_event("type: ASPSM_BEATAck -> nothing will be sent"); |
| 2419 | close_log_event(); |
| 2420 | break; |
| 2421 | default: |
| 2422 | TTCN_Logger::log_event("Unsupported M3UA msg type %x of class ASPSM-> packet dropped.", (unsigned char)(inbuffer[M3UA_TYP_OFFS])); |
| 2423 | close_log_event(); |
| 2424 | send_M3UA_error_msg( PAR_ERRC_UNSMT, inbuffer[M3UA_TYP_OFFS]); |
| 2425 | break; |
| 2426 | } |
| 2427 | return length - offset; |
| 2428 | } |
| 2429 | //------------ |
| 2430 | |
| 2431 | //processing M3UA ASPTM msg |
| 2432 | int MTP3asp__PT_PROVIDER::processing_M3UA_ASPTM_msg(unsigned char* inbuffer,int length) |
| 2433 | { |
| 2434 | debuglog("Entering function:processing_ASPTM_msg"); |
| 2435 | TTCN_Logger::begin_event(TTCN_PORTEVENT); |
| 2436 | TTCN_Logger::log_event("MTP3 Test Port (%s): {", get_name()); |
| 2437 | TTCN_Logger::log_event("decoded msg class: ASPTM, "); |
| 2438 | |
| 2439 | int offset = M3UA_MSG_OFFS; //pointer for processing |
| 2440 | switch (inbuffer[M3UA_TYP_OFFS]) |
| 2441 | { |
| 2442 | case M3UA_MSG_TYP_ASPTM_ASPAC: //ASP Active |
| 2443 | M3UAState = AssocActive; |
| 2444 | TTCN_Logger::log_event("type: ASPTM_ASPAC -> ASPACAck will be sent"); |
| 2445 | close_log_event(); |
| 2446 | send_msg(aspac_ack_msg, sizeof_aspac_ack_msg); |
| 2447 | break; |
| 2448 | case M3UA_MSG_TYP_ASPTM_ASPIA: //ASP InActive |
| 2449 | TTCN_Logger::log_event("type: ASPTM_ASPIA -> ASPIAAck will be sent"); |
| 2450 | close_log_event(); |
| 2451 | send_msg(aspia_ack_msg, sizeof_aspia_ack_msg); |
| 2452 | break; |
| 2453 | case M3UA_MSG_TYP_ASPTM_ASPACAck: |
| 2454 | M3UAState = AssocActive; |
| 2455 | TTCN_Logger::log_event("type: ASPTM_ASPACAck -> nothing will be sent"); |
| 2456 | TTCN_Logger::log_event("M3UAState's been changed to AssocActive."); |
| 2457 | close_log_event(); |
| 2458 | break; |
| 2459 | case M3UA_MSG_TYP_ASPTM_ASPIAAck: |
| 2460 | TTCN_Logger::log_event("type: ASPTM_ASPIAAck -> nothing will be sent"); |
| 2461 | close_log_event(); |
| 2462 | break; |
| 2463 | default: |
| 2464 | TTCN_Logger::log_event("Unsupported M3UA msg type %x of class ASPSM-> packet dropped.", (unsigned char)(inbuffer[M3UA_TYP_OFFS])); |
| 2465 | close_log_event(); |
| 2466 | send_M3UA_error_msg( PAR_ERRC_UNSMT, inbuffer[M3UA_TYP_OFFS]); |
| 2467 | break; |
| 2468 | } |
| 2469 | return length - offset; |
| 2470 | } |
| 2471 | //------------ |
| 2472 | |
| 2473 | //processing M3UA RKM msg |
| 2474 | int MTP3asp__PT_PROVIDER::processing_M3UA_RKM_msg(unsigned char* inbuffer,int length) |
| 2475 | { |
| 2476 | debuglog("Entering function:processing_RKM_msg"); |
| 2477 | int offset = M3UA_MSG_OFFS; //pointer for processing |
| 2478 | warn("Unsupported M3UA msg class M3UA_RKM -> packet dropped."); |
| 2479 | return length - offset; |
| 2480 | } |
| 2481 | //------------ |
| 2482 | |
| 2483 | //processing M3UA unsupported msg class |
| 2484 | int MTP3asp__PT_PROVIDER::processing_M3UA_unsupported_msg_class(unsigned char* inbuffer,int length) |
| 2485 | { |
| 2486 | warn("Unsupported M3UA msg class -> packet dropped."); |
| 2487 | send_M3UA_error_msg( PAR_ERRC_UNSMC, inbuffer[M3UA_CLS_OFFS] ); |
| 2488 | int offset = M3UA_MSG_OFFS; //pointer for processing |
| 2489 | return length - offset; |
| 2490 | } |
| 2491 | //------------ |
| 2492 | |
| 2493 | // processing_M3UA_Transfer_msg - called if the msg class is "Transfer" i.e M3UA_MSG_CLS_TRNSFM: |
| 2494 | int MTP3asp__PT_PROVIDER::processing_M3UA_Transfer_msg(unsigned char* inbuffer,int length) |
| 2495 | { |
| 2496 | debuglog("Entering function:processing_M3UA_Transfer_msg"); |
| 2497 | int offset = M3UA_MSG_OFFS; //pointer for processing |
| 2498 | unsigned int recv_opc, recv_dpc,recv_si, recv_ni, recv_mp,recv_sls =0; |
| 2499 | int param_length = 0; |
| 2500 | TTCN_Logger::begin_event(TTCN_DEBUG); |
| 2501 | TTCN_Logger::log_event("MTP3 Test Port (%s): {", get_name()); |
| 2502 | TTCN_Logger::log_event("decoded msg class: DataTrnsf, "); |
| 2503 | |
| 2504 | switch (inbuffer[M3UA_TYP_OFFS]) //msg type |
| 2505 | { |
| 2506 | case M3UA_MSG_TYP_TRSNFM_DATA: |
| 2507 | TTCN_Logger::log_event("msg type DATA, "); |
| 2508 | while (offset <= length-8) //processing potential params |
| 2509 | { |
| 2510 | switch (inbuffer[offset++]) //1st octet of tag. Offset already incremented after the 'case' ! |
| 2511 | { |
| 2512 | case PAR_PREFIX_COMMON: |
| 2513 | TTCN_Logger::log_event (" DATA: COMMON parameter, "); |
| 2514 | switch (inbuffer[offset++]) //2nd octet of tag |
| 2515 | { |
| 2516 | case PAR_ROUTING_CTX: |
| 2517 | TTCN_Logger::log_event ("Routing Context (unsupported par) -> skipped), "); |
| 2518 | // Send back an error msg |
| 2519 | skip_par_after_tag(inbuffer, offset); |
| 2520 | break; |
| 2521 | case PAR_CORREL_ID: |
| 2522 | TTCN_Logger::log_event ("Correlation ID (unsupported par) -> skipped), "); |
| 2523 | skip_par_after_tag(inbuffer, offset); |
| 2524 | break; |
| 2525 | default: |
| 2526 | TTCN_Logger::log_event ("invalid COMMON param tag:0x%02x%02x -> skipped", PAR_PREFIX_COMMON, inbuffer[offset-1]); |
| 2527 | skip_par_after_tag(inbuffer, offset); |
| 2528 | break; |
| 2529 | } |
| 2530 | case PAR_PREFIX_M3UA: |
| 2531 | TTCN_Logger::log_event ("DATA: M3UA parameter: "); |
| 2532 | switch (inbuffer[offset++]) //2nd octet of M3UA tag |
| 2533 | { |
| 2534 | case PAR_PROT_DATA: |
| 2535 | //--------------------------------------------- |
| 2536 | TTCN_Logger::log_event ("Protocol Data"); |
| 2537 | // retrieving length |
| 2538 | param_length = decode_16b_int(inbuffer+offset); offset+=2; |
| 2539 | TTCN_Logger::log_event(", DATA: Length of Protocol Data parameter is %d",param_length); |
| 2540 | // retrieving M3UA protocol data paremeter opc, dpc, si, ni, mp, |
| 2541 | // sls |
| 2542 | recv_opc = decode_32b_int(inbuffer+offset); offset +=4; |
| 2543 | recv_dpc = decode_32b_int(inbuffer+offset); offset +=4; |
| 2544 | recv_si = (unsigned int)(inbuffer[offset++]); |
| 2545 | recv_ni = (unsigned int)(inbuffer[offset++]); |
| 2546 | recv_mp = (unsigned int)(inbuffer[offset++]); |
| 2547 | recv_sls = (unsigned int)(inbuffer[offset++]); |
| 2548 | TTCN_Logger::log_event(", DATA: decoded Protocol Data parameter:"); |
| 2549 | // filling up TTCN structure |
| 2550 | if ((Loop==MTP3_ON) || |
| 2551 | (!Filter) || |
| 2552 | (Filter && |
| 2553 | (recv_opc == (unsigned)Sut_Pc) && (recv_dpc == (unsigned)Tester_Pc) && |
| 2554 | (recv_ni == (unsigned)mtp3_ni) |
| 2555 | )) |
| 2556 | { |
| 2557 | ASP__MTP3__TRANSFERind recv_msg; |
| 2558 | MTP3__Field__sio recv_sio; |
| 2559 | recv_sio.ni()= int2bit(recv_ni,2); |
| 2560 | recv_sio.prio()= int2bit(recv_mp,2); |
| 2561 | recv_sio.si()= int2bit(recv_si,4); |
| 2562 | recv_msg.sio() = recv_sio; |
| 2563 | recv_msg.sls() = recv_sls; |
| 2564 | recv_msg.opc()= recv_opc; |
| 2565 | recv_msg.dpc() = recv_dpc;; |
| 2566 | recv_msg.data() = OCTETSTRING(param_length-16, // 16 octet paramheader + 5 routing label |
| 2567 | &inbuffer[offset]); |
| 2568 | recv_msg.log(); |
| 2569 | close_log_event(); |
| 2570 | incoming_message ( recv_msg ); |
| 2571 | offset += param_length-16; |
| 2572 | return length - offset; |
| 2573 | } |
| 2574 | else |
| 2575 | { |
| 2576 | close_log_event(); |
| 2577 | log("Either the received M3UA(OPC, DPC, SI) fields, or the embedded MTP3 rooting label (OPC, DPC) not matched with the filter setting -> packet dropped."); |
| 2578 | return length - offset; |
| 2579 | } |
| 2580 | break; |
| 2581 | default: |
| 2582 | TTCN_Logger::log_event ("invalid M3UA param tag:0x%02x%02x-> skipped", PAR_PREFIX_M3UA, inbuffer[offset-1]); |
| 2583 | skip_par_after_tag(inbuffer, offset); |
| 2584 | } |
| 2585 | break; |
| 2586 | default: |
| 2587 | TTCN_Logger::log_event ("invalid 1st octet param tag:0x%02x in DATA (packet dropped)",inbuffer[offset-1]); |
| 2588 | close_log_event(); |
| 2589 | return length -offset; |
| 2590 | break; |
| 2591 | } |
| 2592 | }// Checking parameter tag (offset <length-8) |
| 2593 | break; |
| 2594 | default: |
| 2595 | TTCN_Logger::log_event("Invalid M3UA msg class TransferMessage msg type %d -> packet dropped", |
| 2596 | (unsigned int)(inbuffer[M3UA_TYP_OFFS])); |
| 2597 | close_log_event(); |
| 2598 | send_M3UA_error_msg( PAR_ERRC_UNSMT, inbuffer[M3UA_TYP_OFFS]); |
| 2599 | break; |
| 2600 | } |
| 2601 | |
| 2602 | return length -offset; |
| 2603 | } |
| 2604 | |
| 2605 | // Set M3UA SingleAPC - Stores field Single Affected Point Code |
| 2606 | void MTP3asp__PT_PROVIDER::Set_M3UA_SingleAPC(unsigned int pc, unsigned char* apc_par) |
| 2607 | { |
| 2608 | //setting par type to APC |
| 2609 | apc_par[0] = PAR_PREFIX_COMMON; |
| 2610 | apc_par[1] = PAR_AFFECTED_PC; |
| 2611 | //setting the length to 4+4 = 8 |
| 2612 | apc_par[2] = 0x00; |
| 2613 | apc_par[3] = 0x08; |
| 2614 | //setting the mask |
| 2615 | apc_par[4] = 0x00; |
| 2616 | //setting the pc |
| 2617 | encode_24b_int(apc_par+5,pc); |
| 2618 | } |
| 2619 | |
| 2620 | // Send DAVA DUNA to APCinDAUD |
| 2621 | void MTP3asp__PT_PROVIDER::Send_DAVA_DUNA_to_APCinDAUD(unsigned int dava_sep, unsigned char* inbuffer, int & offset) |
| 2622 | { |
| 2623 | unsigned int length = decode_16b_int(inbuffer+offset); |
| 2624 | offset +=2; |
| 2625 | unsigned int current_pc; |
| 2626 | |
| 2627 | //checking the length |
| 2628 | if ((length < 8) || (length%4)) |
| 2629 | { warn("Invalid length in APC parameter -> not processed"); |
| 2630 | return; |
| 2631 | } |
| 2632 | |
| 2633 | for (unsigned int i = 4 ; i < length; i += 4) |
| 2634 | { |
| 2635 | if (inbuffer[offset++] == 0x00) // mask===>single pc |
| 2636 | { |
| 2637 | current_pc = decode_24b_int(inbuffer+offset); |
| 2638 | offset +=3; |
| 2639 | if (dava_sep == current_pc) //dava |
| 2640 | { Set_M3UA_SingleAPC(dava_sep, dava_1apc_msg+M3UA_MSG_OFFS); |
| 2641 | log("DAVA will be sent for pc=%d", dava_sep); |
| 2642 | send_msg(dava_1apc_msg, sizeof_dava_1apc_msg); |
| 2643 | } |
| 2644 | else //duna |
| 2645 | { Set_M3UA_SingleAPC(current_pc, duna_1apc_msg+M3UA_MSG_OFFS); |
| 2646 | log("DUNA will be sent for pc=%d", current_pc); |
| 2647 | send_msg(duna_1apc_msg, sizeof_duna_1apc_msg); |
| 2648 | } |
| 2649 | } |
| 2650 | else //masked pc |
| 2651 | { warn("Unsupported masking (mask=0x%02x) for PC=%d in APC parameter -> ignored", |
| 2652 | inbuffer[offset-1], current_pc); |
| 2653 | } |
| 2654 | } |
| 2655 | return; |
| 2656 | } |
| 2657 | |
| 2658 | // send M3UA error msg |
| 2659 | // send an eror msg with error_code. Additional parameter matches to the error code: |
| 2660 | void MTP3asp__PT_PROVIDER::send_M3UA_error_msg(unsigned int error_code, unsigned int add_par ) |
| 2661 | { |
| 2662 | encode_16b_int( error_msg+M3UA_MSG_OFFS+4, error_code); |
| 2663 | encode_16b_int( error_msg+M3UA_MSG_OFFS+8, add_par); |
| 2664 | send_msg(error_msg, sizeof_error_msg ); |
| 2665 | }; |
| 2666 | |
| 2667 | // Coder functions for M3UA: int -> unsigned char array |
| 2668 | //------------------------------------------------------ |
| 2669 | // Result:Less significant byte in highest address |
| 2670 | // Most Significant Byte first (in lowest address) = MSB = Big Endian = Network Byte Order |
| 2671 | void MTP3asp__PT_PROVIDER::encode_32b_int(unsigned char *to, unsigned int from) |
| 2672 | { |
| 2673 | to[3] = from & 0xFF; |
| 2674 | from >>= 8; |
| 2675 | to[2] = from & 0xFF; |
| 2676 | from >>= 8; |
| 2677 | to[1] = from & 0xFF; |
| 2678 | from >>= 8; |
| 2679 | to[0] = from & 0xFF; |
| 2680 | } |
| 2681 | //------------ |
| 2682 | |
| 2683 | unsigned int MTP3asp__PT_PROVIDER::decode_32b_int(const unsigned char *from) |
| 2684 | { |
| 2685 | return from[3] | (from[2] << 8) | (from[1] << 16) | (from[0] << 24); |
| 2686 | } |
| 2687 | //------------ |
| 2688 | |
| 2689 | void MTP3asp__PT_PROVIDER::encode_24b_int(unsigned char *to, unsigned int from) |
| 2690 | { |
| 2691 | to[2] = from & 0xFF; |
| 2692 | from >>= 8; |
| 2693 | to[1] = from & 0xFF; |
| 2694 | from >>= 8; |
| 2695 | to[0] = from & 0xFF; |
| 2696 | } |
| 2697 | //------------ |
| 2698 | |
| 2699 | unsigned int MTP3asp__PT_PROVIDER::decode_24b_int(const unsigned char *from) |
| 2700 | { |
| 2701 | return from[2] | (from[1] << 8) | (from[0] << 16); |
| 2702 | } |
| 2703 | //------------ |
| 2704 | |
| 2705 | void MTP3asp__PT_PROVIDER::encode_16b_int(unsigned char *to, int from) |
| 2706 | { |
| 2707 | to[1] = from & 0xFF; |
| 2708 | from >>= 8; |
| 2709 | to[0] = from & 0xFF; |
| 2710 | } |
| 2711 | //------------ |
| 2712 | |
| 2713 | unsigned int MTP3asp__PT_PROVIDER::decode_16b_int(const unsigned char *from) |
| 2714 | { |
| 2715 | return from[1] | (from[0] << 8); |
| 2716 | } |
| 2717 | //------------ |
| 2718 | |
| 2719 | //skip par after tag |
| 2720 | void MTP3asp__PT_PROVIDER::skip_par_after_tag(unsigned char* inbuffer, int &offset) |
| 2721 | { |
| 2722 | offset += decode_16b_int(inbuffer+offset)-2; //the length contains |
| 2723 | //the param hdr. itself |
| 2724 | if (offset%4) offset += 4-(offset%4); //skipping padding |
| 2725 | } |
| 2726 | //------------ |
| 2727 | #endif |
| 2728 | |
| 2729 | |
| 2730 | |
| 2731 | #ifdef TARGET_TEST |
| 2732 | // -------------------------- |
| 2733 | // Functions for Target testing |
| 2734 | // -------------------------- |
| 2735 | // In case of target this function handles the received message |
| 2736 | void MTP3asp__PT_PROVIDER::message_incoming(const unsigned char* msg, int messageLength, int) |
| 2737 | { |
| 2738 | OCTETSTRING rcvData = OCTETSTRING(messageLength, msg); |
| 2739 | |
| 2740 | int msgType = oct2int(substr(rcvData,0,1)); |
| 2741 | switch (msgType) |
| 2742 | { |
| 2743 | case 0: //TRANSFERind message received |
| 2744 | if(Tcp_is_up) //Registration was already performed |
| 2745 | { |
| 2746 | ASP__MTP3__TRANSFERind recv_msg; |
| 2747 | MTP3__Field__sio recv_sio; |
| 2748 | BITSTRING sio_bit = oct2bit(substr(rcvData,5,1)); |
| 2749 | recv_sio.ni()= substr(sio_bit,0,2); |
| 2750 | recv_sio.prio()= substr(sio_bit,2,2); |
| 2751 | recv_sio.si()= substr(sio_bit,4,4); |
| 2752 | recv_msg.sio() = recv_sio; |
| 2753 | recv_msg.opc() = oct2int(substr(rcvData,6,4)); |
| 2754 | recv_msg.dpc() = oct2int(substr(rcvData,10,4)); |
| 2755 | recv_msg.sls() = oct2int(substr(rcvData,14,1)); |
| 2756 | recv_msg.data() = substr(rcvData,15,rcvData.lengthof()-15); |
| 2757 | if (Tcp_is_up == 1) //No unregistration ongoing |
| 2758 | incoming_message(recv_msg); |
| 2759 | else //Unregistration ongoing |
| 2760 | log("Received ASP_MTP3_TRANSFERind is ignored since unregistration is started."); |
| 2761 | } |
| 2762 | else |
| 2763 | error("Message was received before successful registration in M3UA server."); |
| 2764 | break; |
| 2765 | |
| 2766 | case 4: //Status message received |
| 2767 | { |
| 2768 | int status = oct2int(substr(rcvData,5,1)); |
| 2769 | if(Tcp_is_up == 2) // Unregistration ongoing |
| 2770 | { |
| 2771 | const char * rcvDat = oct2str(rcvData); |
| 2772 | log("Message \"%s\" received. Status = %i", rcvDat, status); |
| 2773 | if (status == 2) |
| 2774 | { |
| 2775 | log("Unregistration performed."); |
| 2776 | Tcp_is_up = 0; |
| 2777 | } |
| 2778 | else if (status == 3) |
| 2779 | error("Unsuccessful unregistration."); |
| 2780 | else if (status == 5) { |
| 2781 | if(forward_status) { |
| 2782 | incoming_message(ASP__MTP3__STATUS(NULL_VALUE)); |
| 2783 | } |
| 2784 | else { |
| 2785 | warn("Invalid STATUS message received from M3UA server with status code=%d.", status); |
| 2786 | } |
| 2787 | } |
| 2788 | } |
| 2789 | else if(Tcp_is_up == 1) // Active state |
| 2790 | { |
| 2791 | if (status == 5) { |
| 2792 | if(forward_status) { |
| 2793 | incoming_message(ASP__MTP3__STATUS(NULL_VALUE)); |
| 2794 | } |
| 2795 | } |
| 2796 | else { |
| 2797 | warn("Invalid STATUS message received from M3UA server with status code=%d.", status); |
| 2798 | } |
| 2799 | } |
| 2800 | else // Registration ongoing |
| 2801 | { |
| 2802 | const char * rcvDat = oct2str(rcvData); |
| 2803 | log("Message \"%s\" received. Status = %i", rcvDat, status); |
| 2804 | if (status == 0) |
| 2805 | { |
| 2806 | log("Registration performed."); |
| 2807 | Tcp_is_up = 1; |
| 2808 | } |
| 2809 | else { |
| 2810 | error("Unsuccessful registration."); |
| 2811 | } |
| 2812 | } |
| 2813 | } |
| 2814 | break; |
| 2815 | case 5: |
| 2816 | { |
| 2817 | if(forward_pause) incoming_message(ASP__MTP3__PAUSE(NULL_VALUE)); |
| 2818 | } |
| 2819 | break; |
| 2820 | case 6: |
| 2821 | { |
| 2822 | if(forward_resume) incoming_message(ASP__MTP3__RESUME(NULL_VALUE)); |
| 2823 | } |
| 2824 | break; |
| 2825 | |
| 2826 | |
| 2827 | default: //Unexpected message received |
| 2828 | warn("Invalid message received from M3UA server."); |
| 2829 | } |
| 2830 | } |
| 2831 | |
| 2832 | void MTP3asp__PT_PROVIDER::Check_Target_TestPort_Variables() |
| 2833 | { |
| 2834 | if (Sut_Pc==-1) error("Parameter SUT_Pc is not set."); |
| 2835 | if (Tester_Pc==-1) error("Parameter TESTER_Pc is not set."); |
| 2836 | if (!Ni_is_set) error("Parameter NI is not set."); |
| 2837 | if (M3UA_version==0) error("Parameter M3UA_version cannot be set to 0 in TargetM3UA mode."); |
| 2838 | |
| 2839 | //packet header |
| 2840 | header_descr = new PacketHeaderDescr( 1, 4, PacketHeaderDescr::Header_MSB); |
| 2841 | } |
| 2842 | |
| 2843 | void MTP3asp__PT_PROVIDER::Check_Target_TestPort_Variables_STC() |
| 2844 | { |
| 2845 | if( destinationname == NULL) error("Parameter DestinationName is not set in TargetSTC mode."); |
| 2846 | |
| 2847 | header_descr = new PacketHeaderDescr( 1, 4, PacketHeaderDescr::Header_MSB); |
| 2848 | } |
| 2849 | |
| 2850 | void MTP3asp__PT_PROVIDER::Target_user_map(const char *system_port) |
| 2851 | { |
| 2852 | Tcp_is_up = 0; |
| 2853 | Check_Target_TestPort_Variables(); |
| 2854 | map_user(); |
| 2855 | |
| 2856 | OCTETSTRING tcpData = int2oct(2,1); //Message type |
| 2857 | if( destinationname == NULL) |
| 2858 | tcpData = tcpData + int2oct(char2oct(system_port).lengthof()+15,4); //Length |
| 2859 | else |
| 2860 | tcpData = tcpData + int2oct(char2oct(destinationname).lengthof()+15,4); |
| 2861 | tcpData = tcpData + int2oct(mtp3_ni,1); |
| 2862 | tcpData = tcpData + int2oct(Sut_Pc,4); |
| 2863 | tcpData = tcpData + int2oct(Tester_Pc,4); |
| 2864 | tcpData = tcpData + int2oct(M3UA_version,1); |
| 2865 | if( destinationname == NULL) |
| 2866 | tcpData = tcpData + char2oct(system_port); |
| 2867 | else |
| 2868 | tcpData = tcpData + char2oct(destinationname); |
| 2869 | |
| 2870 | send_outgoing((const unsigned char*)tcpData,tcpData.lengthof()); |
| 2871 | |
| 2872 | TTCN_Logger::begin_event(TTCN_DEBUG); |
| 2873 | TTCN_Logger::log_event("MTP3 Test Port (%s): ", get_name()); |
| 2874 | TTCN_Logger::log_event_str("Registration message sent: "); |
| 2875 | tcpData.log(); |
| 2876 | TTCN_Logger::end_event(); |
| 2877 | |
| 2878 | int fd = get_socket_fd(); |
| 2879 | pollfd pollFd = { fd, POLLIN, 0 }; |
| 2880 | int nEvents = poll(&pollFd, 1, 3000 /* ms */); |
| 2881 | if (nEvents == 0) |
| 2882 | error("No response received for REGISTER message. Exiting after timeout."); |
| 2883 | if (nEvents < 0 || (pollFd.revents & (POLLIN | POLLHUP)) == 0) |
| 2884 | error("No response received for REGISTER message. Exiting after error (%d)", |
| 2885 | (nEvents < 0) ? errno : 0); |
| 2886 | Handle_Fd_Event(fd, TRUE, FALSE, FALSE); |
| 2887 | } |
| 2888 | |
| 2889 | void MTP3asp__PT_PROVIDER::TargetSTC_user_map(const char *system_port) |
| 2890 | { |
| 2891 | Tcp_is_up = 0; |
| 2892 | Check_Target_TestPort_Variables_STC(); |
| 2893 | map_user(); |
| 2894 | |
| 2895 | OCTETSTRING tcpData = int2oct(2,1); //Message type |
| 2896 | tcpData = tcpData + int2oct(char2oct(destinationname).lengthof()+15,4); |
| 2897 | tcpData = tcpData + int2oct(0,1); |
| 2898 | tcpData = tcpData + int2oct(0,4); |
| 2899 | tcpData = tcpData + int2oct(0,4); |
| 2900 | tcpData = tcpData + int2oct(0,1); |
| 2901 | tcpData = tcpData + char2oct(destinationname); |
| 2902 | |
| 2903 | send_outgoing((const unsigned char*)tcpData,tcpData.lengthof()); |
| 2904 | |
| 2905 | TTCN_Logger::begin_event(TTCN_DEBUG); |
| 2906 | TTCN_Logger::log_event("MTP3 Test Port (%s): ", get_name()); |
| 2907 | TTCN_Logger::log_event_str("Registration message sent: "); |
| 2908 | tcpData.log(); |
| 2909 | TTCN_Logger::end_event(); |
| 2910 | |
| 2911 | int fd = get_socket_fd(); |
| 2912 | pollfd pollFd = { fd, POLLIN, 0 }; |
| 2913 | int nEvents = poll(&pollFd, 1, 3000 /* ms */); |
| 2914 | if (nEvents == 0) |
| 2915 | error("No response received for REGISTER message. Exiting after timeout."); |
| 2916 | if (nEvents < 0 || (pollFd.revents & (POLLIN | POLLHUP)) == 0) |
| 2917 | error("No response received for REGISTER message. Exiting after error (%d)", |
| 2918 | (nEvents < 0) ? errno : 0); |
| 2919 | Handle_Fd_Event(fd, TRUE, FALSE, FALSE); |
| 2920 | } |
| 2921 | |
| 2922 | void MTP3asp__PT_PROVIDER::Target_user_unmap(const char *system_port) |
| 2923 | { |
| 2924 | OCTETSTRING tcpData = int2oct(3,1); //Message type |
| 2925 | tcpData = tcpData + int2oct(6,4); //Length |
| 2926 | tcpData = tcpData + int2oct(0,1); |
| 2927 | send_outgoing((const unsigned char*)tcpData,tcpData.lengthof()); |
| 2928 | |
| 2929 | TTCN_Logger::begin_event(TTCN_DEBUG); |
| 2930 | TTCN_Logger::log_event("MTP3 Test Port (%s): ", get_name()); |
| 2931 | TTCN_Logger::log_event_str("Unregistration message sent: "); |
| 2932 | tcpData.log(); |
| 2933 | TTCN_Logger::end_event(); |
| 2934 | |
| 2935 | Tcp_is_up = 2; //Unregistration ongoing |
| 2936 | |
| 2937 | while (Tcp_is_up == 2) |
| 2938 | { |
| 2939 | int fd = get_socket_fd(); |
| 2940 | pollfd pollFd = { fd, POLLIN, 0 }; |
| 2941 | int nEvents = poll(&pollFd, 1, 3000 /* ms */); |
| 2942 | if (nEvents == 0) |
| 2943 | error("No response received for UNREGISTER message. Exiting after timeout."); |
| 2944 | if (nEvents < 0 || (pollFd.revents & (POLLIN | POLLHUP)) == 0) |
| 2945 | error("No response received for UNREGISTER message. Exiting after error (%d)", |
| 2946 | (nEvents < 0) ? errno : 0); |
| 2947 | Handle_Fd_Event(fd, TRUE, FALSE, FALSE); |
| 2948 | } |
| 2949 | unmap_user(); |
| 2950 | } |
| 2951 | #endif |
| 2952 | } |