示例#1
0
static void InitMandatoryPropertiesInRAM()
{
    char* machineIdValue = propertyStoreRuntimeValues[AJSVC_PROPERTY_STORE_APP_ID].value[AJSVC_PROPERTY_STORE_NO_LANGUAGE_INDEX];
    const char* currentAppIdValue = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_APP_ID);
    const char* currentDeviceIdValue = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_DEVICE_ID);
    const char* currentDeviceNameValue = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_DEVICE_NAME);
    size_t serialIdLen = 0;
    size_t machineIdLen = 0;
    AJ_GUID theAJ_GUID;
    AJ_Status status;
    char deviceName[DEVICE_NAME_VALUE_LENGTH + 1] = { 0 };
    if (currentAppIdValue == NULL || currentAppIdValue[0] == '\0') {
        status = AJ_GetLocalGUID(&theAJ_GUID);
        if (status == AJ_OK) {
            AJ_GUID_ToString(&theAJ_GUID, machineIdValue, propertyStoreRuntimeValues[AJSVC_PROPERTY_STORE_APP_ID].size);
        }
    }
    if (currentDeviceIdValue == NULL || currentDeviceIdValue[0] == '\0') {
        AJSVC_PropertyStore_SetValue(AJSVC_PROPERTY_STORE_DEVICE_ID, machineIdValue);
    }
    if (currentDeviceNameValue == NULL || currentDeviceNameValue[0] == '\0') {
#ifdef ONBOARDING_SERVICE
        serialIdLen = AJOBS_DEVICE_SERIAL_ID_LEN;
#else
        serialIdLen = 7;
#endif
        machineIdLen = strlen(machineIdValue);
#ifdef _WIN32
        _snprintf(deviceName, DEVICE_NAME_VALUE_LENGTH + 1, "%s %s %s", deviceManufactureName, deviceProductName, &machineIdValue[machineIdLen - min(serialIdLen, machineIdLen)]);
#else
        snprintf(deviceName, DEVICE_NAME_VALUE_LENGTH + 1, "%s %s %s", deviceManufactureName, deviceProductName, &machineIdValue[machineIdLen - min(serialIdLen, machineIdLen)]);
#endif
        AJSVC_PropertyStore_SetValue(AJSVC_PROPERTY_STORE_DEVICE_NAME, deviceName);
    }
}
示例#2
0
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 const char* GenerateSoftAPSSID(char* obSoftAPssid)
{
    const char* deviceId;
    size_t deviceIdLen;
    char manufacture[AJOBS_DEVICE_MANUFACTURE_NAME_LEN + 1] = { 0 };
    size_t manufacureLen;
    char product[AJOBS_DEVICE_PRODUCT_NAME_LEN + 1] = { 0 };
    size_t productLen;
    char serialId[AJOBS_DEVICE_SERIAL_ID_LEN + 1] = { 0 };
    size_t serialIdLen;

    if (obSoftAPssid[0] == '\0') {
        deviceId = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_DEVICE_ID);
        deviceIdLen = strlen(deviceId);
        manufacureLen = min(strlen(deviceManufactureName), AJOBS_DEVICE_MANUFACTURE_NAME_LEN);
        productLen = min(strlen(deviceProductName), AJOBS_DEVICE_PRODUCT_NAME_LEN);
        serialIdLen = min(deviceIdLen, AJOBS_DEVICE_SERIAL_ID_LEN);
        memcpy(manufacture, deviceManufactureName, manufacureLen);
        manufacture[manufacureLen] = '\0';
        memcpy(product, deviceProductName, productLen);
        product[productLen] = '\0';
        memcpy(serialId, deviceId + (deviceIdLen - serialIdLen), serialIdLen);
        serialId[serialIdLen] = '\0';
#ifdef _WIN32
        _snprintf(obSoftAPssid, AJOBS_SSID_MAX_LENGTH + 1, "AJ_%s_%s_%s", manufacture, product, serialId);
#else
        snprintf(obSoftAPssid, AJOBS_SSID_MAX_LENGTH + 1, "AJ_%s_%s_%s", manufacture, product, serialId);
#endif
    }

    return obSoftAPssid;
}
示例#4
0
int8_t AJSVC_PropertyStore_GetCurrentDefaultLanguageIndex()
{
    const char* currentDefaultLanguage = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_DEFAULT_LANGUAGE);
    int8_t currentDefaultLanguageIndex = AJSVC_PropertyStore_GetLanguageIndex(currentDefaultLanguage);
    if (currentDefaultLanguageIndex == AJSVC_PROPERTY_STORE_ERROR_LANGUAGE_INDEX) {
        currentDefaultLanguageIndex = AJSVC_PROPERTY_STORE_NO_LANGUAGE_INDEX;
        AJ_WarnPrintf(("Failed to find default language %s defaulting to %s", (currentDefaultLanguage != NULL ? currentDefaultLanguage : "NULL"), propertyStoreDefaultLanguages[AJSVC_PROPERTY_STORE_NO_LANGUAGE_INDEX]));
    }
    return currentDefaultLanguageIndex;
}
示例#5
0
static const char* GenerateSoftAPSSID(char* obSoftAPssid)
{
    AJ_InfoPrintf(("\n%s\n", __func__));
    const char* deviceId;
    size_t deviceIdLen;
    size_t serialIdLen;
    char serialId[AJOBS_DEVICE_SERIAL_ID_LEN + 1] = { 0 };
    char product[AJOBS_DEVICE_PRODUCT_NAME_LEN + AJOBS_DEVICE_MANUFACTURE_NAME_LEN + 1] = { 0 };

    const char* deviceProductName = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_DEVICE_NAME);

    if ((obSoftAPssid[0] == '\0') && (deviceProductName != NULL)) {
        deviceId = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_DEVICE_ID);
        if (deviceId != NULL) {
            deviceIdLen = strlen(deviceId);
            serialIdLen = min(deviceIdLen, AJOBS_DEVICE_SERIAL_ID_LEN);
            strlcpy(product, AJOBS_DEVICE_PRODUCT_NAME_LEN + AJOBS_DEVICE_MANUFACTURE_NAME_LEN + 1, deviceProductName);

            // can't have spaces in SSID
            {
                size_t i = 0;
                for (; i < serialIdLen; ++i) {
                    if (product[i] == ' ') {
                        product[i] = '_';
                    }
                }
            }

            strlcpy(serialId, AJOBS_DEVICE_SERIAL_ID_LEN + 1, deviceId + (deviceIdLen - serialIdLen));
            snprintf(obSoftAPssid, AJOBS_SSID_MAX_LENGTH + 1, "AJ_%s_%s", product, serialId);
        }
    }

    AJ_AlwaysPrintf(("%s: SoftAP: %s\n", __func__, obSoftAPssid));
    return obSoftAPssid;
}
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;
}
示例#7
0
int8_t AJSVC_PropertyStore_GetLanguageIndex(const char* const language)
{
    uint8_t langIndex;
    const char* search = language;
    if (search != NULL) {
        if (search[0] == '\0') { // Check for empty language, if yes then search for current default language index
            search = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_DEFAULT_LANGUAGE);
            if (search == NULL) {
                return AJSVC_PROPERTY_STORE_ERROR_LANGUAGE_INDEX;
            }
        }
        langIndex = AJSVC_PROPERTY_STORE_NO_LANGUAGE_INDEX;
        for (; langIndex < AJSVC_PROPERTY_STORE_NUMBER_OF_LANGUAGES; langIndex++) {
            if (!strcmp(search, propertyStoreDefaultLanguages[langIndex])) {
                return (int8_t)langIndex;
            }
        }
    }
    return AJSVC_PROPERTY_STORE_ERROR_LANGUAGE_INDEX;
}
static uint32_t PasswordCallback(uint8_t* buffer, uint32_t bufLen)
{
    AJ_Status status = AJ_OK;
    const char* hexPassword;
    size_t hexPasswordLen;
    uint32_t len = 0;

    hexPassword = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_PASSCODE);
    if (hexPassword == NULL) {
        AJ_AlwaysPrintf(("Password is NULL!\n"));
        return len;
    }
    AJ_AlwaysPrintf(("Retrieved 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;
}
/**
 * Send Notification - see notes in h file
 */
AJ_Status AJNS_Producer_SendNotification(AJ_BusAttachment* busAttachment, AJNS_NotificationContent* content, uint16_t messageType, uint32_t ttl, uint32_t* messageSerialNumber)
{
    AJ_Status status;
    AJNS_Notification notification;
    uint32_t serialNumber;

  //  AJ_InfoPrintf(("In SendNotification\n"));

    notification.version = AJNS_NotificationVersion;
    if (messageType >= AJNS_NUM_MESSAGE_TYPES)
	{
        AJ_ErrPrintf(("Could not Send Notification - MessageType is not valid\n"));
        return AJ_ERR_DISALLOWED;
    }
    notification.messageType = messageType;

    if ((ttl < AJNS_NOTIFICATION_TTL_MIN) || (ttl > AJNS_NOTIFICATION_TTL_MAX)) 
	{      //ttl is mandatory and must be in range
        AJ_ErrPrintf(("TTL '%u' is not a valid TTL value\n", ttl));
        return AJ_ERR_DISALLOWED;
    }

    notification.deviceId = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_DEVICE_ID);
    notification.deviceName = AJSVC_PropertyStore_GetValueForLang(AJSVC_PROPERTY_STORE_DEVICE_NAME, AJSVC_PropertyStore_GetLanguageIndex(""));
    notification.appId = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_APP_ID);
    notification.appName = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_APP_NAME);

    if ((notification.deviceId == 0) || (notification.deviceName == 0) ||
        (notification.appId == 0) || (notification.appName == 0)) 
	{
        AJ_ErrPrintf(("DeviceId/DeviceName/AppId/AppName can not be NULL\n"));
        return AJ_ERR_DISALLOWED;
    }

    if ((strlen(notification.deviceId) == 0) || (strlen(notification.deviceName) == 0) ||
        (strlen(notification.appId) == 0) || (strlen(notification.appName) == 0)) 
	{
        AJ_ErrPrintf(("DeviceId/DeviceName/AppId/AppName can not be empty\n"));
        return AJ_ERR_DISALLOWED;
    }

    if (notification.version > 1) 
	{
        notification.originalSenderName = AJ_GetUniqueName(busAttachment);

        if (notification.originalSenderName == 0) 
		{
            AJ_ErrPrintf(("OriginalSender can not be NULL\n"));
            return AJ_ERR_DISALLOWED;
        }

        if (strlen(notification.originalSenderName) == 0) 
		{
            AJ_ErrPrintf(("OriginalSender can not be empty\n"));
            return AJ_ERR_DISALLOWED;
        }
    }
	else 
	{
        notification.originalSenderName = NULL;
    }

    if (!notificationId)
	{
    //    AJ_InfoPrintf(("Generating random number for notification id\n"));
        AJ_RandBytes((uint8_t*)&notificationId, 4);
    }

    notification.notificationId = notificationId;
    notification.content = content;

    status = AJNS_Producer_SendNotifySignal(busAttachment, &notification, ttl, &serialNumber);

    if (status == AJ_OK) 
	{
        lastSentNotifications[messageType].notificationId = notificationId++;
        lastSentNotifications[messageType].serialNum = serialNumber;
        if (messageSerialNumber != NULL) 
		{
            *messageSerialNumber = serialNumber;
        }
    }

    return status;
}