Ejemplo n.º 1
0
AJ_Status unmarshalTimePropertyValue(TimePropertyValue* timePropertyValue, AJ_Message* message)
{
    AJ_Status status;
    AJ_Arg outerStructArg, innerStructArg;
    uint16_t widgetType;

    status = AJ_UnmarshalContainer(message, &outerStructArg, AJ_ARG_STRUCT);
    if (status != AJ_OK) {
        return status;
    }
    status = AJ_UnmarshalArgs(message, "q", &widgetType);
    if (status != AJ_OK) {
        return status;
    }

    if (widgetType != TIME_PROPERTY) {
        return AJ_ERR_UNEXPECTED;
    }
    status = AJ_UnmarshalContainer(message, &innerStructArg, AJ_ARG_STRUCT);
    if (status != AJ_OK) {
        return status;
    }
    status = AJ_UnmarshalArgs(message, "qqq", &timePropertyValue->hour, &timePropertyValue->minute, &timePropertyValue->second);
    if (status != AJ_OK) {
        return status;
    }

    status = AJ_UnmarshalCloseContainer(message, &innerStructArg);
    if (status != AJ_OK) {
        return status;
    }
    return AJ_UnmarshalCloseContainer(message, &outerStructArg);
}
Ejemplo n.º 2
0
AJ_Status unmarshalDatePropertyValue(DatePropertyValue* datePropertyValue, AJ_Message* message)
{
    AJ_Status status;
    AJ_Arg outerStructArg, innerStructArg;
    uint16_t widgetType;

    status = AJ_UnmarshalContainer(message, &outerStructArg, AJ_ARG_STRUCT);
    if (status != AJ_OK) {
        return status;
    }
    status = AJ_UnmarshalArgs(message, "q", &widgetType);
    if (status != AJ_OK) {
        return status;
    }

    if (widgetType != DATE_PROPERTY) {
        return AJ_ERR_UNEXPECTED;
    }
    status = AJ_UnmarshalContainer(message, &innerStructArg, AJ_ARG_STRUCT);
    if (status != AJ_OK) {
        return status;
    }
    status = AJ_UnmarshalArgs(message, "qqq", &datePropertyValue->mDay, &datePropertyValue->month, &datePropertyValue->fullYear);
    if (status != AJ_OK) {
        return status;
    }

    status = AJ_UnmarshalCloseContainer(message, &innerStructArg);
    if (status != AJ_OK) {
        return status;
    }
    return AJ_UnmarshalCloseContainer(message, &outerStructArg);
}
Ejemplo n.º 3
0
AJ_Status AJS_UnmarshalPropArgs(duk_context* ctx, AJ_Message* msg, uint8_t accessor, duk_idx_t msgIdx)
{
    AJ_Status status;
    const char* iface;
    const char* prop;
    const char* signature;
    uint32_t propId;
    uint8_t secure = FALSE;

    AJ_InfoPrintf(("PushPropArgs\n"));

    if (accessor == AJ_PROP_GET_ALL) {
        status = AJ_UnmarshalArgs(msg, "s", &iface);
        if (status == AJ_OK) {
            duk_push_string(ctx, iface);
            /*
             * Save interface (read-only) so we know how to marshal the reply values
             */
            duk_push_string(ctx, AJS_HIDDEN_PROP("propIface"));
            duk_dup(ctx, -2);
            duk_def_prop(ctx, msgIdx, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE);
        }
        /*
         * This call always returns an error status because the interface name we are passing in is
         * invalid but it will indicate if security is required so we can perform the check below
         */
        AJ_IdentifyProperty(msg, iface, "", &propId, &signature, &secure);
    } else {
        status = AJ_UnmarshalArgs(msg, "ss", &iface, &prop);
        if (status == AJ_OK) {
            status = AJ_IdentifyProperty(msg, iface, prop, &propId, &signature, &secure);
            if (status == AJ_OK) {
                duk_push_string(ctx, iface);
                duk_push_string(ctx, prop);
                if (accessor == AJ_PROP_GET) {
                    /*
                     * If we are getting a property save the signature so we know how to marshal the
                     * value in the reply.
                     */
                    duk_push_string(ctx, AJS_HIDDEN_PROP("propSig"));
                    duk_push_string(ctx, signature);
                    duk_def_prop(ctx, msgIdx, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE);
                } else {
                    /*
                     * Push the value to set
                     */
                    status = PushArg(ctx, msg);
                }
            }
        }
    }
    /*
     * If the interface is secure check the message is encrypted
     */
    if ((status == AJ_OK) && secure && !(msg->hdr->flags & AJ_FLAG_ENCRYPTED)) {
        status = AJ_ERR_SECURITY;
        AJ_WarnPrintf(("Security violation accessing property\n"));
    }
    return status;
}
Ejemplo n.º 4
0
uint8_t isControlPanelAnnounce(AJ_Message* msg)
{
    AJ_Status status = AJ_OK;
    AJ_Arg array1, array2, struct1;
    uint16_t uint1, uint2;
    char* buffer;

    status = AJ_UnmarshalArgs(msg, "q", &uint1);
    if (status != AJ_OK) {
        return FALSE;
    }

    status = AJ_UnmarshalArgs(msg, "q", &uint2);
    if (status != AJ_OK) {
        return FALSE;
    }
    status = AJ_UnmarshalContainer(msg, &array1, AJ_ARG_ARRAY);
    if (status != AJ_OK) {
        return FALSE;
    }
    do {
        status = AJ_UnmarshalContainer(msg, &struct1, AJ_ARG_STRUCT);
        if (status != AJ_OK) {
            return FALSE;
        }
        status = AJ_UnmarshalArgs(msg, "o", &buffer);
        if (status != AJ_OK) {
            return FALSE;
        }

        status = AJ_UnmarshalContainer(msg, &array2, AJ_ARG_ARRAY);
        if (status != AJ_OK) {
            return FALSE;
        }
        do {
            if ((status = AJ_UnmarshalArgs(msg, "s", &buffer)) != AJ_OK) {
                if (status == AJ_ERR_NO_MORE) {
                    break;
                } else {
                    return FALSE;
                }
            }
            if (strcmp(buffer, "org.alljoyn.ControlPanel.ControlPanel") == 0) {
                return TRUE;
            }
        } while (1);
        status = AJ_UnmarshalCloseContainer(msg, &array2);
        if (status != AJ_OK) {
            break;
        }
        status = AJ_UnmarshalCloseContainer(msg, &struct1);
        if (status != AJ_OK) {
            break;
        }
    } while (1);
    return FALSE;
}
Ejemplo n.º 5
0
static AJ_Status SessionBindReply(duk_context* ctx, AJ_Message* msg)
{
    AJ_Status status;
    uint32_t result;
    uint16_t port;
    uint8_t ldstate;

    status = AJ_UnmarshalArgs(msg, "uq", &result, &port);
    if (status != AJ_OK) {
        return status;
    }
    if (port != AJS_APP_PORT) {
        AJ_ResetArgs(msg);
#if !defined(AJS_CONSOLE_LOCKDOWN)
        status = AJS_GetLockdownState(&ldstate);
        if (status == AJ_OK && ldstate == AJS_CONSOLE_UNLOCKED) {
            status = AJS_ConsoleMsgHandler(ctx, msg);
        }
#endif
        if (status == AJ_ERR_NO_MATCH) {
            status = AJS_ServicesMsgHandler(msg);
            if (status == AJ_ERR_NO_MATCH) {
                status = AJ_OK;
            }
        }
    }
    return status;
}
Ejemplo n.º 6
0
static AJ_Status AppHandleCat(AJ_Message* msg)
{
#define BUFFER_SIZE 256
    const char* string0;
    const char* string1;
    char buffer[BUFFER_SIZE];
    AJ_Message reply;
    AJ_Arg replyArg;

    AJ_UnmarshalArgs(msg, "ss", &string0, &string1);
    AJ_MarshalReplyMsg(msg, &reply);

    /* We have the arguments. Now do the concatenation. */
    strncpy(buffer, string0, BUFFER_SIZE);
    buffer[BUFFER_SIZE - 1] = '\0';
    strncat(buffer, string1, BUFFER_SIZE - strlen(buffer));
    buffer[BUFFER_SIZE - 1] = '\0';

    AJ_InitArg(&replyArg, AJ_ARG_STRING, 0, buffer, 0);
    AJ_MarshalArg(&reply, &replyArg);

    return AJ_DeliverMsg(&reply);

#undef BUFFER_SIZE
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
AJ_Status AJCFG_GetConfigurationsHandler(AJ_Message* msg)
{
    AJ_Status status = AJ_OK;
    AJ_Message reply;
    char* language;
    int8_t langIndex = AJSVC_PROPERTY_STORE_ERROR_LANGUAGE_INDEX;
    AJSVC_PropertyStoreCategoryFilter filter;

    AJ_InfoPrintf(("Handling GetConfigurations request\n"));

    memset(&filter, 0, sizeof(AJSVC_PropertyStoreCategoryFilter));
    filter.bit1Config = TRUE;
    status = AJ_UnmarshalArgs(msg, "s", &language);
    if (status != AJ_OK) {
        return status;
    }
    if (AJSVC_IsLanguageSupported(msg, &reply, language, &langIndex)) {
        status = AJ_MarshalReplyMsg(msg, &reply);
        if (status != AJ_OK) {
            return status;
        }
        status = AJSVC_PropertyStore_ReadAll(&reply, filter, langIndex);
        if (status != AJ_OK) {
            return status;
        }
    }
    status = AJ_DeliverMsg(&reply);
    if (status != AJ_OK) {
        return status;
    }

    return status;
}
Ejemplo n.º 9
0
AJ_Status AJSUSI_VgaGetBacklightBrightness_Handler(AJ_Message* msg)
{
    AJ_Status status = AJ_OK;
    AJ_Message reply;
    AJ_Arg replyArg;
    uint32_t id, bright;

    //Get Args
    status = AJ_UnmarshalArgs(msg, "u", &id);
    if (status != AJ_OK) {
        return status;
    }
    AJ_InfoPrintf(("%s : id=%d\n", __func__, id));

    //SUSI API
    if (AJ_SusiVgaGetBacklightBrightness(id, &bright)) {
        AJ_MarshalErrorMsg(msg, &reply, AJ_ErrFeatureNotAvailable);
        return AJ_DeliverMsg(&reply);
    }

    //Status Reply
    AJ_InfoPrintf(("%s : ret=0x%x\n", __func__, bright));
    AJ_InitArg(&replyArg, AJ_ARG_UINT32, 0, &bright, 0);
    return SendReplyMsg(msg, &replyArg);
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
AJ_Status AJNS_Consumer_DismissSignalHandler(AJ_Message* msg)
{
    AJ_Status status;
    uint32_t notificationId = 0;
    char appId[UUID_LENGTH * 2 + 1];

    status = AJ_UnmarshalArgs(msg, "i", &notificationId);
    if (status != AJ_OK) {
        goto Exit;
    }

    status = AJSVC_UnmarshalAppId(msg, appId, sizeof(appId));
    if (status != AJ_OK) {
        goto Exit;
    }

    if (appOnDismiss) {
        (*appOnDismiss)(notificationId, appId);
    }

Exit:

    AJ_CloseMsg(msg);

    return status;
}
Ejemplo n.º 12
0
int UnmarshalPort() {
	uint16_t port;
	char* joiner;
	uint32_t sessionId;

	AJ_UnmarshalArgs(&c_message, "qus", &port, &sessionId, &joiner);
	return port;
}
Ejemplo n.º 13
0
/*
 * Handles a property SET request so unmarshals the property value to apply.
 */
static AJ_Status PropSetHandler(AJ_Message* replyMsg, uint32_t propId, void* context)
{
    if (propId == APP_INT_VAL_PROP) {
        return AJ_UnmarshalArgs(replyMsg, "i", &propVal);
    } else {
        return AJ_ERR_UNEXPECTED;
    }
}
Ejemplo n.º 14
0
AJ_Status AJS_SessionLost(duk_context* ctx, AJ_Message* msg)
{
    uint32_t sessionId;
    AJ_UnmarshalArgs(msg, "u", &sessionId);

    AJ_InfoPrintf(("AJS_SessionLost(): Removing session: %u\n", sessionId));
    return RemoveSessions(ctx, sessionId);
}
Ejemplo n.º 15
0
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;
}
Ejemplo n.º 16
0
AJ_Status AJCFG_SetPasscodeHandler(AJ_Message* msg)
{
    AJ_Status status = AJ_OK;
    char* daemonRealm;
    AJ_Arg newPasscode;
    AJ_Message reply;
    uint8_t forceRoutingNodeDisconnect = FALSE;
    uint8_t errorReply = FALSE;

    AJ_InfoPrintf(("Handling SetPasscode request\n"));

    status = AJ_UnmarshalArgs(msg, "s", &daemonRealm);
    if (status != AJ_OK) {
        return status;
    }
    AJ_InfoPrintf(("Realm=%s\n", daemonRealm));
    status = AJ_UnmarshalArg(msg, &newPasscode);
    if (status != AJ_OK) {
        return status;
    }
    AJ_InfoPrintf(("Passcode=%d bytes long\n", newPasscode.len));
    if (newPasscode.len > 0) { // Check passcode is not empty
        if (AppSetPasscode) {
            status = (AppSetPasscode)(daemonRealm, (const uint8_t*)newPasscode.val.v_string, (uint8_t)newPasscode.len);
            if (status == AJ_ERR_RESOURCES) { // Check passcode is too long to persist
                status = AJ_MarshalErrorMsg(msg, &reply, AJSVC_ERROR_MAX_SIZE_EXCEEDED);
                if (status != AJ_OK) {
                    return status;
                }
                errorReply = TRUE;
            }
            forceRoutingNodeDisconnect = (status == AJ_ERR_READ);
        }
    } else {
        AJ_ErrPrintf(("Error - newPasscode cannot be empty!\n"));
        status = AJ_MarshalErrorMsg(msg, &reply, AJSVC_ERROR_INVALID_VALUE);
        if (status != AJ_OK) {
            return status;
        }
        errorReply = TRUE;
    }
    if (!errorReply) {
        status = AJ_MarshalReplyMsg(msg, &reply);
        if (status != AJ_OK) {
            return status;
        }
    }
    status = AJ_DeliverMsg(&reply);

    if (forceRoutingNodeDisconnect) {
        return AJ_ERR_READ;
    }
    return status;
}
Ejemplo n.º 17
0
AJ_Status AJ_PeerHandleGenSessionKeyReply(AJ_Message* msg)
{
    AJ_Status status;
    /*
     * For 12 bytes of verifier, we need at least 12 * 2 characters
     * to store its representation in hex (24 octets + 1 octet for \0).
     * However, the KeyGen function demands a bigger buffer
     * (to store 16 bytes key in addition to the 12 bytes verifier).
     * Hence we allocate, the maximum of (12 * 2 + 1) and (16 + 12).
     */
    char verifier[VERIFIER_LEN + AES_KEY_LEN];
    char* nonce;
    char* remVerifier;

    /*
     * Check we are in an auth conversation with the sender
     */
    status = CheckAuthPeer(msg);
    if (status != AJ_OK) {
        return status;
    }
    if (msg->hdr->msgType == AJ_MSG_ERROR) {
        status = AJ_ERR_SECURITY;
    } else {
        AJ_UnmarshalArgs(msg, "ss", &nonce, &remVerifier);
        status = KeyGen(msg->sender, AJ_ROLE_KEY_INITIATOR, authContext.nonce, nonce, (uint8_t*)verifier, sizeof(verifier));
        if (status == AJ_OK) {
            /*
             * Check verifier strings match as expected
             */
            if (strcmp(remVerifier, verifier) != 0) {
                status = AJ_ERR_SECURITY;
            }
        }
        if (status == AJ_OK) {
            AJ_Arg key;
            AJ_Message call;
            uint8_t groupKey[AES_KEY_LEN];
            /*
             * Group keys are exchanged via an encrypted message
             */
            AJ_MarshalMethodCall(msg->bus, &call, AJ_METHOD_EXCHANGE_GROUP_KEYS, msg->sender, 0, AJ_FLAG_ENCRYPTED, CALL_TIMEOUT);
            AJ_GetGroupKey(NULL, groupKey);
            AJ_MarshalArg(&call, AJ_InitArg(&key, AJ_ARG_BYTE, AJ_ARRAY_FLAG, groupKey, sizeof(groupKey)));
            status = AJ_DeliverMsg(&call);
        }
    }
    if (status != AJ_OK) {
        PeerAuthComplete(status);
    }
    return AJ_OK;
}
Ejemplo n.º 18
0
static AJ_Status AppHandleFlash(AJ_Message* msg)
{
    AJ_Message reply;
    uint32_t timeout;
    AJ_UnmarshalArgs(msg, "u", &timeout);
    AJ_AlwaysPrintf(("AppHandleFlash(%u)\n", timeout));

    DUE_led_timed(timeout);


    AJ_MarshalReplyMsg(msg, &reply);
    return AJ_DeliverMsg(&reply);
}
Ejemplo n.º 19
0
AJ_Status AJ_GUID_HandleNameOwnerChanged(AJ_Message* msg)
{
    AJ_Status status;
    char* name;
    char* oldOwner;
    char* newOwner;

    status = AJ_UnmarshalArgs(msg, "sss", &name, &oldOwner, &newOwner);
 //   AJ_InfoPrintf(("AJ_GUID_HandleNameOwnerChanged(name=%s,oldOwner=%s,newOwner=%s)\n", name, oldOwner, newOwner));
    if ((status == AJ_OK) && newOwner && oldOwner && newOwner[0] == '\0') 
	{
        AJ_GUID_DeleteNameMapping(msg->bus, oldOwner);
    }
    return status;
}
Ejemplo n.º 20
0
static AJ_Status SetName(AJ_Message* replyMsg, uint32_t propId, void* context)
{
    AJ_Status status = AJ_ERR_UNEXPECTED;

    if (propId == BASIC_SIGNAL_SERVICE_NAME_ID) {
        char*string;
        AJ_UnmarshalArgs(replyMsg, "s", &string);
        strncpy(propertyName, string, propertyNameSize);
        propertyName[propertyNameSize - 1] = '\0';
        AJ_AlwaysPrintf(("Set 'name' property was called changing name to '%s'.\n", propertyName));
        status = AJ_OK;
    }

    return status;
}
AJ_Status unmarshalPropertyValue(PropertyWidget* widget, AJ_Message* message, void* newValue, const char* lockerId)
{
    AJ_Status status = AJ_ERR_UNEXPECTED;

    switch (widget->propertyType) {
    case SINGLE_VALUE_PROPERTY:
        return AJ_UnmarshalArgs(message, widget->signature, newValue);

    case DATE_VALUE_PROPERTY:
        return unmarshalDatePropertyValue(newValue, message);

    case TIME_VALUE_PROPERTY:
        return unmarshalTimePropertyValue(newValue, message);
    }
    return status;
}
Ejemplo n.º 22
0
static AJ_Status SessionDispatcher(duk_context* ctx, AJ_Message* msg)
{
    AJ_Status status;
    uint32_t sessionId;
    uint16_t port;
    char* joiner;
    uint8_t ldstate;

    status = AJ_UnmarshalArgs(msg, "qus", &port, &sessionId, &joiner);
    if (status != AJ_OK) {
        return status;
    }
    /*
     * Automatically accept sessions requests to the application port
     */
    if (port == AJS_APP_PORT) {
        return AJS_HandleAcceptSession(ctx, msg, port, sessionId, joiner);
    }
    /*
     * See if this is the control panel port
     */
    if (AJCPS_CheckSessionAccepted(port, sessionId, joiner)) {
        return AJ_BusReplyAcceptSession(msg, TRUE);
    }
    status = AJ_ResetArgs(msg);
    if (status != AJ_OK) {
        return status;
    }
    /*
     * JavaScript doesn't accept/reject session so the session is either for the console or perhaps
     * a service if the services bind their own ports.
     */
#if !defined(AJS_CONSOLE_LOCKDOWN)
    status = AJS_GetLockdownState(&ldstate);
    if (status == AJ_OK && ldstate == AJS_CONSOLE_UNLOCKED) {
        status = AJS_ConsoleMsgHandler(ctx, msg);
    }
#endif
    if (status == AJ_ERR_NO_MATCH) {
        status = AJS_ServicesMsgHandler(msg);
    }
    if (status == AJ_ERR_NO_MATCH) {
        AJ_ErrPrintf(("SessionDispatcher rejecting attempt to join unbound port %d\n", port));
        status = AJ_BusReplyAcceptSession(msg, FALSE);
    }
    return status;
}
Ejemplo n.º 23
0
AJ_Status AJS_HandleJoinSessionReply(duk_context* ctx, AJ_Message* msg)
{
    const char* peer = NULL;
    SessionInfo* sessionInfo = NULL;
    uint32_t replySerial = msg->replySerial;
    uint8_t joined = FALSE;

    AJS_GetGlobalStashObject(ctx, "sessions");
    duk_enum(ctx, -1, DUK_ENUM_OWN_PROPERTIES_ONLY);
    while (duk_next(ctx, -1, 1)) {
        peer = duk_get_string(ctx, -2);
        AJ_ASSERT(duk_is_object(ctx, -1));
        duk_get_prop_string(ctx, -1, "info");
        sessionInfo = duk_get_buffer(ctx, -1, NULL);
        AJ_ASSERT(sessionInfo);
        duk_pop_3(ctx);
        if (sessionInfo->replySerial == replySerial) {
            uint32_t sessionId;
            uint32_t replyStatus;
            /*
             * Check if the join was successful
             */
            AJ_UnmarshalArgs(msg, "uu", &replyStatus, &sessionId);
            if (replyStatus == AJ_JOINSESSION_REPLY_SUCCESS) {
                /*
                 * TODO - if we have a well-known name send a ping to get the unique name
                 */
                sessionInfo->sessionId = sessionId;
                joined = TRUE;
            }
            sessionInfo->replySerial = 0;
            break;
        }
    }
    duk_pop(ctx); /* Pop the enum */
    if (joined) {
        /*
         * TODO - we may need to initiate authentication with the remote peer
         */
        AnnouncementCallbacks(ctx, peer, sessionInfo);
    }
    /* Pop "sessions" */
    duk_pop(ctx);
    return AJ_OK;
}
AJ_Status AJNS_Producer_DismissRequestHandler(AJ_BusAttachment* busAttachment, AJ_Message* msg)
{
    AJ_Status status;
    int32_t notificationId;
    const char* appId;
    AJ_Message reply;

   // AJ_InfoPrintf(("In DismissMsg\n"));
    status = AJ_UnmarshalArgs(msg, "i", &notificationId);
    if (status != AJ_OK) 
	{
        AJ_ErrPrintf(("Could not unmarshal message\n"));
        return status;
    }

    status = AJ_MarshalReplyMsg(msg, &reply);
    if (status != AJ_OK) 
	{
        return status;
    }

    status = AJ_DeliverMsg(&reply);
    if (status != AJ_OK)
	 {
        return status;
    }

    appId = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_APP_ID);
    status = AJNS_SendDismissSignal(busAttachment, notificationId, appId);
    if (status != AJ_OK) 
	{
        return status;
    }

    status = AJNS_Producer_CancelNotificationById(busAttachment, notificationId);
    if (status != AJ_OK) 
	{
        return status;
    }

 //   AJ_InfoPrintf(("***************** Message with Notification id %d dismissed successfully *****************\n", notificationId));

    return status;
}
Ejemplo n.º 25
0
AJ_Status AJ_PeerHandleExchangeGUIDs(AJ_Message* msg, AJ_Message* reply)
{
    char guidStr[33];
    uint32_t version;
    char* str;
    AJ_GUID remoteGuid;
    AJ_GUID localGuid;

    AJ_UnmarshalArgs(msg, "su", &str, &version);
    AJ_GUID_FromString(&remoteGuid, str);
    AJ_GUID_AddNameMapping(&remoteGuid, msg->sender, NULL);
    /*
     * We are not currently negotiating versions so we tell the peer what version we require.
     */
    version = REQUIRED_AUTH_VERSION;
    AJ_MarshalReplyMsg(msg, reply);
    AJ_GetLocalGUID(&localGuid);
    AJ_GUID_ToString(&localGuid, guidStr, sizeof(guidStr));
    return AJ_MarshalArgs(reply, "su", guidStr, version);
}
Ejemplo n.º 26
0
static AJ_Status PropAccessAll(AJ_Message* msg, PropCallback* cb)
{
    AJ_Status status;
    AJ_Message reply;
    const char* iface;

    AJ_InfoPrintf(("PropAccessAll(msg=0x%p, cb=0x%p)\n", msg, cb));

    status = AJ_UnmarshalArgs(msg, "s", &iface);
    if (status == AJ_OK) {
        status = AJ_MarshalReplyMsg(msg, &reply);
    }
    if (status == AJ_OK) {
        status = AJ_MarshalAllPropertiesArgs(&reply, iface, cb->Get, cb->context);
    }
    if (status != AJ_OK) {
        AJ_MarshalStatusMsg(msg, &reply, status);
    }
    return AJ_DeliverMsg(&reply);
}
Ejemplo n.º 27
0
AJ_Status AJ_PeerHandleGenSessionKey(AJ_Message* msg, AJ_Message* reply)
{
    AJ_Status status;
    char* remGuid;
    char* locGuid;
    char* nonce;
    AJ_GUID guid;
    AJ_GUID localGuid;
    /*
     * For 12 bytes of verifier, we need at least 12 * 2 characters
     * to store its representation in hex (24 octets + 1 octet for \0).
     * However, the KeyGen function demands a bigger buffer
     * (to store 16 bytes key in addition to the 12 bytes verifier).
     * Hence we allocate, the maximum of (12 * 2 + 1) and (16 + 12).
     */
    char verifier[AES_KEY_LEN + VERIFIER_LEN];

    /*
     * Remote peer GUID, Local peer GUID and Remote peer's nonce
     */
    AJ_UnmarshalArgs(msg, "sss", &remGuid, &locGuid, &nonce);
    /*
     * We expect arg[1] to be the local GUID
     */
    status = AJ_GUID_FromString(&guid, locGuid);
    if (AJ_OK == status) {
        status = AJ_GetLocalGUID(&localGuid);
    }
    if ((status != AJ_OK) || (memcmp(&guid, &localGuid, sizeof(AJ_GUID)) != 0)) {
        return AJ_MarshalErrorMsg(msg, reply, AJ_ErrRejected);
    }
    AJ_RandHex(authContext.nonce, sizeof(authContext.nonce), NONCE_LEN);
    status = KeyGen(msg->sender, AJ_ROLE_KEY_RESPONDER, nonce, authContext.nonce, (uint8_t*)verifier, sizeof(verifier));
    if (status == AJ_OK) {
        AJ_MarshalReplyMsg(msg, reply);
        status = AJ_MarshalArgs(reply, "ss", authContext.nonce, verifier);
    } else {
        status = AJ_MarshalErrorMsg(msg, reply, AJ_ErrRejected);
    }
    return status;
}
Ejemplo n.º 28
0
AJ_Status AJSUSI_VgaSetBacklightEnable_Handler(AJ_Message* msg)
{
    AJ_Status status = AJ_OK;
    AJ_Message reply;
    uint32_t id, enable;

    //Get Args
    status = AJ_UnmarshalArgs(msg, "uu", &id, &enable);
    if (status != AJ_OK) {
        return status;
    }
    AJ_InfoPrintf(("%s : id=%d, enable=%d\n", __func__, id, enable));

    //SUSI API
    if (AJ_SusiVgaSetBacklightEnable(id, enable)) {
        AJ_MarshalErrorMsg(msg, &reply, AJ_ErrFeatureNotAvailable);
        return AJ_DeliverMsg(&reply);
    }

    //Status Reply
    return SendReplyMsg(msg, NULL);
}
Ejemplo n.º 29
0
AJ_Status AJ_PeerHandleExchangeGUIDsReply(AJ_Message* msg)
{
    AJ_Status status;
    const char* guidStr;
    AJ_GUID remoteGuid;
    uint32_t version;
    char nul = '\0';

    status = AJ_UnmarshalArgs(msg, "su", &guidStr, &version);
    if (status != AJ_OK) {
        return status;
    }
    if (version != REQUIRED_AUTH_VERSION) {
        PeerAuthComplete(AJ_ERR_SECURITY);
        return AJ_OK;
    }
    AJ_GUID_FromString(&remoteGuid, guidStr);
    /*
     * Two name mappings to add, the well known name, and the unique name from the message.
     */
    AJ_GUID_AddNameMapping(&remoteGuid, msg->sender, authContext.peerName);
    /*
     * Remember which peer is being authenticated
     */
    authContext.peerGuid = AJ_GUID_Find(msg->sender);
    /*
     * Initialize SASL state machine
     */
    AJ_SASL_InitContext(&authContext.sasl, authMechanisms, AJ_AUTH_RESPONDER, msg->bus->pwdCallback);
    /*
     * Start the authentication conversation
     */
    status = AuthResponse(msg, &nul);
    if (status != AJ_OK) {
        PeerAuthComplete(status);
    }
    return status;
}
Ejemplo n.º 30
0
AJ_Status AJ_GUID_HandleNameHasOwnerReply(AJ_Message* msg)
{
    AJ_Status status;
    NameToGUID* mapping;
    uint32_t hasOwner;

  //  AJ_InfoPrintf(("AJ_GUID_HandleNameHasOwnerReply(msg=0x%p)\n", msg));
    mapping = LookupReplySerial(msg->replySerial);
    if (!mapping) 
	{
        return AJ_OK;
    }
    mapping->replySerial = 0;

    if (msg->hdr->msgType == AJ_MSG_ERROR) 
	{
        AJ_ErrPrintf(("AJ_GUID_HandleNameHasOwnerReply(msg=0x%p): error=%s.\n", msg, msg->error));
        status = AJ_ERR_FAILURE;
        AJ_GUID_DeleteNameMapping(msg->bus, mapping->uniqueName);
        return status;
    }
    status = AJ_UnmarshalArgs(msg, "b", &hasOwner);
    if (status != AJ_OK) 
	{
        AJ_ErrPrintf(("AJ_GUID_HandleNameHasOwnerReply(msg=0x%p): Unmarshal error\n", msg));
        AJ_GUID_DeleteNameMapping(msg->bus, mapping->uniqueName);
        return status;
    }

    // Name has owner complete.
 //   AJ_InfoPrintf(("Name %s has owner %d\n", mapping->uniqueName, hasOwner));
    if (!hasOwner) 
	{
        AJ_GUID_DeleteNameMapping(msg->bus, mapping->uniqueName);
    }

    return status;
}