| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #include "stm32f10x.h"
- #include <stdio.h>
- #include <stdarg.h>
- #include <string.h>
- #include <stdlib.h>
- #include "Tuoreniot.h"
- #include "mbedtls_util.h"
- #include "Log_Module.h"
- #include "At_Module.h"
- #include "Common_Util.h"
- #include "ec800m.h"
- #include "cJSON.h"
- unsigned char key[17]="tuorenzhinenghua";
- /**
- *
- *注册参数信息打包
- */
- void packRegistParams(uint8_t * pack_data, uint16_t * pack_data_length, struct Regist_Params_Struct registParams)
- {
- sprintf((char *)(pack_data + 2), "{\"platform\":\"%s\",\"connectionType\":\"%s\",\"deviceId\":\"%s\",\"userId\":%d}",
- registParams.platform, registParams.connType, registParams.deviceId, registParams.userId); // 拼接AT指令
- Log_Printf_Debug("%s\r\n", (char *)(pack_data + 2));
-
- uint16_t datalen = utils_aes128_ECB_base64_enc_with_length((char *)key, (pack_data + 2));
-
- pack_data[0] = datalen>>8;//头2个字节赋值数据长度
- pack_data[1] = datalen;
- * pack_data_length = datalen + 2;
- }
- /**
- *
- *注册数据解密
- */
- uint8_t analysisRegistData(uint8_t * regist_data, uint16_t regist_data_length, struct Regist_Params_Struct * regist_data_struct)
- {
- // Log_Printf_Debug("regist_data: \r\n");
- // Log_SendHex(regist_data, regist_data_length);
- // Log_Printf_Debug("\r\n");
- uint8_t result;
- utils_aes128_ECB_base64_dec((char *)key,regist_data,regist_data_length);
- Log_Printf_Debug("解密数据(%d):%s\r\n", regist_data_length, (char *)regist_data);
- cJSON *json = cJSON_Parse((char *)regist_data);
- if(!json)
- {
- Log_Printf_Debug("json parse error,%s\r\n",cJSON_GetErrorPtr());
- result = 0;
- }else{
- strcpy(regist_data_struct->deviceSecret, cJSON_GetObjectItem(json,"deviceSecret")->valuestring);
- strcpy(regist_data_struct->productKey, cJSON_GetObjectItem(json,"productKey")->valuestring);
- strcpy(regist_data_struct->deviceName, cJSON_GetObjectItem(json,"deviceName")->valuestring);
- result = 1;
- }
- cJSON_Delete(json);
- return result;
- }
- void printf_regist_param_struct(struct Regist_Params_Struct regist_params_struct)
- {
- Log_Printf("------print regist params start------\r\n");
- Log_Printf("connType=%s\r\n", regist_params_struct.connType);
- Log_Printf("deviceId=%s\r\n", regist_params_struct.deviceId);
- Log_Printf("deviceName=%s\r\n", regist_params_struct.deviceName);
- Log_Printf("platform=%s\r\n", regist_params_struct.platform);
- Log_Printf("deviceSecret=%s\r\n", regist_params_struct.deviceSecret);
- Log_Printf("Host=%s\r\n", regist_params_struct.host);
- Log_Printf("port=%d\r\n", regist_params_struct.port);
- Log_Printf("productKey=%s\r\n", regist_params_struct.productKey);
- Log_Printf("userId=%d\r\n", regist_params_struct.userId);
- Log_Printf("------print regist params end------\r\n");
- }
|