1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 
5 #ifndef AMP_DEFINES_H
6 #define AMP_DEFINES_H
7 
8 #include "board_config.h"
9 #include "mbedtls/aes.h"
10 #include "mbedtls/base64.h"
11 #include "mbedtls/des.h"
12 #include "mbedtls/md5.h"
13 #include "mbedtls/sha1.h"
14 
15 #define AMP_PY_PATH          "main.py"
16 #define AMP_PY_PKG_PATH      "app.zip"
17 
18 #define AMP_PY_ENTRY_DEFAULE (AMP_FS_EXT_ROOT_DIR "/" AMP_PY_PATH)
19 #define AMP_PY_ENTRY_BAK     (AMP_FS_ROOT_DIR "/" AMP_PY_PATH)
20 
21 #define AMP_PY_PKG_DEFAULE   (AMP_FS_ROOT_DIR "/" AMP_PY_PKG_PATH)
22 #define AMP_PY_PKG_DIR       (AMP_FS_ROOT_DIR "/")
23 
24 #define AMP_APP_MAIN_JSON    (AMP_FS_ROOT_DIR "/app.json")
25 #define AMP_APP_PACKAGE_JSON (AMP_FS_ROOT_DIR "/package.json")
26 #define AMP_APP_INDEX_JS     (AMP_FS_ROOT_DIR "/index.js")
27 
28 typedef enum {
29     HAL_SEEK_SET,
30     HAL_SEEK_CUR,
31     HAL_SEEK_END
32 } hal_fs_seek_type_t;
33 
34 /* sdk version */
35 #define AMP_VERSION_LENGTH           128
36 #define AMP_VERSION_NUMBER           "1.15"
37 #define AMP_GIT_COMMIT               "g9c40fab"
38 #define AMP_MODULE_HARDWARE          aos_get_module_hardware_version()
39 #define AMP_MODULE_SOFTWARE          aos_get_module_software_version()
40 
41 /* interval device infomation */
42 #define AMP_DEVICE_TOKEN             "_amp_device_token"
43 #define AMP_DEVICE_TOKEN_VERIFY_FLAG "_amp_device_pyamptoken_verify_flag"
44 #define AMP_DEVICE_TOKEN_LENGTH      64
45 
46 #define AMP_INTERNAL_PRODUCTKEY      "_amp_internal_productkey"
47 #define AMP_INTERNAL_PRODUCTSECRET   "_amp_internal_productsecret"
48 #define AMP_INTERNAL_DEVICENAME      "_amp_internal_devicename"
49 #define AMP_INTERNAL_DEVICESECRET    "_amp_internal_devicesecret"
50 
51 /* customer device infomation */
52 #define AMP_CUSTOMER_PRODUCTKEY      "_amp_customer_productkey"
53 #define AMP_CUSTOMER_PRODUCTSECRET   "_amp_customer_productsecret"
54 #define AMP_CUSTOMER_DEVICENAME      "_amp_customer_devicename"
55 #define AMP_CUSTOMER_DEVICESECRET    "_amp_customer_devicesecret"
56 
57 #define osWaitForever                0xFFFFFFFF /* wait forever timeout value */
58 #define PLATFORM_WAIT_INFINITE       (~0)
59 
60 #define IOTX_PRODUCT_KEY_LEN         (20)
61 #define IOTX_DEVICE_NAME_LEN         (32)
62 #define IOTX_DEVICE_SECRET_LEN       (64)
63 #define IOTX_PRODUCT_SECRET_LEN      (64)
64 
65 /* task stack size */
66 #define JSENGINE_TASK_STACK_SIZE     (1024 * 15)
67 
68 /* task priority */
69 #define JSE_TSK_PRIORITY             (AOS_DEFAULT_APP_PRI + 5)
70 #define CLI_TSK_PRIORITY             (AOS_DEFAULT_APP_PRI + 7)
71 #define MQTT_TSK_PRIORITY            (AOS_DEFAULT_APP_PRI + 6)
72 #define MQTTHTTP_TSK_PRIORITY        (AOS_DEFAULT_APP_PRI + 4)
73 #define SSDP_TSK_PRIORITY            (AOS_DEFAULT_APP_PRI + 3)
74 #define WEBSOCKET_TSK_PRIORITY       (AOS_DEFAULT_APP_PRI + 4)
75 #define WIFI_TSK_PRIORITY            (AOS_DEFAULT_APP_PRI + 4)
76 #define UPDATE_TSK_PRIORITY          (AOS_DEFAULT_APP_PRI + 6)
77 #define ADDON_TSK_PRIORRITY          (AOS_DEFAULT_APP_PRI + 3)
78 
79 /* log system operation wrapper */
80 #define amp_debug(mod, fmt, ...)     LOGD(mod, fmt, ##__VA_ARGS__)
81 #define amp_info(mod, fmt, ...)      LOGI(mod, fmt, ##__VA_ARGS__)
82 #define amp_warn(mod, fmt, ...)      LOGW(mod, fmt, ##__VA_ARGS__)
83 #define amp_error(mod, fmt, ...)     LOGE(mod, fmt, ##__VA_ARGS__)
84 #define amp_fatal(mod, fmt, ...)     LOGF(mod, fmt, ##__VA_ARGS__)
85 
86 /* JS console stdout */
87 #if defined(AMP_REPL_ENABLE) && defined(AMP_REPL_STDIO_EXTERNAL)
88 #define amp_console(fmt, ...)            \
89     do {                                 \
90         repl_printf(fmt, ##__VA_ARGS__); \
91         repl_printf("\r\n");             \
92     } while (0)
93 #else
94 #define amp_console(fmt, ...)           \
95     do {                                \
96         aos_printf(fmt, ##__VA_ARGS__); \
97         aos_printf("\r\n");             \
98     } while (0)
99 #endif
100 /* md5 */
101 #define amp_md5_context    mbedtls_md5_context
102 #define amp_md5            mbedtls_md5
103 #define amp_md5_init       mbedtls_md5_init
104 #define amp_md5_starts     mbedtls_md5_starts
105 #define amp_md5_update     mbedtls_md5_update
106 #define amp_md5_finish     mbedtls_md5_finish
107 #define amp_md5_free       mbedtls_md5_free
108 
109 /* sha1 */
110 #define amp_sha1_context   mbedtls_sha1_context
111 #define amp_sha1_init      mbedtls_sha1_init
112 #define amp_sha1_starts    mbedtls_sha1_starts
113 #define amp_sha1_update    mbedtls_sha1_update
114 #define amp_sha1_finish    mbedtls_sha1_finish
115 #define amp_sha1_free      mbedtls_sha1_free
116 
117 /* aes */
118 #define AMP_AES_ENCRYPT    MBEDTLS_AES_ENCRYPT
119 #define AMP_AES_DECRYPT    MBEDTLS_AES_DECRYPT
120 #define amp_aes_context    mbedtls_aes_context
121 #define amp_aes_init       mbedtls_aes_init
122 #define amp_aes_setkey_enc mbedtls_aes_setkey_enc
123 #define amp_aes_setkey_dec mbedtls_aes_setkey_dec
124 #define amp_aes_crypt_cbc  mbedtls_aes_crypt_cbc
125 #define amp_aes_free       mbedtls_aes_free
126 
127 /* des */
128 #define amp_des_context    mbedtls_des_context
129 #define amp_des_init       mbedtls_des_init
130 #define amp_des_setkey_enc mbedtls_des_setkey_enc
131 #define amp_des_crypt_ecb  mbedtls_des_crypt_ecb
132 #define amp_des_free       mbedtls_des_free
133 
134 /* base64 */
135 #define amp_base64_encode  mbedtls_base64_encode
136 #define amp_base64_decode  mbedtls_base64_decode
137 
138 #endif /* AMP_DEFINES_H */
139