wrapper.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) 2015-2018 Alibaba Group Holding Limited
  3. *
  4. * Again edit by rt-thread group
  5. * Change Logs:
  6. * Date Author Notes
  7. * 2019-07-21 MurphyZhao first edit
  8. */
  9. #include <rtthread.h>
  10. #include <string.h>
  11. #include "wrappers_defs.h"
  12. #define DBG_TAG "ali.tcp"
  13. #define DBG_LVL DBG_INFO
  14. #include <rtdbg.h>
  15. #if defined(PKG_USING_ALI_IOTKIT_PRODUCT_KEY) \
  16. && defined(PKG_USING_ALI_IOTKIT_PRODUCT_SECRET) \
  17. && defined(PKG_USING_ALI_IOTKIT_DEVICE_NAME) \
  18. && defined(PKG_USING_ALI_IOTKIT_DEVICE_SECRET)
  19. char _product_key[IOTX_PRODUCT_KEY_LEN + 1] = PKG_USING_ALI_IOTKIT_PRODUCT_KEY;
  20. char _product_secret[IOTX_PRODUCT_SECRET_LEN + 1] = PKG_USING_ALI_IOTKIT_PRODUCT_SECRET;
  21. char _device_name[IOTX_DEVICE_NAME_LEN + 1] = PKG_USING_ALI_IOTKIT_DEVICE_NAME;
  22. char _device_secret[IOTX_DEVICE_SECRET_LEN + 1] = PKG_USING_ALI_IOTKIT_DEVICE_SECRET;
  23. #else
  24. char _product_key[IOTX_PRODUCT_KEY_LEN + 1] = "a1wlm6xAOPf";
  25. char _product_secret[IOTX_PRODUCT_SECRET_LEN + 1] = "NfIdVcfBP7rtH24H";
  26. char _device_name[IOTX_DEVICE_NAME_LEN + 1] = "DEV_419_ALINK_1";
  27. char _device_secret[IOTX_DEVICE_SECRET_LEN + 1] = "asXuHqpF68Hqxx8nHQ077QkiikHmYJrA";
  28. #endif
  29. int HAL_GetFirmwareVersion(char *version)
  30. {
  31. RT_ASSERT(version);
  32. char *ver = "app-1.0.0-20180101.1000";
  33. int len = strlen(ver);
  34. memset(version, 0x0, IOTX_FIRMWARE_VER_LEN);
  35. strncpy(version, ver, IOTX_FIRMWARE_VER_LEN);
  36. version[len] = '\0';
  37. return strlen(version);
  38. }
  39. int HAL_SetProductKey(char* product_key)
  40. {
  41. int len = strlen(product_key);
  42. if (len > IOTX_PRODUCT_KEY_LEN)
  43. return -1;
  44. memset(_product_key, 0x0, IOTX_PRODUCT_KEY_LEN + 1);
  45. strncpy(_product_key, product_key, len);
  46. return len;
  47. }
  48. int HAL_SetDeviceName(char* device_name)
  49. {
  50. int len = strlen(device_name);
  51. if (len > IOTX_DEVICE_NAME_LEN)
  52. return -1;
  53. memset(_device_name, 0x0, IOTX_DEVICE_NAME_LEN + 1);
  54. strncpy(_device_name, device_name, len);
  55. return len;
  56. }
  57. int HAL_SetDeviceSecret(char* device_secret)
  58. {
  59. int len = strlen(device_secret);
  60. if (len > IOTX_DEVICE_SECRET_LEN)
  61. return -1;
  62. memset(_device_secret, 0x0, IOTX_DEVICE_SECRET_LEN + 1);
  63. strncpy(_device_secret, device_secret, len);
  64. return len;
  65. }
  66. int HAL_SetProductSecret(char* product_secret)
  67. {
  68. int len = strlen(product_secret);
  69. if (len > IOTX_PRODUCT_SECRET_LEN)
  70. return -1;
  71. memset(_product_secret, 0x0, IOTX_PRODUCT_SECRET_LEN + 1);
  72. strncpy(_product_secret, product_secret, len);
  73. return len;
  74. }
  75. int HAL_GetProductKey(char product_key[IOTX_PRODUCT_KEY_LEN + 1])
  76. {
  77. memset(product_key, 0x0, IOTX_PRODUCT_KEY_LEN + 1);
  78. strncpy(product_key, _product_key, IOTX_PRODUCT_KEY_LEN);
  79. return strlen(product_key);
  80. }
  81. int HAL_GetProductSecret(char product_secret[IOTX_PRODUCT_SECRET_LEN + 1])
  82. {
  83. memset(product_secret, 0x0, IOTX_PRODUCT_SECRET_LEN + 1);
  84. strncpy(product_secret, _product_secret, IOTX_PRODUCT_SECRET_LEN);
  85. return strlen(product_secret);
  86. }
  87. int HAL_GetDeviceName(char device_name[IOTX_DEVICE_NAME_LEN + 1])
  88. {
  89. memset(device_name, 0x0, IOTX_DEVICE_NAME_LEN + 1);
  90. strncpy(device_name, _device_name, IOTX_DEVICE_NAME_LEN);
  91. return strlen(device_name);
  92. }
  93. int HAL_GetDeviceSecret(char device_secret[IOTX_DEVICE_SECRET_LEN + 1])
  94. {
  95. memset(device_secret, 0x0, IOTX_DEVICE_SECRET_LEN + 1);
  96. strncpy(device_secret, _device_secret, IOTX_DEVICE_SECRET_LEN);
  97. return strlen(device_secret);
  98. }
  99. RT_WEAK void HAL_Firmware_Persistence_Start(void)
  100. {
  101. LOG_I("OTA start... [Not implemented]");
  102. return;
  103. }
  104. RT_WEAK int HAL_Firmware_Persistence_Write(char *buffer, uint32_t length)
  105. {
  106. LOG_I("OTA write... [Not implemented]");
  107. return 0;
  108. }
  109. RT_WEAK int HAL_Firmware_Persistence_Stop(void)
  110. {
  111. /* check file md5, and burning it to flash ... finally reboot system */
  112. LOG_I("OTA finish... [Not implemented]");
  113. return 0;
  114. }