char * getFullDeviceMac() { if(strlen(fullDeviceMAC) == 0) { getDeviceMac(); } return fullDeviceMAC; }
/* function call from lmlite with parameters */ void network_devices_status_report(struct networkdevicestatusdata *head, BOOL extender, char* parent_mac) { int i = 0, k = 0; uint8_t* b64buffer = NULL; size_t decodesize = 0; int numElements = 0; struct networkdevicestatusdata* ptr = head; avro_writer_t writer; char * serviceName = "lmlite"; char * dest = "event:raw.kestrel.reports.NetworkDevicesStatus"; char * contentType = "avro/binary"; // contentType "application/json", "avro/binary" uuid_t transaction_id; char trans_id[37]; char CpeMacHoldingBuf[ 20 ] = {0}; unsigned char CpeMacid[ 7 ] = {0}; CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, LMLite %s : ENTER \n", __FUNCTION__ )); numElements = NumberofElementsinLinkedList(head); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, numElements = %d\n", numElements )); OneAvroSerializedSize = 0; /* goes thru total number of elements in link list */ writer = prepare_writer_status(); //Reset out writer avro_writer_reset(writer); //Network Device Report avro_value_t adr; avro_generic_value_new(iface, &adr); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, GatewayNetworkDeviceStatusReport\tType: %d\n", avro_value_get_type(&adr))); avro_value_t adrField = {0,0}; avro_value_t array = {0,0}; size_t new_index = 0; //Optional value for unions, mac address is an union avro_value_t optional = {0,0}; // timestamp - long avro_value_get_by_name(&adr, "header", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_get_by_name(&adrField, "timestamp", &adrField, NULL); avro_value_set_branch(&adrField, 1, &optional); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); struct timeval ts; gettimeofday(&ts, NULL); #ifndef UTC_ENABLE int64_t tstamp_av_main = ((int64_t) (ts.tv_sec - getTimeOffsetFromUtc()) * 1000000) + (int64_t) ts.tv_usec; #else int64_t tstamp_av_main = ((int64_t) (ts.tv_sec) * 1000000) + (int64_t) ts.tv_usec; #endif tstamp_av_main = tstamp_av_main/1000; avro_value_set_long(&optional, tstamp_av_main ); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, timestamp = ""%" PRId64 "\n", tstamp_av_main )); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, timestamp\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); // uuid - fixed 16 bytes uuid_generate_random(transaction_id); uuid_unparse(transaction_id, trans_id); avro_value_get_by_name(&adr, "header", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_get_by_name(&adrField, "uuid", &adrField, NULL); avro_value_set_branch(&adrField, 1, &optional); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_fixed(&optional, transaction_id, 16); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, uuid\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); //source - string avro_value_get_by_name(&adr, "header", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_get_by_name(&adrField, "source", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&adrField, 1, &optional); avro_value_set_string(&optional, ReportSource); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, source\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); if ( extender == FALSE ) { //cpe_id block /* MAC - Get CPE mac address, do it only pointer is NULL */ memset(CpeMacHoldingBuf, 0, sizeof CpeMacHoldingBuf); memset(CpeMacid, 0, sizeof CpeMacid); if ( macStr == NULL ) { macStr = getDeviceMac(); strncpy( CpemacStr, macStr, sizeof(CpemacStr)); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Received DeviceMac from Atom side: %s\n",macStr)); } for (k = 0; k < 6; k++ ) { /* copy 2 bytes */ CpeMacHoldingBuf[ k * 2 ] = CpemacStr[ k * 2 ]; CpeMacHoldingBuf[ k * 2 + 1 ] = CpemacStr[ k * 2 + 1 ]; CpeMacid[ k ] = (unsigned char)strtol(&CpeMacHoldingBuf[ k * 2 ], NULL, 16); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Mac address = %0x\n", CpeMacid[ k ] )); } avro_value_get_by_name(&adr, "cpe_id", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_get_by_name(&adrField, "mac_address", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&adrField, 1, &optional); avro_value_set_fixed(&optional, CpeMacid, 6); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, mac_address\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); // cpe_type - string avro_value_get_by_name(&adr, "cpe_id", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_get_by_name(&adrField, "cpe_type", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&adrField, 1, &optional); avro_value_set_string(&optional, CPE_TYPE_GATEWAY_STRING); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, cpe_type\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); // cpe_parent - Recurrsive CPEIdentifier block avro_value_get_by_name(&adr, "cpe_id", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_get_by_name(&adrField, "cpe_parent", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&adrField, 0, &optional); avro_value_set_null(&optional); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, cpe_parent\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); } else { //cpe_id block avro_value_t parent_optional = {0,0}, parent_adrField = {0,0}; memset(CpeMacHoldingBuf, 0, sizeof CpeMacHoldingBuf); memset(CpeMacid, 0, sizeof CpeMacid); for (k = 0; k < 6; k++ ) { /* copy 2 bytes */ CpeMacHoldingBuf[ k * 2 ] = parent_mac[ k * 3 ]; CpeMacHoldingBuf[ k * 2 + 1 ] = parent_mac[ k * 3 + 1 ]; CpeMacid[ k ] = (unsigned char)strtol(&CpeMacHoldingBuf[ k * 2 ], NULL, 16); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Extender Mac address = %0x\n", CpeMacid[ k ] )); } avro_value_get_by_name(&adr, "cpe_id", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_get_by_name(&adrField, "mac_address", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&adrField, 1, &optional); avro_value_set_fixed(&optional, CpeMacid, 6); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, mac_address\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); // cpe_type - string avro_value_get_by_name(&adr, "cpe_id", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_get_by_name(&adrField, "cpe_type", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&adrField, 1, &optional); avro_value_set_string(&optional, CPE_TYPE_EXTENDER_STRING); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, cpe_type\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); // cpe_parent - Recurrsive CPEIdentifier block avro_value_get_by_name(&adr, "cpe_id", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_get_by_name(&adrField, "cpe_parent", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); /* MAC - Get CPE mac address, do it only pointer is NULL */ if ( macStr == NULL ) { macStr = getDeviceMac(); strncpy( CpemacStr, macStr, sizeof(CpemacStr)); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Received DeviceMac from Atom side: %s\n",macStr)); } memset(CpeMacHoldingBuf, 0, sizeof CpeMacHoldingBuf); memset(CpeMacid, 0, sizeof CpeMacid); for (k = 0; k < 6; k++ ) { /* copy 2 bytes */ CpeMacHoldingBuf[ k * 2 ] = CpemacStr[ k * 2 ]; CpeMacHoldingBuf[ k * 2 + 1 ] = CpemacStr[ k * 2 + 1 ]; CpeMacid[ k ] = (unsigned char)strtol(&CpeMacHoldingBuf[ k * 2 ], NULL, 16); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG Parent Mac address = %0x\n", CpeMacid[ k ] )); } // assume 1 parent ONLY // Parent MAC avro_value_set_branch(&adrField, 1, &parent_optional); avro_value_get_by_name(&parent_optional, "mac_address", &parent_adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&parent_adrField, 1, &parent_optional); avro_value_set_fixed(&parent_optional, CpeMacid, 6); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, parent mac_address\tType: %d\n", avro_value_get_type(&parent_optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); // Parent cpe_type avro_value_set_branch(&adrField, 1, &parent_optional); avro_value_get_by_name(&parent_optional, "cpe_type", &parent_adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&parent_adrField, 1, &parent_optional); avro_value_set_string(&parent_optional, CPE_TYPE_GATEWAY_STRING); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, parent cpe_type\tType: %d\n", avro_value_get_type(&parent_optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); // no more parent, set NULL avro_value_set_branch(&adrField, 1, &parent_optional); avro_value_get_by_name(&parent_optional, "cpe_parent", &parent_adrField, NULL); avro_value_set_branch(&parent_adrField, 0, &parent_optional); avro_value_set_null(&parent_optional); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, parent cpe_parent\tType: %d\n", avro_value_get_type(&parent_optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); } //host_table_version block avro_value_get_by_name(&adr, "host_table_version", &adrField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&adrField, 1, &optional); avro_value_set_long(&optional, lmHosts.lastActivity); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, host_table_version\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); //Data Field block avro_value_get_by_name(&adr, "data", &adrField, NULL); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, NetworkDeviceStatusReports - data array\tType: %d\n", avro_value_get_type(&adrField))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); //adrField now contains a reference to the AssociatedDeviceReportsArray //Device Report avro_value_t dr = {0,0}; //Current Device Report Field avro_value_t drField = {0,0}; while(ptr) { if( (!strcmp(ptr->parent, parent_mac) && (extender == TRUE)) || (extender == FALSE) ) { CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Current Link List Ptr = [0x%lx], numElements = %d\n", (ulong)ptr, numElements )); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \tDevice entry #: %d\n", i + 1)); //Append a DeviceReport item to array avro_value_append(&adrField, &dr, NULL); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \tDevice Status Report\tType: %d\n", avro_value_get_type(&dr))); //data array block memset(CpeMacHoldingBuf, 0, sizeof CpeMacHoldingBuf); memset(CpeMacid, 0, sizeof CpeMacid); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Mac address from node list = %s \n", ptr->device_mac )); for (k = 0; k < 6; k++ ) { /* copy 2 bytes */ CpeMacHoldingBuf[ k * 2 ] = ptr->device_mac[ k * 3 ]; CpeMacHoldingBuf[ k * 2 + 1 ] = ptr->device_mac[ k * 3 + 1 ]; CpeMacid[ k ] = (unsigned char)strtol(&CpeMacHoldingBuf[ k * 2 ], NULL, 16); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Mac address = %0x\n", CpeMacid[ k ] )); } //device_mac - fixed 6 bytes avro_value_get_by_name(&dr, "device_id", &drField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, device_id\tType: %d\n", avro_value_get_type(&drField))); avro_value_get_by_name(&drField, "mac_address", &drField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&drField, 1, &optional); avro_value_set_fixed(&optional, CpeMacid, 6); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \tmac_address\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); //device_type - string avro_value_get_by_name(&dr, "device_id", &drField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, device_id\tType: %d\n", avro_value_get_type(&drField))); avro_value_get_by_name(&drField, "device_type", &drField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&drField, 1, &optional); avro_value_set_string(&optional, ptr->device_type); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \tdevice_type\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); //timestamp - long avro_value_get_by_name(&dr, "timestamp", &drField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&drField, 1, &optional); int64_t tstamp_av = (int64_t) ptr->timestamp.tv_sec * 1000000 + (int64_t) ptr->timestamp.tv_usec; tstamp_av = tstamp_av/1000; avro_value_set_long(&optional, tstamp_av); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, timestamp = ""%" PRId64 "\n", tstamp_av )); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \ttimestamp\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); //interface_name - string avro_value_get_by_name(&dr, "interface_name", &drField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&drField, 1, &optional); //avro_value_set_string(&optional, " aa "); avro_value_set_string(&optional, ptr->interface_name ); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \tinterface_name\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); //status - enum avro_value_get_by_name(&dr, "status", &drField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&drField, 1, &optional); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, status\tType: %d\n", avro_value_get_type(&optional))); if ( ptr->is_active ) avro_value_set_enum(&optional, avro_schema_enum_get_by_name(avro_value_get_schema(&optional), "ONLINE")); else avro_value_set_enum(&optional, avro_schema_enum_get_by_name(avro_value_get_schema(&optional), "OFFLINE")); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); //hostname - string avro_value_get_by_name(&dr, "hostname", &drField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&drField, 1, &optional); avro_value_set_string(&optional, ptr->hostname); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \thostname\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); //ipaddress - array avro_value_get_by_name(&dr, "ip_addresses", &drField, NULL); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); avro_value_set_branch(&drField, 1, &optional); avro_value_append(&optional, &array, NULL); avro_value_set_string(&array, ptr->ipaddress); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \tipaddress\tType: %d\n", avro_value_get_type(&optional))); if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror())); i++; } #if SIMULATION ptr = 0; #else ptr = ptr->next; // next link list #endif /* check for writer size, if buffer is almost full, skip trailing linklist */ avro_value_sizeof(&adr, &AvroSerializedSize); OneAvroSerializedSize = ( OneAvroSerializedSize == 0 ) ? AvroSerializedSize : OneAvroSerializedSize; if ( ( WRITER_BUF_SIZE - AvroSerializedSize ) < OneAvroSerializedSize ) { CcspLMLiteTrace(("RDK_LOG_ERROR, AVRO write buffer is almost full, size = %d func %s, exit!\n", (int)AvroSerializedSize, __FUNCTION__ )); break; } } //Thats the end of that avro_value_write(writer, &adr); avro_value_sizeof(&adr, &AvroSerializedSize); AvroSerializedSize += MAGIC_NUMBER_SIZE + SCHEMA_ID_LENGTH; CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Serialized writer size %d\n", (int)AvroSerializedSize)); //Free up memory avro_value_decref(&adr); avro_writer_free(writer); //free(buffer); /* if ( consoleDebugEnable ) { // b64 encoding decodesize = b64_get_encoded_buffer_size( AvroSerializedSize ); b64buffer = malloc(decodesize * sizeof(uint8_t)); b64_encode( (uint8_t*)AvroSerializedBuf, AvroSerializedSize, b64buffer); fprintf( stderr, "\nAVro serialized data\n"); for (k = 0; k < (int)AvroSerializedSize ; k++) { char buf[30]; if ( ( k % 32 ) == 0 ) fprintf( stderr, "\n"); sprintf(buf, "%02X", (unsigned char)AvroSerializedBuf[k]); fprintf( stderr, "%c%c", buf[0], buf[1] ); } fprintf( stderr, "\n\nB64 data\n"); for (k = 0; k < (int)decodesize; k++) { if ( ( k % 32 ) == 0 ) fprintf( stderr, "\n"); fprintf( stderr, "%c", b64buffer[k]); } fprintf( stderr, "\n\n"); free(b64buffer); }*/ CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Before ND WebPA SEND message call\n")); #ifdef PARODUS_ENABLE CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, serviceName: %s\n", serviceName)); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, dest: %s\n", dest)); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, trans_id: %s\n", trans_id)); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, contentType: %s\n", contentType)); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, AvroSerializedBuf: %s\n", AvroSerializedBuf)); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, AvroSerializedSize: %d\n", (int)AvroSerializedSize)); #endif // Send data from LMLite to webpa using CCSP bus interface sendWebpaMsg(serviceName, dest, trans_id, contentType, AvroSerializedBuf, AvroSerializedSize); CcspTraceWarning(("NetworkDevicesStatus report sent to Webpa, Destination=%s, Transaction-Id=%s \n",dest,trans_id)); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, After ND WebPA SEND message call\n")); CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, LMLite %s : EXIT \n", __FUNCTION__ )); #if SIMULATION exit(0); #endif }
AJ_EXPORT AJ_Status AJ_WSL_NET_connect(const char* SSID, const char* passphrase, WSL_NET_AUTH_MODE auth, WSL_NET_CRYPTO_TYPE crypto, uint8_t softAP) { AJ_Status status; wsl_scan_list* list; list = (wsl_scan_list*)AJ_WSL_GetScanList(); WSL_ClearScanList(list); AJ_WSL_NET_SetPowerMode(2); uint8_t bss_mac[6]; // Open auth does not require you to explicitly set the BSSID so this secondary scan is not needed if (!softAP) { if (auth != WSL_NET_AUTH_NONE) { // Do a scan of just the SSID you want AJ_WSL_SetProbedSSID(SSID, 1); { AJ_BufList* start_scan; uint8_t found = 0; int i; AJ_WSL_NET_set_scan_params(); while (!found) { wsl_work_item* item; AJ_InfoPrintf(("AJ_WSL_NET_scan(): START_SCAN\n")); start_scan = AJ_BufListCreate(); AJ_WSL_SetProbedSSID(SSID, 1); AJ_WSL_NET_set_scan_params(); AJ_WSL_NET_BSS_FILTER(6); WSL_MarshalPacket(start_scan, WSL_START_SCAN, 0, 0, 0, 0, 0, 0, 0, 0); WMI_MarshalHeader(start_scan, 1, 1); AJ_WSL_WMI_PadPayload(start_scan); //AJ_BufListPrintDumpContinuous(start_scan); AJ_WSL_WMI_QueueWorkItem(0, AJ_WSL_WORKITEM(AJ_WSL_WORKITEM_NETWORK, WSL_NET_SCAN), AJ_WSL_HTC_DATA_ENDPOINT1, start_scan); status = AJ_WSL_WMI_WaitForWorkItem(0, AJ_WSL_WORKITEM(AJ_WSL_WORKITEM_NETWORK, WSL_NET_SCAN), &item); AJ_WSL_WMI_FreeWorkItem(item); // Get the new list (just of the SSID provided in the connect command) AJ_WSL_NET_scan_stop(); list = (wsl_scan_list*)AJ_WSL_GetScanList(); if (list->size == 0) { AJ_AlwaysPrintf(("Could not find access point %s\n", SSID)); WSL_ClearScanList(list); AJ_Sleep(AJ_WSL_CONNECT_WAIT); continue; } WSL_PrintScanSorted(); // Find the SSID you want to connect to in the second scan list for (i = 0; i < list->size; i++) { if (0 == strcmp(list->list[i].ssid, SSID)) { memcpy(&bss_mac, list->list[i].bssid, 6); found = 1; break; } } WSL_ClearScanList(list); } } } } { AJ_BufList* connect; AJ_BufList* connectOut; static const uint8_t zero_mac[6] = { 0, 0, 0, 0, 0, 0 }; uint8_t connect_mac[6]; wsl_work_item* item = NULL; uint8_t found = 0; connect = AJ_BufListCreate(); /* Three different ways connect can be called. * 1. SoftAP: The devices mac is fetched and used * 2. Using Auth: The SSID's mac is found and used * 3. Open auth: A zero'ed mac is used */ if (softAP) { WSL_MarshalPacket(connect, WSL_SET_SOFT_AP, 0, 0x04, 0x01, auth, crypto, 0x00, crypto, 0x00, strlen(SSID), SSID, 0x0, getDeviceMac(), 0x0044, 0x0000); WMI_MarshalHeader(connect, 1, 1); } else if ((auth != WSL_NET_AUTH_NONE) && (crypto != WSL_NET_CRYPTO_WEP)) { WSL_MarshalPacket(connect, WSL_CONNECT, 0, 0x01, 0x01, auth, crypto, 0x00, crypto, 0x00, strlen(SSID), SSID, 0x0, &bss_mac, 0x0044, 0x0000); WMI_MarshalHeader(connect, 1, 1); } else { // if the auth mode is open, use zero_mac, and set flags to zero WSL_MarshalPacket(connect, WSL_CONNECT, 0, 0x01, 0x01, auth, crypto, 0x00, crypto, 0x00, strlen(SSID), SSID, 0x0, &zero_mac, 0x0000, 0x0000); WMI_MarshalHeader(connect, 1, 1); } AJ_InfoPrintf(("AJ_WSL_NET_connect(): CONNECT\n")); AJ_WSL_WMI_PadPayload(connect); //AJ_BufListPrintDumpContinuous(connect); connectOut = AJ_BufListCreateCopy(connect); AJ_WSL_WMI_QueueWorkItem(0, AJ_WSL_WORKITEM(AJ_WSL_WORKITEM_NETWORK, WSL_NET_CONNECT), AJ_WSL_HTC_DATA_ENDPOINT1, connectOut); if (softAP) { AJ_AlwaysPrintf(("Waiting for a connection to the softAP %s\n", SSID)); memcpy(&connect_mac, (uint8_t*)getDeviceMac(), sizeof(connect_mac)); while (WSL_MacsAreEqual((uint8_t*)&connect_mac, (uint8_t*)getDeviceMac()) == TRUE) { status = AJ_WSL_WMI_WaitForWorkItem(0, AJ_WSL_WORKITEM(AJ_WSL_WORKITEM_NETWORK, WSL_NET_CONNECT), &item); if (item) { if (item->itemType == WSL_NET_CONNECT) { AJ_InfoPrintf(("AJ_WSL_ip6config(): WORK ITEM RECEIVED\n")); uint16_t WMIEvent; uint32_t toss; uint16_t channel; WMI_Unmarshal(item->node->buffer, "quqM", &WMIEvent, &toss, &channel, &connect_mac); } else { AJ_WarnPrintf(("AJ_WSL_NET_connect(): BAD WORK ITEM RECEIVED\n")); } AJ_WSL_WMI_FreeWorkItem(item); found = 1; } } } else { status = AJ_WSL_WMI_WaitForWorkItem(0, AJ_WSL_WORKITEM(AJ_WSL_WORKITEM_NETWORK, WSL_NET_CONNECT), &item); AJ_WSL_WMI_FreeWorkItem(item); } AJ_BufListFree(connect, 1); return status; } }
AJ_EXPORT AJ_Status AJ_WSL_NET_connect(const char* SSID, const char* passphrase, WSL_NET_AUTH_MODE auth, WSL_NET_CRYPTO_TYPE crypto, uint8_t softAP) { AJ_Status status = AJ_OK; wsl_scan_list* list; list = (wsl_scan_list*)AJ_WSL_GetScanList(); AJ_WSL_NET_SetPowerMode(2); uint8_t bss_mac[6]; // Open auth does not require you to explicitly set the BSSID so this secondary scan is not needed if (!softAP) { if (auth != WSL_NET_AUTH_NONE) { AJ_Time timer; uint8_t found = 0; AJ_InitTimer(&timer); while (!found) { AJ_WSL_InitScanList(AJ_WSL_SCAN_LIST_SIZE); AJ_WSL_SetProbedSSID(SSID, 1); status = AJ_WSL_NET_scan(); // Some kind of scan error if (status != AJ_OK) { WSL_ClearScanList(); continue; } AJ_WSL_NET_scan_stop(); if (AJ_GetElapsedTime(&timer, TRUE) > AJ_WSL_CONNECT_TIMEOUT) { AJ_ErrPrintf(("AJ_WSL_NET_connect() Could not find the access point %s\n", SSID)); WSL_ClearScanList(); return AJ_ERR_FAILURE; } // Find the SSID you want to connect to in the second scan list if (getMacFromSSID(SSID, bss_mac, list)) { WSL_ClearScanList(); found = 1; break; } else { WSL_ClearScanList(); AJ_Sleep(AJ_WSL_CONNECT_WAIT); continue; } } if (crypto != WSL_NET_CRYPTO_WEP) { status = AJ_WSL_NET_SetPassphrase(SSID, passphrase, strlen(passphrase)); if (status != AJ_OK) { return status; } } } } { AJ_BufList* connect; AJ_BufList* connectOut; static const uint8_t zero_mac[6] = { 0, 0, 0, 0, 0, 0 }; uint8_t connect_mac[6]; wsl_work_item* item = NULL; connect = AJ_BufListCreate(); /* Three different ways connect can be called. * 1. SoftAP: The devices mac is fetched and used * 2. Using Auth: The SSID's mac is found and used * 3. Open auth: A zero'ed mac is used */ if (softAP) { WSL_MarshalPacket(connect, WSL_SET_SOFT_AP, 0, 0x04, 0x01, auth, crypto, 0x00, crypto, 0x00, strlen(SSID), SSID, 0x0, getDeviceMac(), 0x0044, 0x0000); WMI_MarshalHeader(connect, 1, 1); } else if ((auth != WSL_NET_AUTH_NONE) && (crypto != WSL_NET_CRYPTO_WEP)) { WSL_MarshalPacket(connect, WSL_CONNECT, 0, 0x01, 0x01, auth, crypto, 0x00, crypto, 0x00, strlen(SSID), SSID, 0x0, &bss_mac, 0x0044, 0x0000); WMI_MarshalHeader(connect, 1, 1); } else { // if the auth mode is open, use zero_mac, and set flags to zero WSL_MarshalPacket(connect, WSL_CONNECT, 0, 0x01, 0x01, auth, crypto, 0x00, crypto, 0x00, strlen(SSID), SSID, 0x0, &zero_mac, 0x0000, 0x0000); WMI_MarshalHeader(connect, 1, 1); } AJ_InfoPrintf(("AJ_WSL_NET_connect(): CONNECT\n")); AJ_WSL_WMI_PadPayload(connect); //AJ_BufListPrintDumpContinuous(connect); connectOut = AJ_BufListCreateCopy(connect); AJ_WSL_WMI_QueueWorkItem(0, AJ_WSL_WORKITEM(AJ_WSL_WORKITEM_NETWORK, WSL_NET_CONNECT), AJ_WSL_HTC_DATA_ENDPOINT1, connectOut); if (softAP) { AJ_AlwaysPrintf(("Waiting for a connection to the softAP %s\n", SSID)); memcpy(&connect_mac, (uint8_t*)getDeviceMac(), sizeof(connect_mac)); while (memcmp((uint8_t*)&connect_mac, (uint8_t*)getDeviceMac(), 6) == 0) { status = AJ_WSL_WMI_WaitForWorkItem(0, AJ_WSL_WORKITEM(AJ_WSL_WORKITEM_NETWORK, WSL_NET_CONNECT), &item, AJ_TIMER_FOREVER); if (item && (status == AJ_OK)) { if (item->itemType == WSL_NET_CONNECT) { AJ_InfoPrintf(("AJ_WSL_NET_connect(): WORK ITEM RECEIVED\n")); uint16_t WMIEvent; uint32_t toss; uint16_t channel; WMI_Unmarshal(item->node->buffer, "quqM", &WMIEvent, &toss, &channel, &connect_mac); } else { AJ_WarnPrintf(("AJ_WSL_NET_connect(): BAD WORK ITEM RECEIVED\n")); } AJ_WSL_WMI_FreeWorkItem(item); } } } else { status = AJ_WSL_WMI_WaitForWorkItem(0, AJ_WSL_WORKITEM(AJ_WSL_WORKITEM_NETWORK, WSL_NET_CONNECT), &item, AJ_TIMER_FOREVER); if (item && (status == AJ_OK)) { AJ_WSL_WMI_FreeWorkItem(item); } } AJ_BufListFree(connect, 1); return status; } }