uint8_t AJRouter_Connect(AJ_BusAttachment* busAttachment, const char* routerName) { while (TRUE) { AJ_Status status = AJ_OK; #ifdef ONBOARDING_SERVICE status = AJOBS_EstablishWiFi(); if (status != AJ_OK) { AJ_AlwaysPrintf(("Failed to establish WiFi connectivity with status=%s\n", AJ_StatusText(status))); AJ_Sleep(AJAPP_CONNECT_PAUSE); return FALSE; } #endif AJ_AlwaysPrintf(("Attempting to connect to bus '%s'\n", routerName)); status = AJ_FindBusAndConnect(busAttachment, routerName, AJAPP_CONNECT_TIMEOUT); if (status != AJ_OK) { AJ_AlwaysPrintf(("Failed to connect to bus sleeping for %d seconds\n", AJAPP_CONNECT_PAUSE / 1000)); AJ_Sleep(AJAPP_CONNECT_PAUSE); #ifdef ONBOARDING_SERVICE if (status == AJ_ERR_DHCP) { AJOBS_SwitchToRetry(); } #endif continue; } const char* busUniqueName = AJ_GetUniqueName(busAttachment); if (busUniqueName == NULL) { AJ_AlwaysPrintf(("Failed to GetUniqueName() from newly connected bus, retrying\n")); continue; } AJ_AlwaysPrintf(("Connected to router with BusUniqueName=%s\n", busUniqueName)); break; } return TRUE; }
static uint32_t PasswordCallback(uint8_t* buffer, uint32_t bufLen) { AJ_Status status = AJ_OK; #ifdef CONFIG_SERVICE const char* hexPassword = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_PASSCODE); #else const char* hexPassword = "******"; #endif size_t hexPasswordLen; uint32_t len = 0; if (hexPassword == NULL) { AJ_AlwaysPrintf(("Password is NULL!\n")); return len; } AJ_AlwaysPrintf(("Configured password=%s\n", hexPassword)); hexPasswordLen = strlen(hexPassword); len = hexPasswordLen / 2; status = AJ_HexToRaw(hexPassword, hexPasswordLen, buffer, bufLen); if (status == AJ_ERR_RESOURCES) { len = 0; } return len; }
static AJ_Status SendEvent(AJ_BusAttachment* busAttachment, uint32_t eventId) { AJ_Status status = AJ_OK; AJ_Message msg; status = AJ_MarshalSignal(busAttachment, &msg, eventId, NULL, 0, AJ_FLAG_SESSIONLESS, 0); if (status != AJ_OK) { goto ErrorExit; } status = AJ_DeliverMsg(&msg); if (status != AJ_OK) { goto ErrorExit; } status = AJ_CloseMsg(&msg); if (status != AJ_OK) { goto ErrorExit; } AJ_AlwaysPrintf(("Event sent successfully\n")); return status; ErrorExit: AJ_AlwaysPrintf(("Event sending failed with status=%s\n", AJ_StatusText(status))); return status; }
static AJ_Status AppHandlePing(AJ_Message* msg) { AJ_Status status; AJ_Message reply; AJ_Arg arg; status = AJ_UnmarshalArg(msg, &arg); if (AJ_OK == status) { if (arg.typeId == AJ_ARG_STRING) { AJ_AlwaysPrintf(("Received ping request '%s'.\n", arg.val.v_string)); } else { AJ_AlwaysPrintf(("Unexpected arg type '%d' in ping request.\n", arg.typeId)); } status = AJ_MarshalReplyMsg(msg, &reply); if (AJ_OK == status) { /* * Just return the arg we received */ status = AJ_MarshalArg(&reply, &arg); if (AJ_OK == status) { status = AJ_DeliverMsg(&reply); } } } return status; }
static void AJ_WSL_HTCProcessControlMessageResponse_Fake(AJ_BufNode* pNodeHTCBody) { wsl_wmi_cmd_hdr* wmiCmdHdr2; wmiCmdHdr2 = (wsl_wmi_cmd_hdr*)pNodeHTCBody->buffer; AJ_WSL_WMI_CMD_HDR_FROM_WIRE(wmiCmdHdr2); AJ_WSL_WMI_CMD_HDR_Print(wmiCmdHdr2); AJ_BufNodePullBytes(pNodeHTCBody, sizeof(wsl_wmi_cmd_hdr)); if (wmiCmdHdr2->commandID == WMI_SOCKET_CMDID) { wsl_wmi_socket_response_event* pSocketResp = (wsl_wmi_socket_response_event*)pNodeHTCBody->buffer; AJ_WSL_WMI_SOCK_RESPONSE_FROM_WIRE(pSocketResp); switch (pSocketResp->responseType) { case WSL_SOCK_OPEN: { //AJ_AlwaysPrintf(("PING response was received over the wire: addr 0x%x, size 0x%x\n\n", ping->ip_addr, ping->size)); AJ_AlwaysPrintf(("OPEN response was received over the wire, Handle is %x\n\n", pSocketResp->socketHandle)); break; } case WSL_SOCK_PING: { //wsl_wmi_sock_ping* ping = (wsl_wmi_sock_ping*)pNodeHTCBody->buffer; //AJ_WSL_WMI_SOCK_PING_FROM_WIRE(ping); //AJ_AlwaysPrintf(("PING response was received over the wire: addr 0x%x, size 0x%x\n\n", ping->ip_addr, ping->size)); AJ_AlwaysPrintf(("PING response was received over the wire, Handle is %x\n\n", pSocketResp->socketHandle)); break; } default: AJ_ASSERT("unknown socket command\n\n"); } } }
static void handleOptionalProperty(const char* peerName, const char* key, const char* sig, const AJ_Arg* value) { if (strcmp(sig, "s") == 0) { AJ_AlwaysPrintf(("Optional Prop: %s=\"%s\"\n", key, value->val.v_string)); } else { AJ_AlwaysPrintf(("Optional Prop: %s=[Not A String]\n", key)); } }
void AllJoyn_Start() { AJ_Status status = AJ_OK; AJ_AlwaysPrintf(("AllJoyn Version %s\n", AJ_GetVersion())); // status = AJ_WiFiScan(NULL, ScanResult, 32); // if (status != AJ_OK) { // AJ_AlwaysPrintf(("WiFi scan failed\n")); // } // status = ConfigureSoftAP(); esp_init(115200); status = ConfigureWifi(); // esp_serial_proxy(); if (status == AJ_OK) { // AJ_Initialize(); AJ_Main(); } AJ_AlwaysPrintf(("Quitting\n")); while (TRUE) { } }
/** * Callback function prototype for requesting a password or pincode from an application. * * @param buffer The buffer to receive the password. * @param bufLen The size of the buffer * * @return Returns the length of the password. If the length is zero this will be * treated as a rejected password request. */ static uint32_t PasswordCallback(uint8_t* buffer, uint32_t bufLen) { char inputBuffer[16]; const uint32_t bufSize = sizeof(inputBuffer) / sizeof(inputBuffer[0]); uint32_t maxCopyLength; #ifdef AJ_NO_CONSOLE /* If there is no console to read/write from/to. */ const char password[] = "107734"; /* Upside down this can be read as 'hELLO!'. */ maxCopyLength = sizeof(password) - 1; if (maxCopyLength > bufSize) { maxCopyLength = bufSize; } memcpy(inputBuffer, password, maxCopyLength); #else /* Take input from stdin and send it. */ AJ_AlwaysPrintf(("Please enter one time password : "******"Responding with password of '%s' length %u.\n", inputBuffer, maxCopyLength)); return maxCopyLength; }
AJ_Status ReceiveNewName(AJ_Message*msg) { AJ_Arg arg; AJ_Status status = AJ_UnmarshalArg(msg, &arg); if (status == AJ_OK) { AJ_AlwaysPrintf(("--==## signalConsumer: Name Changed signal Received ##==--\n")); AJ_AlwaysPrintf(("\tNew name: '%s'.\n", arg.val.v_string)); } return status; }
void TimerCallbackEndProc(uint32_t timerId, void* context) { AJ_AlwaysPrintf(("TimerCallbackEndProc %.6d \n", timerId)); #ifdef READTEST if (0 == memcmp(txBuffer, rxBuffer, sizeof(rxBuffer))) { AJ_AlwaysPrintf(("Passed: buffers match.\n")); } else { AJ_AlwaysPrintf(("FAILED: buffers mismatch.\n")); exit(-1); } #endif exit(0); }
static AJ_Status ApplicationHandleDismiss(int32_t notificationId, const char* appId) { AJ_AlwaysPrintf(("******************** Begin New Dismiss Received ********************\n")); AJ_AlwaysPrintf(("Notification Id: %d\nApp Id: %s\n", notificationId, appId)); if (savedNotification.version > 0 && !strcmp(appId, savedNotification.appId) && notificationId == savedNotification.notificationId) { AJ_AlwaysPrintf(("Notification dimissed: Version %u sent from OriginalSender %s\n", savedNotification.version, savedNotification.originalSenderName)); if (processingAction == FALSE) { savedNotification.version = 0; } } AJ_AlwaysPrintf(("******************** End New Dismiss Received ********************\n")); return AJ_OK; }
AJ_Status NotificationConsumer_Init() { AJ_Status status = AJ_OK; Consumer_SetupEnv(&inputMode, &superAgentMode); AJ_AlwaysPrintf(("Init(): Set Consumer to detect SuperAgent option is turned %s\n", superAgentMode ? "ON" : "off")); status = AJNS_Consumer_Start(superAgentMode, &ApplicationHandleNotify, &ApplicationHandleDismiss); memset(&savedNotification, 0, sizeof(AJNS_Consumer_NotificationReference)); AJ_AlwaysPrintf(("\n---------------------\nNotification Consumer started!\n")); AJ_AlwaysPrintf(("DISMISS_DELAY_PERIOD: %u ms\n", DISMISS_DELAY_PERIOD)); AJ_AlwaysPrintf(("---------------------\n\n")); return status; }
void WSL_PrintScan(void) { int i; for (i = 0; i < list.size; i++) { AJ_AlwaysPrintf(("%-17.17s ", list.list[i].ssid)); AJ_AlwaysPrintf(("RSSI: %u ", list.list[i].rssi)); AJ_AlwaysPrintf(("BSSID: %02x:%02x:%02x:%02x:%02x:%02x\n", list.list[i].bssid[0], list.list[i].bssid[1], list.list[i].bssid[2], list.list[i].bssid[3], list.list[i].bssid[4], list.list[i].bssid[5])); } }
static void AppDoWork() { /* * This function is called if there are no messages to unmarshal */ AJ_AlwaysPrintf(("do work\n")); }
/* * This test builds a ping response in a simulated wire buffer, and then parses the response */ static void run_wsl_simulate_ping_recv(const struct test_case* test) { AJ_AlwaysPrintf(("\n\n**************\nTEST: %s\n\n", __FUNCTION__)); ResetFakeWireBuffers(); AJ_WSL_NET_ping_FAKERESPONSE(); AJ_WSL_HTC_ProcessIncoming(); }
AJ_Status OnboardingReadInfo(AJOBS_Info* info) { AJ_Status status = AJ_OK; size_t size = sizeof(AJOBS_Info); AJ_NV_DATASET* nvramHandle; int sizeRead; if (NULL == info) { return AJ_ERR_NULL; } memset(info, 0, size); if (!AJ_NVRAM_Exist(AJ_OBS_OBINFO_NV_ID)) { return AJ_ERR_INVALID; } nvramHandle = AJ_NVRAM_Open(AJ_OBS_OBINFO_NV_ID, "r", 0); if (nvramHandle != NULL) { sizeRead = AJ_NVRAM_Read(info, size, nvramHandle); status = AJ_NVRAM_Close(nvramHandle); if (sizeRead != sizeRead) { status = AJ_ERR_READ; } else { AJ_AlwaysPrintf(("Read Info values: state=%d, ssid=%s authType=%d pc=%s\n", info->state, info->ssid, info->authType, info->pc)); } } return status; }
AJ_Status AppHandleCat(AJ_Message* msg) { AJ_Status status = AJ_OK; AJ_Message reply; char* partA; char* partB; char* totalString; AJ_AlwaysPrintf(("%s:%d:%s %d\n", __FILE__, __LINE__, __FUNCTION__, 0)); AJ_UnmarshalArgs(msg, "ss", &partA, &partB); totalString = (char*) AJ_Malloc(strlen(partA) + strlen(partB) + 1); if (!totalString) { return AJ_ERR_RESOURCES; } strcpy(totalString, partA); strcpy(totalString + strlen(partA), partB); AJ_MarshalReplyMsg(msg, &reply); AJ_MarshalArgs(&reply, "s", totalString); status = AJ_DeliverMsg(&reply); AJ_Free(totalString); return status; }
void TestTimeConversion() { TS_Time time; TS_Date date; AJ_Time ajtime; uint8_t dow; const char* WEEKDAYS[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; ajtime.seconds = 1409262479; // Thu, 28 Aug 2014 21:47:59 GMT ajtime.milliseconds = 66; AJ_AlwaysPrintf(("epoch %u.%03u\n", ajtime.seconds, ajtime.milliseconds)); AJTime2TSDateTime(&ajtime, &date, &time); dow = TSDateTime2AJTime(&date, &time, &ajtime); AJ_AlwaysPrintf(("%s %02u/%02u/%02u %02u:%02u:%02u.%03u\n", WEEKDAYS[dow - 1], date.day, date.month, date.year, time.hour, time.minute, time.second, time.milliseconds)); AJ_AlwaysPrintf(("epoch %u.%03u\n", ajtime.seconds, ajtime.milliseconds)); }
static AJ_Status AuthListenerCallback(uint32_t authmechanism, uint32_t command, AJ_Credential* cred) { AJ_Status status = AJ_ERR_INVALID; AJ_AlwaysPrintf(("AuthListenerCallback authmechanism %08X command %d\n", authmechanism, command)); switch (authmechanism) { case AUTH_SUITE_ECDHE_NULL: cred->expiration = keyexpiration; status = AJ_OK; break; case AUTH_SUITE_ECDHE_PSK: switch (command) { case AJ_CRED_PUB_KEY: cred->data = (uint8_t*) psk_hint; cred->len = strlen(psk_hint); cred->expiration = keyexpiration; status = AJ_OK; break; case AJ_CRED_PRV_KEY: cred->data = (uint8_t*) psk_char; cred->len = strlen(psk_char); cred->expiration = keyexpiration; status = AJ_OK; break; } break; default: break; } return status; }
static void ScanResult(void* context, const char* ssid, const uint8_t mac[6], uint8_t rssi, AJ_WiFiSecurityType secType, AJ_WiFiCipherType cipherType) { static const char* const sec[] = { "OPEN", "WEP", "WPA", "WPA2" }; static const char* const typ[] = { "", ":TKIP", ":CCMP", ":WEP" }; AJ_AlwaysPrintf(("SSID %s [%02x:%02X:%02x:%02x:%02x:%02x] RSSI=%d security=%s%s\n", ssid, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], rssi, sec[secType], typ[cipherType])); }
void ram_diag() { AJ_AlwaysPrintf(("SRAM usage (stack, heap, static): %d, %d, %d\n", stack_used(), heap_used(), static_used())); }
static AJSVC_ServiceStatus AJApp_MessageProcessor(AJ_BusAttachment* busAttachment, AJ_Message* msg, AJ_Status* status) { AJSVC_ServiceStatus serviceStatus = AJSVC_SERVICE_STATUS_HANDLED; uint16_t port; char* joiner; uint32_t sessionId = 0; uint8_t session_accepted = FALSE; if (msg->msgId == AJ_METHOD_ACCEPT_SESSION) { // Process all incoming request to join a session and pass request for acceptance by all services *status = AJ_UnmarshalArgs(msg, "qus", &port, &sessionId, &joiner); if (*status != AJ_OK) { return serviceStatus; } session_accepted |= (port == AJ_ABOUT_SERVICE_PORT); session_accepted |= AJSVC_CheckSessionAccepted(port, sessionId, joiner); *status = AJ_BusReplyAcceptSession(msg, session_accepted); AJ_AlwaysPrintf(("%s session session_id=%u joiner=%s for port %u\n", (session_accepted ? "Accepted" : "Rejected"), sessionId, joiner, port)); } else { switch (currentServicesInitializationState) { case INIT_SERVICES_PORT: if (msg->msgId == AJ_REPLY_ID(AJ_METHOD_BIND_SESSION_PORT)) { currentServicesInitializationState = nextServicesInitializationState; } break; default: serviceStatus = AJSVC_MessageProcessorAndDispatcher(busAttachment, msg, status); break; } } return serviceStatus; }
static void run_buflist_external(const struct test_case* test) { uint8_t externA[10]; uint8_t externB[10]; /* * verify the buffer list management */ AJ_BufList* list1 = AJ_BufListCreate(); AJ_BufNode* pNode1 = AJ_BufListCreateNodeExternalBuffer((uint8_t*)&externA, sizeof(externA)); AJ_BufNode* pNode2 = AJ_BufListCreateNodeExternalBuffer((uint8_t*)&externB, sizeof(externB)); AJ_AlwaysPrintf(("\n\n**************\nTEST: %s\n\n", __FUNCTION__)); memset(pNode1->buffer, 0x1, pNode1->length); memset(pNode2->buffer, 0x2, pNode2->length); AJ_BufListPushHead(list1, pNode1); AJ_BufListPushTail(list1, pNode2); AJ_BufNodeIterate(AJ_BufListNodePrint, list1, NULL); AJ_BufNodeIterate(AJ_BufListNodePrintDump, list1, NULL); AJ_BufListFree(list1, 1); }
AJ_Status SendPing(AJ_BusAttachment* bus, uint32_t sessionId) { AJ_Status status; AJ_Message msg; AJ_AlwaysPrintf(("Sending ping request '%s'.\n", pingString)); status = AJ_MarshalMethodCall(bus, &msg, PRX_PING, fullServiceName, sessionId, AJ_FLAG_ENCRYPTED, METHOD_TIMEOUT); if (AJ_OK == status) { status = AJ_MarshalArgs(&msg, "s", pingString); } else { AJ_InfoPrintf(("In SendPing() AJ_MarshalMethodCall() status = %d.\n", status)); } if (AJ_OK == status) { status = AJ_DeliverMsg(&msg); } else { AJ_InfoPrintf(("In SendPing() AJ_MarshalArgs() status = %d.\n", status)); } if (AJ_OK != status) { AJ_InfoPrintf(("In SendPing() AJ_DeliverMsg() status = %d.\n", status)); } return status; }
static void PasswordGenerate() { #ifdef AJ_NO_CONSOLE /* If there is no console to read/write from/to. */ const char password[] = "107734"; /* Upside down this can be read as 'hELLO!'. */ const int maxPinSize = sizeof(pinStr) / sizeof(pinStr[0]) - 1; pinLength = sizeof(password) - 1; if (pinLength > maxPinSize) { pinLength = maxPinSize; } memcpy(pinStr, password, pinLength); pinStr[pinLength] = '\0'; #else int pin; /* seed the random number */ srand((unsigned int) time(NULL)); pin = 1000 * (rand() % 1000) + (rand() % 1000); sprintf(pinStr, "%06d", pin); AJ_AlwaysPrintf(("One Time Password : '******'.\n", pinStr)); pinLength = (uint32_t)strlen(pinStr); #endif }
AJ_Status NotificationConsumer_Init(AJ_Object* proxyObjects) { AJ_Status status = AJ_OK; Consumer_SetupEnv(&inputMode, &superAgentMode); AJ_AlwaysPrintf(("Init(): Set Consumer to detect SuperAgent option is turned %s\n", superAgentMode ? "ON" : "off")); status = AJNS_Consumer_Start(superAgentMode, proxyObjects, &ApplicationHandleNotify, &ApplicationHandleDismiss); memset(&savedNotification, 0, sizeof(AJNS_Consumer_NotificationReference)); return status; }
static void set_SPI_registers(void) { volatile uint16_t spi_API = 0; AJ_AlwaysPrintf(("\n\n**************\nTEST: %s\n\n", __FUNCTION__)); // reset the target // spi_API = (1 << 15); // AJ_WSL_SPI_RegisterWrite(AJ_WSL_SPI_REG_SPI_CONFIG, spi_API); // AJ_Sleep(1 << 22); // one extra write to force the device out of the reset state. spi_API = 0x80; AJ_WSL_SPI_RegisterWrite(AJ_WSL_SPI_REG_SPI_CONFIG, spi_API); AJ_Sleep(100); // write spi_API = 0x80; // same as capture AJ_WSL_SPI_RegisterWrite(AJ_WSL_SPI_REG_SPI_CONFIG, spi_API); // AJ_InfoPrintf(("AJ_WSL_SPI_REG_SPI_CONFIG was %04x\n", spi_API)); AJ_WSL_SPI_RegisterRead(AJ_WSL_SPI_REG_WRBUF_SPC_AVA, (uint8_t*)&spi_API); spi_API = LE16_TO_CPU(spi_API); AJ_InfoPrintf(("AJ_WSL_SPI_REG_WRBUF_SPC_AVA was %04x\n", spi_API)); spi_API = 0x40; // same as capture AJ_WSL_SPI_RegisterWrite(AJ_WSL_SPI_REG_WRBUF_WATERMARK, spi_API); // AJ_InfoPrintf(("AJ_WSL_SPI_REG_SPI_CONFIG was %04x\n", spi_API)); spi_API = 0x400; // same as capture AJ_WSL_SPI_RegisterWrite(AJ_WSL_SPI_REG_INTR_CAUSE, spi_API); AJ_InfoPrintf(("AJ_WSL_SPI_REG_INTR_CAUSE was %04x\n", spi_API)); spi_API = 0x3ff; AJ_WSL_SPI_RegisterWrite(AJ_WSL_SPI_REG_INTR_ENABLE, spi_API); AJ_InfoPrintf(("AJ_WSL_SPI_REG_INTR_ENABLE was %04x\n", spi_API)); spi_API = 0x0e; AJ_WSL_SPI_RegisterWrite(AJ_WSL_SPI_REG_INTR_ENABLE, spi_API); AJ_InfoPrintf(("AJ_WSL_SPI_REG_INTR_ENABLE was %04x\n", spi_API)); spi_API = 0x1e; AJ_WSL_SPI_RegisterWrite(AJ_WSL_SPI_REG_INTR_ENABLE, spi_API); AJ_InfoPrintf(("AJ_WSL_SPI_REG_INTR_ENABLE was %04x\n", spi_API)); spi_API = 0x0; AJ_WSL_SPI_RegisterWrite(AJ_WSL_SPI_REG_INTR_ENABLE, spi_API); AJ_InfoPrintf(("AJ_WSL_SPI_REG_INTR_ENABLE was %04x\n", spi_API)); spi_API = 0x1e; AJ_WSL_SPI_RegisterWrite(AJ_WSL_SPI_REG_INTR_ENABLE, spi_API); AJ_InfoPrintf(("AJ_WSL_SPI_REG_INTR_ENABLE was %04x\n", spi_API)); AJ_Sleep(100); }
AJ_Status AppHandleChatSignal(AJ_Message* msg) { AJ_Status status = AJ_OK; char* chatString; AJ_UnmarshalArgs(msg, "s", &chatString); AJ_AlwaysPrintf(("RX chat from %s[%u]: %s\n", msg->sender, msg->sessionId, chatString)); return status; }
void AJ_NVRAM_Init() { nvm_init(INT_FLASH); nvm_get_page_size(INT_FLASH, &AJ_NVRAM_PageSize); if (*((uint32_t*)AJ_NVRAM_BASE_ADDRESS) != AJ_NV_SENTINEL) { AJ_AlwaysPrintf(("Sentinel has not been set, clearing NVRAM\n")); _AJ_NVRAM_Clear(); } }
static uint8_t AcceptNewTestPeer(const char* peerName) { AJ_AlwaysPrintf(("AcceptNewTestPeer: name:%s\n", peerName)); if ((strcmp(g_peerServiceName, peerName) == 0)) { return TRUE; } return FALSE; }