/* * Handles a property GET request so marshals the property value to return */ AJ_Status AJOBS_PropGetHandler(AJ_Message* replyMsg, uint32_t propId, void* context) { AJ_Status status = AJ_OK; AJ_Arg structure; const AJOBS_Error* obError = AJOBS_GetError(); if (propId == OBS_VERSION_PROP) { status = AJ_MarshalArgs(replyMsg, "q", AJSVC_OnboardingVersion); } else if (propId == OBS_STATE_PROP) { status = AJ_MarshalArgs(replyMsg, "n", AJOBS_GetState()); } else if (propId == OBS_LASTERROR_PROP) { status = AJ_MarshalContainer(replyMsg, &structure, AJ_ARG_STRUCT); if (status != AJ_OK) { goto Exit; } status = AJ_MarshalArgs(replyMsg, "ns", obError->code, obError->message); if (status != AJ_OK) { goto Exit; } status = AJ_MarshalCloseContainer(replyMsg, &structure); } else { status = AJ_ERR_UNEXPECTED; } Exit: return status; }
AJ_Status AJS_AttachAllJoyn(AJ_BusAttachment* aj) { AJ_Status status; uint8_t isConnected = FALSE; uint32_t linkTO = LINK_TO; size_t sapSz; /* * Initialize the onboarding service */ sapSz = min(sizeof(obSettings.AJOBS_SoftAPSSID), sizeof(softAPSSID)); memcpy((char*)obSettings.AJOBS_SoftAPSSID, softAPSSID, sapSz); status = AJOBS_Start(&obSettings); if (status != AJ_OK) { goto Exit; } AJ_InfoPrintf(("Attempting to attach to AllJoyn\n")); while (!isConnected) { status = AJSVC_RoutingNodeConnect(aj, busNode, CONNECT_TO, CONNECT_PAUSE, linkTO, &isConnected); if (status != AJ_ERR_TIMEOUT) { break; } } if (isConnected) { status = AJS_ServicesInit(aj); if (status != AJ_OK) { AJ_ErrPrintf(("Failed to initialize services")); } } if (isConnected && (AJOBS_GetState() != AJOBS_STATE_CONFIGURED_VALIDATED)) { /* * Kick of onboarding */ status = AJ_BusBindSessionPort(aj, ONBOARDING_PORT, NULL, 0); /* * Allow onboarding service to run its course */ while (status == AJ_OK) { AJ_Message msg; status = AJ_UnmarshalMsg(aj, &msg, MSG_TO); if (status == AJ_ERR_NO_MATCH) { /* * Discard unknown messages */ status = AJ_CloseMsg(&msg); continue; } if (status == AJ_ERR_TIMEOUT) { /* * Check the link is still up */ status = AJ_BusLinkStateProc(aj); if (status == AJ_OK) { continue; } } if (status != AJ_OK) { break; } switch (msg.msgId) { case AJ_REPLY_ID(AJ_METHOD_BIND_SESSION_PORT): AJ_AboutInit(aj, ONBOARDING_PORT); break; case AJ_METHOD_ACCEPT_SESSION: /* * TODO - check that the port number is correct */ status = AJ_BusReplyAcceptSession(&msg, TRUE); if (status == AJ_OK) { status = AJOBS_ConnectedHandler(aj); } break; default: /* * Let the service message handlers have first dibs on the message */ status = AJS_ServicesMsgHandler(&msg); if (status == AJ_ERR_NO_MATCH) { /* * Pass the unhandled message to the standard bus handler */ status = AJ_BusHandleBusMessage(&msg); if (status == AJ_ERR_NO_MATCH) { AJ_ErrPrintf(("Discarding unhandled message\n")); status = AJ_OK; } } break; } /* * Let the link monitor know we are receiving messages */ AJ_NotifyLinkActive(); /* * Free resources used by the message */ AJ_CloseMsg(&msg); if (AJOBS_GetState() == AJOBS_STATE_CONFIGURED_VALIDATED) { AJ_InfoPrintf(("Onboarding completed\n")); break; } AJ_InfoPrintf(("Onboarding continuing\n")); } /* * If we got an error during onboarding we should restart */ if (status != AJ_OK) { status = AJ_ERR_RESTART; } } /* * If all went well let the services know we are connected */ if (isConnected && (status == AJ_OK)) { /* * Add match rules to subscribe to session related signals */ status = AJ_BusSetSignalRuleFlags(aj, sessionLostMatchRule, AJ_BUS_SIGNAL_ALLOW, AJ_FLAG_NO_REPLY_EXPECTED); if (status == AJ_OK) { status = AJSVC_ConnectedHandler(aj); } } Exit: return status; }