+++ /dev/null
-ESP-IDF Bluedroid Demos
-=======================
-
-Some demos integration for bluedroid
-
-
+++ /dev/null
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-/***************************************************************
-* *
-* * This file is for client to execute battery-related operation
-* *
-***************************************************************/
-#include <stdint.h>
-#include <string.h>
-#include <stdbool.h>
-#include <stdio.h>
-
-#include "bta_api.h"
-#include "bta_gatt_api.h"
-#include "controller.h"
-
-#include "gatt_int.h"
-#include "bt_trace.h"
-#include "btm_api.h"
-#include "bt_types.h"
-#include "gattc_profile.h"
-#include "esp_gatts_api.h"
-
-#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
-#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
-esp_gattc_if_t client_if;
-
-esp_bt_uuid_t bas_uuid = {LEN_UUID_16, {UUID_SERVCLASS_BATTERY}};
-
-uint16_t get_uuid16(esp_bt_uuid_t* p_uuid)
-{
- if(p_uuid->len == LEN_UUID_16)
- {
- return p_uuid->uu.uuid16;
- }
- else if(p_uuid->len == LEN_UUID_128)
- {
- UINT16 u16;
- UINT8 *p = &p_uuid->uu.uuid128[LEN_UUID_128 - 4];
- STREAM_TO_UINT16(u16, p);
- return u16;
- }
- else
- {
- return (UINT16)p_uuid->uu.uuid32;
- }
-}
-
-/*fill a GATT ID structure*/
-void bta_le_fill_16bits_gatt_id(UINT8 inst_id, UINT16 uuid, tBTA_GATT_ID* p_output)
-{
- p_output->inst_id = inst_id;
- p_output->uuid.len = LEN_UUID_16;
- p_output->uuid.uu.uuid16 = uuid;
-}
-
-/*fill a service ID structure with a 16 bits service UUID*/
-void bta_le_fill_16bits_srvc_id(bool is_pri, UINT8 inst_id, UINT16 srvc_uuid, esp_gatt_srvc_id_t* p_output)
-{
- memset((void *)p_output, 0, sizeof(esp_gatt_srvc_id_t));
- p_output->is_primary = is_pri;
- bta_le_fill_16bits_gatt_id(inst_id, srvc_uuid, &p_output->id);
-}
-
-/*fill a char ID structure with a 16 bits char UUID*/
-void bta_le_fill_16bits_char_id(UINT8 inst_id, UINT16 char_uuid, esp_gatt_id_t* p_output)
-{
- memset((void *)p_output, 0, sizeof(esp_gatt_id_t));
- bta_le_fill_16bits_gatt_id(inst_id, char_uuid, p_output);
-}
-
-/******************************************************************************
-** Function bas_gattc_callback
-**
-** Description battery service register callback function
-*******************************************************************************/
-static void bas_gattc_callback(esp_gattc_evt_t event, esp_gattc_t* p_data)
-{
- switch (event)
- {
- case ESP_GATTC_REG_EVT:
- {
- esp_gatt_status_t status = p_data->reg_oper.status;
- client_if = p_data->reg_oper.client_if;
- LOG_ERROR("BAS register completed: event=%d, status=%d, client_if=%d\n",
- event, status, client_if);
-
- }
- break;
-
- /*connect callback*/
- case ESP_GATTC_OPEN_EVT:
- {
-
- LOG_ERROR("\n%s:device is connected "BT_BD_ADDR_STR", client_if=%d, status=%d, connect_id=%d\n",
- __FUNCTION__, BT_BD_ADDR_HEX(p_data->open.remote_bda), p_data->open.client_if,
- p_data->open.status, p_data->open.conn_id);
- /*return whether the remote device is currently connected*/
- int is_connected = BTA_DmGetConnectionState(p_data->open.remote_bda);
- LOG_ERROR("is_connected=%d\n",is_connected);
- /*get the energy info of the controller*/
-
- /*read battery level*/
- int conn_id = p_data->open.conn_id;
-
- /*discover service*/
- esp_ble_gattc_svc_search_req(conn_id, NULL);
-
- }
- break;
-
- case ESP_GATTC_SEARCH_RES_EVT:
- {
- // tBTA_GATTC_SRVC_RES service_result;
- LOG_ERROR("find the service,uuid=0x%x, is_primary=%d\n",
- get_uuid16(&p_data->srvc_res.service_uuid.id.uuid),
- p_data->srvc_res.service_uuid.is_primary);
- }
- break;
-
- case ESP_GATTC_SEARCH_CMPL_EVT:
- {
- LOG_ERROR("search service complete, conn_id=%d,status=%d\n", p_data->search_cmpl.conn_id,
- p_data->search_cmpl.status);
-
- /*get first characteristic of battey service*/
- LOG_ERROR("get first characteristic of battery service\n");
- tBTA_GATT_STATUS status;
- tBTA_GATT_SRVC_ID battery_srvc_id;
- tBTA_GATTC_CHAR_ID out_char_id;
- tGATT_CHAR_PROP out_char_prop;
- bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_srvc_id);
- status = esp_ble_gattc_get_first_char(p_data->search_cmpl.conn_id, &battery_srvc_id, NULL,
- &out_char_id, &out_char_prop);
- if(status == 0)
- {
- LOG_ERROR("the first char:srvc_id=0x%x,char_id=0x%x, property = %d\n",
- get_uuid16(&out_char_id.srvc_id.id.uuid), get_uuid16(&out_char_id.char_id.uuid),
- out_char_prop);
- /*read battery level*/
- tBTA_GATTC_CHAR_ID battery_char_id;
- bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_char_id.srvc_id);
- bta_le_fill_16bits_char_id(0, GATT_UUID_BATTERY_LEVEL, &battery_char_id.char_id);
-
- esp_ble_gattc_read_char(p_data->search_cmpl.conn_id, &battery_char_id,
- BTA_GATT_AUTH_REQ_NONE);
- }
- }
- break;
-
- case ESP_GATTC_READ_CHAR_EVT:
- {
-
- LOG_ERROR("\nread characteristic:connect_id=%d, status=%d\n",
- p_data->read.conn_id, p_data->read.status);
- LOG_ERROR("srvc_id=0x%x,char_id=0x%x,descr_type=0x%x\n",
- get_uuid16(&p_data->read.srvc_id.id.uuid),
- get_uuid16(&p_data->read.char_id.uuid),
- get_uuid16(&p_data->read.descr_type.uuid));
- if(get_uuid16(&p_data->read.descr_type.uuid) != GATT_UUID_CHAR_AGG_FORMAT
- && p_data->read.p_value->unformat.len > 0
- && p_data->read.p_value->unformat.p_value != NULL)
- {
- LOG_ERROR("read the value: len=%d, value=%d\n", p_data->read.p_value->unformat.len,
- *(p_data->read.p_value->unformat.p_value));
- }
- }
- break;
-
- default:
- LOG_ERROR("unsettled event: %d\n", event);
- }
-
-}
-
-/***************************************************************
-**
-** Function bac_register
-**
-** Description register app for battery service
-**
-****************************************************************/
-void bac_register(void)
-{
- esp_ble_gattc_app_register(&bas_uuid, bas_gattc_callback);
-
-}
-
+++ /dev/null
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <stdint.h>
-#include <string.h>
-#include <stdbool.h>
-
-#include "fixed_queue.h"
-#include "gki.h"
-#include "bt_defs.h"
-#include "bt_trace.h"
-#include "bt_types.h"
-#include "allocator.h"
-
-#include "bta_api.h"
-#include "bta_gatt_api.h"
-#include "bt_app_common.h"
-
-#include "controller.h"
-//#include "prf_defs.h"
-#include "hash_map.h"
-#include "hash_functions.h"
-#include "alarm.h"
-//#include "app_button.h"
-#if (BUT_PROFILE_CFG)
-#include "button_pro.h"
-#endif ///BUT_PROFILE_CFG
-#include "thread.h"
-#include "bt_app_common.h"
-#include "dis_api.h"
-#include "gattc_profile.h"
-#include "smp_int.h"
-#include "smp_api.h"
-
-static fixed_queue_t *bta_app_msg_queue;
-fixed_queue_t *bt_app_general_alarm_queue;
-hash_map_t *bt_app_general_alarm_hash_map;
-pthread_mutex_t bt_app_general_alarm_lock;
-static const size_t BT_APP_GENERAL_ALARM_HASH_MAP_SIZE = 10;
-
-xQueueHandle xBtaApp1Queue;
-xTaskHandle xBtaApp1TaskHandle;
-
-#define BT_APP_TTYPE_MAIN_ENTRY (1)
-static TIMER_LIST_ENT main_boot_tle;
-
-tSMP_CB smp_cmd;
-
-static void bt_app_context_switched(void *p_msg);
-static void bt_app_send_msg(void *p_msg);
-static void bt_app_task_handler(void *arg);
-static void bta_app_msg_ready(fixed_queue_t *queue);
-static void bt_app_task_shut_down(void);
-
-static void bt_app_general_alarm_ready(fixed_queue_t *queue);
-static void bt_app_general_alarm_process(TIMER_LIST_ENT *p_tle);
-void bt_app_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec);
-
-//extern void ble_test_conn(void);
-//extern void bt_test_start_inquiry(void);
-extern void ble_server_test(void);
-
-static void bt_app_task_handler(void *arg)
-{
- BtTaskEvt_t e;
- UINT8 button_msg[2] = {0x01,0x00};
- for (;;) {
- if (pdTRUE == xQueueReceive(xBtaApp1Queue, &e, (portTickType)portMAX_DELAY)) {
- if (e.sig == 0xff) {
- fixed_queue_process(bta_app_msg_queue);
- fixed_queue_process(bt_app_general_alarm_queue);
- }
-#if (BUT_PROFILE_CFG)
- // else if(e.sig == BUTTON_PRESS_EVT){
- // LOG_ERROR("button_press_event come in,button_value=%x\n",e.par);
- // button_msg[1] = e.par;
- // button_msg_notify(2,button_msg);
-
-
- //}
-#endif ///BUT_PROFILE_CFG
-
- }
- }
-}
-
-static void bt_app_task_post(void)
-{
- BtTaskEvt_t evt;
-
- evt.sig = 0xff;
- evt.par = 0;
-
- if (xQueueSend(xBtaApp1Queue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
- ets_printf("btdm_post failed\n");
- }
-
-}
-
-
-static void bta_app_msg_ready(fixed_queue_t *queue) {
- BT_HDR *p_msg;
- while (!fixed_queue_is_empty(queue)) {
- p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
- LOG_ERROR("bta_app_msg_ready, evt: %d\n", p_msg->event);
- switch (p_msg->event) {
- case BT_EVT_APP_CONTEXT_SWITCH:
- bt_app_context_switched(p_msg);
- break;
- default:
- LOG_ERROR("unhandled BT_APP event (%d)\n", p_msg->event & BT_EVT_MASK);
- break;
- }
- GKI_freebuf(p_msg);
- }
-}
-
-static void bt_app_context_switched(void *p_msg)
-{
- tBTAPP_CONTEXT_SWITCH_CBACK *p = (tBTAPP_CONTEXT_SWITCH_CBACK *) p_msg;
-
- if (p->p_cb)
- p->p_cb(p->event, p->p_param);
-}
-
-static void bt_app_send_msg(void *p_msg)
-{
- if (bta_app_msg_queue) {
- fixed_queue_enqueue(bta_app_msg_queue, p_msg);
- //ke_event_set(KE_EVENT_BT_APP_TASK);
- bt_app_task_post();
- }
-}
-
-bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTAPP_COPY_CBACK *p_copy_cback)
-{
- tBTAPP_CONTEXT_SWITCH_CBACK *p_msg;
-
- LOG_ERROR("btapp_transfer_context evt %d, len %d", event, param_len);
-
- /* allocate and send message that will be executed in btif context */
- if ((p_msg = (tBTAPP_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTAPP_CONTEXT_SWITCH_CBACK) + param_len)) != NULL)
- {
- p_msg->hdr.event = BT_EVT_APP_CONTEXT_SWITCH; /* internal event */
- p_msg->p_cb = p_cback;
-
- p_msg->event = event; /* callback event */
-
- /* check if caller has provided a copy callback to do the deep copy */
- if (p_copy_cback)
- {
- p_copy_cback(event, p_msg->p_param, p_params);
- }
- else if (p_params)
- {
- memcpy(p_msg->p_param, p_params, param_len); /* callback parameter data */
- }
-
- bt_app_send_msg(p_msg);
- return BT_STATUS_SUCCESS;
- }
- else
- {
- /* let caller deal with a failed allocation */
- return BT_STATUS_NOMEM;
- }
-}
-
-void bt_app_task_start_up(void)
-{
- bta_app_msg_queue = fixed_queue_new(SIZE_MAX);
- if (bta_app_msg_queue == NULL)
- goto error_exit;
- //ke_event_callback_set(KE_EVENT_BT_APP_TASK, &bt_app_task_handler);
-
- xBtaApp1Queue = xQueueCreate(3, sizeof(BtTaskEvt_t));
- xTaskCreate(bt_app_task_handler, "BtaApp1T", 8192, NULL, configMAX_PRIORITIES - 3, xBtaApp1TaskHandle);
-
- fixed_queue_register_dequeue(bta_app_msg_queue, bta_app_msg_ready);
-
- bt_app_general_alarm_hash_map = hash_map_new(BT_APP_GENERAL_ALARM_HASH_MAP_SIZE,
- hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
- if (bt_app_general_alarm_hash_map == NULL)
- goto error_exit;
-
- pthread_mutex_init(&bt_app_general_alarm_lock, NULL);
-
- bt_app_general_alarm_queue = fixed_queue_new(SIZE_MAX);
- if (bt_app_general_alarm_queue == NULL)
- goto error_exit;
- fixed_queue_register_dequeue(bt_app_general_alarm_queue, bt_app_general_alarm_ready);
-
- memset(&main_boot_tle, 0, sizeof(TIMER_LIST_ENT));
- return;
-
-error_exit:
- LOG_ERROR("%s Unable to allocate resources for bt_app\n", __func__);
- bt_app_task_shut_down();
-}
-
-static void bt_app_task_shut_down(void)
-{
- fixed_queue_unregister_dequeue(bta_app_msg_queue);
- fixed_queue_free(bta_app_msg_queue, NULL);
- bta_app_msg_queue = NULL;
-
- // todo: hash map, pthread_mutex...
- fixed_queue_unregister_dequeue(bt_app_general_alarm_queue);
-
- vTaskDelete(xBtaApp1TaskHandle);
- vQueueDelete(xBtaApp1Queue);
-}
-
-
-static void bt_app_dm_data_copy(uint16_t event, char *dst, char *src)
-{
- tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC*)dst;
- tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC*)src;
-
- if (!src_dm_sec)
- return;
-
- assert(dst_dm_sec);
- memcpy(dst_dm_sec, src_dm_sec, sizeof(tBTA_DM_SEC));
-
- if (event == BTA_DM_BLE_KEY_EVT)
- {
- dst_dm_sec->ble_key.p_key_value = osi_malloc(sizeof(tBTM_LE_KEY_VALUE));
- assert(src_dm_sec->ble_key.p_key_value);
- assert(dst_dm_sec->ble_key.p_key_value);
- memcpy(dst_dm_sec->ble_key.p_key_value, src_dm_sec->ble_key.p_key_value, sizeof(tBTM_LE_KEY_VALUE));
- }
-}
-
-static void bt_app_dm_data_free(uint16_t event, tBTA_DM_SEC *dm_sec)
-{
- if (event == BTA_DM_BLE_KEY_EVT)
- osi_free(dm_sec->ble_key.p_key_value);
-}
-
-static void bt_app_dm_upstreams_evt(UINT16 event, char *p_param)
-{
- tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param;
- switch (event) {
- case BTA_DM_ENABLE_EVT: {
-
-// BTA_DmSetDeviceName("ijiazu");
-
-
-
-
- /*set connectable,discoverable, pairable and paired only modes of local device*/
- tBTA_DM_DISC disc_mode = BTA_DM_BLE_GENERAL_DISCOVERABLE;
- tBTA_DM_CONN conn_mode = BTA_DM_BLE_CONNECTABLE;
- //BTA_DmSetVisibility(disc_mode, conn_mode, (UINT8)BTA_DM_NON_PAIRABLE, (UINT8)BTA_DM_CONN_ALL);
-
-#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
- /* Enable local privacy */
- //BTA_DmBleConfigLocalPrivacy(BLE_LOCAL_PRIVACY_ENABLED);
- do {
- const controller_t *controller = controller_get_interface();
- char bdstr[18];
- bdaddr_to_string(controller->get_address(), bdstr, sizeof(bdstr));
- LOG_ERROR("BDA is: %s\n", bdstr);
- } while (0);
-#endif
- }
- break;
- case BTA_DM_BLE_SEC_REQ_EVT:
-
- smp_cb.local_io_capability = 0x03; //no input no output
- smp_cb.loc_oob_flag = 0x00; //oob data not present
- smp_cb.loc_auth_req = 0x01;
- smp_cb.loc_enc_size = 0x10;
- smp_cb.local_i_key = 0x01;
- smp_cb.local_r_key = 0x01; //1101
-
- //memcpy(smp_cb.pairing_bda,p_data->ble_req.bd_addr,0x06);
-
- smp_sm_event(&smp_cb,SMP_PAIRING_REQ_EVT,NULL);
- //smp_send_cmd(SMP_OPCODE_PAIRING_RSP,&smp_cb);
- //smp_generate_srand_mrand_confirm(&smp_cb,NULL);
- //smp_set_state(SMP_STATE_PAIR_REQ_RSP,SMP_BR_PAIRING_REQ_EVT);
- //BTA_DmConfirm(p_data->ble_req.bd_addr,true);
- break;
- case BTA_DM_BLE_KEY_EVT:
- if(p_data->ble_key.key_type == BTM_LE_KEY_PENC)
- {
- smp_set_state(SMP_STATE_IDLE);
- }
- break;
- default:
- break;
- }
-
- bt_app_dm_data_free(event, p_data);
-}
-
-static void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data)
-{
- LOG_ERROR("bte_dm_evt: %d\n", (uint16_t)event);
- bt_app_transfer_context(bt_app_dm_upstreams_evt, (uint16_t)event,
- (void *)p_data, sizeof(tBTA_DM_SEC), bt_app_dm_data_copy);
-}
-
-void bt_app_init_ok(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param)
-{
- BTA_EnableBluetooth(bte_dm_evt);
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- bt_app_start_timer(&main_boot_tle, BT_APP_TTYPE_MAIN_ENTRY, 8);
-}
-
-/* Alarm timer */
-static void bt_app_general_alarm_cb(void *data) {
- assert(data != NULL);
- TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
-
- fixed_queue_enqueue(bt_app_general_alarm_queue, p_tle);
- //ke_event_set(KE_EVENT_BT_APP_TASK);
- bt_app_task_post();
-}
-
-void bt_app_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec) {
- osi_alarm_t *alarm = NULL;
-
- assert(p_tle != NULL);
-
- // Get the alarm for the timer list entry.
- pthread_mutex_lock(&bt_app_general_alarm_lock);
- if (!hash_map_has_key(bt_app_general_alarm_hash_map, p_tle)) {
- alarm = osi_alarm_new("bt_app", bt_app_general_alarm_cb, (void *)p_tle, 0);
- hash_map_set(bt_app_general_alarm_hash_map, p_tle, alarm);
- }
- pthread_mutex_unlock(&bt_app_general_alarm_lock);
-
- pthread_mutex_lock(&bt_app_general_alarm_lock);
- alarm = hash_map_get(bt_app_general_alarm_hash_map, p_tle);
- pthread_mutex_unlock(&bt_app_general_alarm_lock);
- if (alarm == NULL) {
- LOG_ERROR("%s Unable to create alarm\n", __func__);
-
- return;
- }
-
- osi_alarm_cancel(alarm);
-
- p_tle->event = type;
- // NOTE: This value is in seconds but stored in a ticks field.
- p_tle->ticks = timeout_sec;
- p_tle->in_use = TRUE;
- osi_alarm_set(alarm, (period_ms_t)(timeout_sec * 1000));
-}
-
-void bt_app_stop_timer(TIMER_LIST_ENT *p_tle)
-{
- assert(p_tle != NULL);
-
- if (p_tle->in_use == FALSE)
- return;
- p_tle->in_use = FALSE;
-
- // Get the alarm for the timer list entry.
- osi_alarm_t *alarm = hash_map_get(bt_app_general_alarm_hash_map, p_tle);
- if (alarm == NULL) {
- LOG_WARN("%s Unable to find expected alarm in hashmap\n", __func__);
- return;
- }
- osi_alarm_cancel(alarm);
-}
-
-static void bt_app_general_alarm_process(TIMER_LIST_ENT *p_tle)
-{
- assert(p_tle != NULL);
- LOG_ERROR("general_alarm_process\n");
- switch (p_tle->event) {
- case BT_APP_TTYPE_MAIN_ENTRY:
- LOG_ERROR("BT_APP main boot**********\n");
-
- // ble_test_conn();
- // ble_server_test();
-
-
- // bt_test_start_inquiry();
- /*set connectable,discoverable, pairable and paired only modes of local device*/
- // tBTA_DM_DISC disc_mode = BTA_DM_BLE_GENERAL_DISCOVERABLE;
- // tBTA_DM_CONN conn_mode = BTA_DM_BLE_CONNECTABLE;
- // BTA_DmSetVisibility(disc_mode, conn_mode, (UINT8)BTA_DM_NON_PAIRABLE, (UINT8)BTA_DM_CONN_ALL);
-
- gatts_server_test();
- //gattc_client_test();
- break;
- }
-
-}
-
-static void bt_app_general_alarm_ready(fixed_queue_t *queue)
-{
- TIMER_LIST_ENT *p_tle;
-
- while (!fixed_queue_is_empty(queue)) {
- p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(queue);
- bt_app_general_alarm_process(p_tle);
- }
-}
-
-void bt_app_core_start(void) {
- bt_app_transfer_context(bt_app_init_ok, 0, NULL, 0, NULL);
-}
-
+++ /dev/null
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "prf_defs.h"
-#if (WX_AIRSYNC_CFG)
-
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include "gki.h"
-#include "app_airsync_md5.h"
-
-const uint32_t X[4][2] = {{0, 1}, {1, 5}, {5, 3}, {0, 7}};
-const uint32_t S[4][4] = {{ 7, 12, 17, 22 },{ 5, 9 , 14, 20 },{ 4, 11, 16, 23 },{ 6, 10, 15, 21 }};
-uint32_t F( uint32_t X, uint32_t Y, uint32_t Z )
-{
- return ( X & Y ) | ( ~X & Z );
-}
-uint32_t G( uint32_t X, uint32_t Y, uint32_t Z )
- {
- return ( X & Z ) | ( Y & ~Z );
- }
-uint32_t H( uint32_t X, uint32_t Y, uint32_t Z )
-{
- return X ^ Y ^ Z;
-}
-uint32_t I( uint32_t X, uint32_t Y, uint32_t Z )
-{
- return Y ^ ( X | ~Z );
-}
- // rotates x left s bits.
-uint32_t rotate_left( uint32_t x, uint32_t s )
-{
- return ( x << s ) | ( x >> ( 32 - s ) );
-}
-
- // Pre-processin
-uint32_t count_padding_bits ( uint32_t length )
-{
-// uint32_t div = length * BITS / BLOCK_SIZE;
- uint32_t mod = length * BITS % BLOCK_SIZE;
- uint32_t c_bits;
- if ( mod == 0 )
- {
- c_bits = MOD_SIZE;
- }
- else
- {
- c_bits = ( MOD_SIZE + BLOCK_SIZE - mod ) % BLOCK_SIZE;
- }
- return c_bits / BITS;
-}
-
-MD5String append_padding_bits ( char * argv )
-{
- uint32_t msg_length = strlen ( argv );
- uint32_t bit_length = count_padding_bits ( msg_length );
- uint64_t app_length = msg_length * BITS;
- MD5String string;
- string.str = (char *)GKI_getbuf(msg_length + bit_length + APP_SIZE / BITS);
- strncpy ( string.str, argv, msg_length );
- memset ( string.str + msg_length, 0, bit_length );
- string.str [ msg_length ] = SINGLE_ONE_BIT;
- memmove ( string.str + msg_length + bit_length, (char *)&app_length, sizeof( uint64_t ) );
- string.len = msg_length + bit_length + sizeof( uint64_t );
- return string;
-}
-
-int32_t wechat_md5 (char *argv, uint8_t *md5_32)
-{
- MD5String string;
- uint32_t w[16];
- uint32_t chain[4];
- uint32_t state[4];
-
- uint32_t ( *auxi[ 4 ])( uint32_t, uint32_t, uint32_t ) = { F, G, H, I };
- int sIdx;
- int wIdx;
- string = append_padding_bits ( argv );
- chain[0] = A;
- chain[1] = B;
- chain[2] = C;
- chain[3] = D;
- for (uint32_t j = 0; j < string.len; j += BLOCK_SIZE / BITS)
- {
- memmove ( (char *)w, string.str + j, BLOCK_SIZE / BITS );
- memmove ( state, chain, sizeof(chain) );
- for ( uint8_t roundIdx = 0; roundIdx < 4; roundIdx++ )
- {
- wIdx = X[ roundIdx ][ 0 ];
- sIdx = 0;
- for (uint8_t i = 0; i < 16; i++ )
- {
- state[sIdx] = state [(sIdx + 1)%4] + rotate_left( state[sIdx] +(*auxi[ roundIdx])( state[(sIdx+1) % 4],
- state[(sIdx+2) % 4],
- state[(sIdx+3) % 4]) + w[ wIdx ] + (uint32_t)floor((1ULL << 32) * fabs(sin( roundIdx * 16 + i + 1 )) ),
- S[ roundIdx ][ i % 4 ]);
- sIdx = ( sIdx + 3 ) % 4;
- wIdx = ( wIdx + X[ roundIdx ][ 1 ] ) & 0xF;
- }
- }
- chain[ 0 ] += state[ 0 ];
- chain[ 1 ] += state[ 1 ];
- chain[ 2 ] += state[ 2 ];
- chain[ 3 ] += state[ 3 ];
- }
- memmove ( md5_32 + 0, (char *)&chain[0], sizeof(uint32_t) );
- memmove ( md5_32 + 4, (char *)&chain[1], sizeof(uint32_t) );
- memmove ( md5_32 + 8, (char *)&chain[2], sizeof(uint32_t) );
- memmove ( md5_32 + 12, (char *)&chain[3], sizeof(uint32_t) );
- free(string.str);
- string.str = NULL;
- return EXIT_SUCCESS;
-
-}
-
-
-#endif ///WX_AIRSYNC_CFG
-
+++ /dev/null
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "prf_defs.h"
-#if (WX_AIRSYNC_CFG)
-
-#include "app_airsync_prf.h"
-#include "wx_airsync_prf.h"
-#include "app_wechat_util.h"
-#include "gki.h"
-#include "mpbledemo2.h"
-
-/*****************************************************************************
-* data handle
-*****************************************************************************/
-data_info g_send_data;
-
-static data_info g_rcv_data;
-data_handler *pDataHandler;
-
-
-static void airsync_process_msgreceive_cb(UINT8 app_id,
- UINT8 conn_id,uint8_t *pData, uint16_t length);
-
-///function for register all products
-static void register_all_products(void)
-{
- REGISTER(mpbledemo2);
- // could register more products if defined
-}
-
-void app_wechat_init(void)
-{
- register_all_products();
-
- data_handler_init(&m_mpbledemo2_handler,PRODUCT_TYPE_MPBLEDEMO2);
- m_mpbledemo2_handler->m_data_init_func();
- m_mpbledemo2_handler->m_data_init_peripheral_func();
-
- app_wechat_SetDatahandler(m_mpbledemo2_handler);
-}
-
-int ble_wechat_indicate_data_chunk(void)
-{
- uint16_t chunk_len = 0;
- chunk_len = g_send_data.len - g_send_data.offset;
- chunk_len = chunk_len > BLE_WECHAT_MAX_DATA_LEN?BLE_WECHAT_MAX_DATA_LEN:chunk_len;
-
- if(chunk_len == 0)
- {
- app_wechat_datahandler()->m_data_free_func(g_send_data.data,g_send_data.len);
- g_send_data.data = NULL;
- g_send_data.len = 0;
- g_send_data.offset = 0;
- return 0;
- }
-
- g_send_data.offset += chunk_len;
- return 1;
-}
-
-
- /*******************************************************************************
-**
-** Function airsync_msgreceive_cb
-**
-** Description the callback function after the airsync profile have been
-** receive the data from the peer device
-** parms appid:the appid have been register to the gatt database
-** conn_id:the current connection index
-** msg_val:the airsync value receive from peer device
-** Returns NULL
-**
-*******************************************************************************/
-static void airsync_process_msgreceive_cb(UINT8 app_id,
- UINT8 conn_id,uint8_t *pData, uint16_t length)
-{
- int error_code;
- int chunk_size = 0;
- if(length <= BLE_WECHAT_MAX_DATA_LEN)
- {
- if(g_rcv_data.len == 0)
- {
- BpFixHead *fix_head = (BpFixHead *)pData;
- g_rcv_data.len = ntohs(fix_head->nLength);
- g_rcv_data.offset = 0;
- g_rcv_data.data = (uint8_t *)GKI_getbuf(g_rcv_data.len);
- }
-
- chunk_size = g_rcv_data.len - g_rcv_data.offset;
- chunk_size = chunk_size < length ? chunk_size : length;
- memcpy(g_rcv_data.data + g_rcv_data.offset, pData, chunk_size);
- g_rcv_data.offset += chunk_size;
-
- if (g_rcv_data.len <= g_rcv_data.offset)
- {
- error_code = app_wechat_datahandler()->m_data_consume_func(g_rcv_data.data, g_rcv_data.len);
- app_wechat_datahandler()->m_data_free_func(g_rcv_data.data,g_rcv_data.len);
- wechat_error_chack(app_wechat_datahandler(), error_code);
- g_rcv_data.len = 0;
- g_rcv_data.offset = 0;
-
- app_wechat_datahandler()->m_data_main_process_func();
- }
-
-
- }
-
-
-}
-
- void app_wechat_SetDatahandler(data_handler* pHandler)
-{
- pDataHandler = pHandler;
-}
-
-bool ble_wechat_is_last_data_sent_out(void)
-{
- return (g_send_data.len == 0 && g_send_data.offset == 0 ) || \
- (g_send_data.len != 0 && g_send_data.len == g_send_data.offset);
-}
-
-//device sent data on the indicate characteristic
-int ble_wechat_indicate_data(uint8_t *data, int len)
-{
- if(data == NULL || len == 0)
- {
- return 0;
- }
-
- if(!ble_wechat_is_last_data_sent_out())
- {
- return 0;
- }
-
- g_send_data.data = data;
- g_send_data.len = len;
- g_send_data.offset = 0;
-
- return (ble_wechat_indicate_data_chunk());
-}
-
-data_handler *app_wechat_datahandler(void)
-{
- return pDataHandler;
-}
-
-
-#endif ///WX_AIRSYNC_CFG
-
+++ /dev/null
-// epb.c\r
-// WeChat Embedded Proto Buffer\r
-//\r
-// Created by harlliu@tencent.com on 14-02-15.\r
-// Copyright 2014 Tencent. All rights reserved.\r
-//\r
-\r
-// Version : 1.0.2\r
-\r
-#include "prf_defs.h"\r
-#if (WX_AIRSYNC_CFG)\r
-\r
-\r
-#include <string.h>\r
-#include "epb.h"\r
-\r
-\r
-#define __LITTLE_ENDIAN__ 1 //Need Test\r
-\r
-typedef enum {\r
- WIRETYPE_VARINT = 0,\r
- WIRETYPE_FIXED64 = 1,\r
- WIRETYPE_LENGTH_DELIMITED = 2,\r
- WIRETYPE_FIXED32 = 5\r
-} WireType;\r
-\r
-#define CONTINUOUS_MASK 0x80\r
-#define WIRETYPE_MASK 0x07\r
-\r
-static int epb_get_varint32_bits(const uint8_t *data, int len, uint32_t *value);\r
-\r
-inline static int sizeof_tag(uint16_t tag)\r
-{\r
- return ((tag&0xff00) == 0) ? 1 : 2; //TODO:Tag more then two bytes\r
-}\r
-\r
-static uint16_t epb_get_wire_type(uint16_t tag) {\r
- uint16_t wire_type = tag & WIRETYPE_MASK;\r
- if ((tag>>8) != 0)\r
- wire_type = (tag>>8) & WIRETYPE_MASK;\r
-\r
- return wire_type;\r
-}\r
-\r
-static int epb_get_value_length(const uint8_t *data, int len, uint32_t wire_type)\r
-{\r
- int offset = 0;\r
- switch(wire_type) {\r
- case WIRETYPE_VARINT:\r
- while ((data[offset++]&CONTINUOUS_MASK)!=0 && offset<len);\r
- break;\r
- case WIRETYPE_FIXED64:\r
- offset += 8;\r
- break;\r
- case WIRETYPE_LENGTH_DELIMITED:\r
- {\r
- int32_t l = 0;\r
- offset += epb_get_varint32_bits(data+offset, len-offset, (uint32_t *)&l);\r
- offset += l;\r
- }\r
- break;\r
- case WIRETYPE_FIXED32:\r
- offset += 4;\r
- break;\r
- default:\r
- return -1;\r
- }\r
- return offset;\r
-}\r
-\r
-static int epb_get_tag_value_offset(const uint8_t *data, int len, uint16_t tag)\r
-{\r
- int offset = 0;\r
- uint32_t p_tag;\r
- while (offset < len) {\r
- p_tag = data[offset++];\r
- while ((data[offset-1]&CONTINUOUS_MASK)!=0 && offset<len) {\r
- p_tag = (p_tag<<8)|(data[offset++]&0x7f); //TODO:Tag more then two bytes\r
- }\r
- if (p_tag == tag)\r
- return offset;\r
-\r
- uint32_t wire_type = epb_get_wire_type(p_tag);\r
- int ret = epb_get_value_length(data+offset, len-offset, wire_type);\r
- if (ret < 0) {\r
- offset++;\r
- continue;\r
- }\r
-\r
- offset += ret;\r
- }\r
- return -1;\r
-}\r
-\r
-static int epb_get_varint32_bits(const uint8_t *data, int len, uint32_t *value)\r
-{\r
- int offset = 0;\r
- uint32_t p_value = data[offset++] & 0x7F;\r
- while ((data[offset-1]&CONTINUOUS_MASK) != 0) {\r
- if (offset >= len)\r
- return -1;\r
-\r
- if (offset >= 5)\r
- break;\r
-\r
- p_value |= ((uint32_t)data[offset]&0x7F) << (offset*7);\r
- ++offset;\r
- }\r
- *value = p_value;\r
- return offset;\r
-}\r
-\r
-static uint32_t epb_get_fixed32_bits(const uint8_t *data, int len)\r
-{\r
- if(len < 4)\r
- return 0;\r
-\r
- uint32_t value = 0;\r
-#ifdef __LITTLE_ENDIAN__\r
- memcpy(&value, data, sizeof(uint32_t));\r
-#else \r
- value = (data[3]<<24)|(data[2]<<16)|(data[1]<<8)|data[0];\r
-#endif\r
- return value;\r
-}\r
-\r
-void epb_unpack_init(Epb *e, const uint8_t *buf, int len)\r
-{\r
- e->unpack_buf = buf;\r
- e->buf_len = len;\r
-}\r
-\r
-bool epb_has_tag(Epb *e, uint16_t tag)\r
-{\r
- int offset = epb_get_tag_value_offset(e->unpack_buf, e->buf_len, tag);\r
- if (offset < 0)\r
- return false;\r
- else\r
- return true;\r
-}\r
-\r
-uint32_t epb_get_uint32(Epb *e, uint16_t tag)\r
-{\r
- int offset = epb_get_tag_value_offset(e->unpack_buf, e->buf_len, tag);\r
- if (offset < 0)\r
- return 0;\r
-\r
- uint32_t value = 0;\r
- epb_get_varint32_bits(e->unpack_buf+offset, e->buf_len-offset, &value);\r
- return value;\r
-}\r
-\r
-int32_t epb_get_int32(Epb *e, uint16_t tag)\r
-{\r
- return epb_get_uint32(e, tag);\r
-}\r
-\r
-int32_t epb_get_sint32(Epb *e, uint16_t tag)\r
-{\r
- uint32_t value = epb_get_uint32(e, tag);\r
- if (value&1)\r
- return -(value>>1) - 1;\r
- else\r
- return value>>1;\r
-}\r
-\r
-bool epb_get_bool(Epb *e, uint16_t tag)\r
-{\r
- return epb_get_uint32(e, tag);\r
-}\r
-\r
-int epb_get_enum(Epb *e, uint16_t tag)\r
-{\r
- return epb_get_uint32(e, tag);\r
-}\r
-\r
-const uint8_t *epb_get_bytes(Epb *e, uint16_t tag, int *len)\r
-{\r
- int offset = epb_get_tag_value_offset(e->unpack_buf, e->buf_len, tag);\r
- if (offset < 0)\r
- return NULL;\r
-\r
- uint32_t l;\r
- offset += epb_get_varint32_bits(e->unpack_buf+offset, e->buf_len-offset, &l);\r
- *len = (int)l;\r
-\r
- return e->unpack_buf+offset;\r
-}\r
-\r
-const char *epb_get_string(Epb *e, uint16_t tag, int *len)\r
-{\r
- return (char *)epb_get_bytes(e, tag, len);\r
-}\r
-\r
-const Message *epb_get_message(Epb *e, uint16_t tag, int *len)\r
-{\r
- return (Message *)epb_get_bytes(e, tag, len);\r
-}\r
-\r
-uint32_t epb_get_fixed32(Epb *e, uint16_t tag)\r
-{\r
- int offset = epb_get_tag_value_offset(e->unpack_buf, e->buf_len, tag);\r
- if (offset < 0)\r
- return 0;\r
-\r
- return epb_get_fixed32_bits(e->unpack_buf+offset, e->buf_len-offset);\r
-}\r
-\r
-int32_t epb_get_sfixed32(Epb *e, uint16_t tag)\r
-{\r
- return epb_get_fixed32(e, tag);\r
-}\r
-\r
-float epb_get_float(Epb *e, uint16_t tag)\r
-{\r
- uint32_t bits = epb_get_fixed32(e, tag);\r
- return *(float *)&bits;\r
-}\r
-\r
-/*\r
- epb pack functions\r
-*/\r
-\r
-inline static int epb_pack_buf_remain(Epb *e)\r
-{\r
- return e->buf_len - e->buf_offset;\r
-}\r
-\r
-static int epb_pack_tag(Epb *e, uint16_t tag)\r
-{\r
- int tag_len = sizeof_tag(tag);\r
- if (epb_pack_buf_remain(e) >= tag_len) {\r
- uint8_t *buf = e->pack_buf + e->buf_offset;\r
- if (tag_len == 2) //TODO\r
- *(buf++) = 0xff&(tag>>8);\r
- *buf = 0xff&tag;\r
- e->buf_offset += tag_len;\r
- return tag_len;\r
- }\r
- return -1;\r
-}\r
-\r
-static int epb_pack_varint32_bits(Epb *e, uint32_t value)\r
-{\r
- uint8_t buf[5] = {0};\r
- int i = 0;\r
- do {\r
- buf[i] = value&0x7f;\r
- if (i-1 >= 0)\r
- buf[i-1] |= 0x80;\r
- value = value >> 7;\r
- ++i;\r
- } while (value!=0 && i<5);\r
- if (epb_pack_buf_remain(e) >= i) {\r
- memcpy(e->pack_buf+e->buf_offset, buf, i);\r
- e->buf_offset += i;\r
- return i;\r
- }\r
- return -1;\r
-}\r
-\r
-void epb_pack_init(Epb *e, uint8_t *buf, int len)\r
-{\r
- e->pack_buf = buf;\r
- e->buf_len = len;\r
- e->buf_offset = 0;\r
-}\r
-\r
-int epb_get_packed_size(Epb *e)\r
-{\r
- return e->buf_offset;\r
-}\r
-\r
-int epb_set_uint32(Epb *e, uint16_t tag, uint32_t value)\r
-{\r
- int len = 0;\r
- int ret = epb_pack_tag(e, tag);\r
- if (ret < 0) return ret;\r
- len += ret;\r
-\r
- ret = epb_pack_varint32_bits(e, value);\r
- if (ret < 0) return ret;\r
- len += ret;\r
-\r
- return len;\r
-}\r
-\r
-int epb_set_int32(Epb *e, uint16_t tag, int32_t value)\r
-{\r
- return epb_set_uint32(e, tag, value);\r
-}\r
-\r
-int epb_set_sint32(Epb *e, uint16_t tag, int32_t value)\r
-{\r
- uint32_t v = (value << 1) ^ (value >> 31);\r
- return epb_set_uint32(e, tag, v);\r
-}\r
-\r
-int epb_set_bool(Epb *e, uint16_t tag, bool value)\r
-{\r
- return epb_set_uint32(e, tag, value);\r
-}\r
-\r
-int epb_set_enum(Epb *e, uint16_t tag, int value)\r
-{\r
- return epb_set_uint32(e, tag, value);\r
-}\r
-\r
-static int epb_set_fixed32_bits(Epb *e, uint32_t value)\r
-{\r
- if (epb_pack_buf_remain(e) >= 4) {\r
-#ifdef __LITTLE_ENDIAN__\r
- memcpy(e->pack_buf+e->buf_offset, &value, 4);\r
-#else\r
- uint8_t *data = (uint8_t *)&value;\r
- for (int i=0; i<4; i++) {\r
- *(e->pack_buf+e->buf_offset+i) = data[4-i];\r
- }\r
-#endif\r
- e->buf_offset += 4;\r
- return 4;\r
- }\r
- return -1;\r
-}\r
-\r
-static int epb_pack_length_delimited(Epb *e, const uint8_t *data, int len)\r
-{\r
- if (epb_pack_buf_remain(e) >= len) {\r
- memcpy(e->pack_buf + e->buf_offset, data, len);\r
- e->buf_offset += len;\r
- return len;\r
- }\r
- return -1;\r
-}\r
-\r
-int epb_set_bytes(Epb *e, uint16_t tag, const uint8_t *data, int length)\r
-{\r
- int len = 0;\r
- int ret = epb_pack_tag(e, tag);\r
- if (ret < 0) return ret;\r
- len += ret;\r
-\r
- ret = epb_pack_varint32_bits(e, length);\r
- if (ret < 0) return ret;\r
- len += ret;\r
-\r
- ret = epb_pack_length_delimited(e, data, length);\r
- if (ret < 0) return ret;\r
- len += ret;\r
-\r
- return len;\r
-}\r
-\r
-int epb_set_string(Epb *e, uint16_t tag, const char *data, int len)\r
-{\r
- return epb_set_bytes(e, tag, (const uint8_t *)data, len);\r
-}\r
-\r
-int epb_set_message(Epb *e, uint16_t tag, const Message *data, int len)\r
-{\r
- return epb_set_bytes(e, tag, data, len);\r
-}\r
-\r
-int epb_set_fixed32(Epb *e, uint16_t tag, uint32_t value)\r
-{\r
- int len = 0;\r
- int ret = epb_pack_tag(e, tag);\r
- if (ret < 0) return ret;\r
- len += ret;\r
-\r
- ret = epb_set_fixed32_bits(e, value);\r
- if (ret < 0) return ret;\r
- len += ret;\r
-\r
- return len;\r
-}\r
-\r
-int epb_set_sfixed32(Epb *e, uint16_t tag, int32_t value)\r
-{\r
- return epb_set_fixed32(e, tag, value);\r
-}\r
-\r
-int epb_set_float(Epb *e, uint16_t tag, float value)\r
-{\r
- uint32_t v = *(uint32_t *)&value;\r
- return epb_set_fixed32(e, tag, v);\r
-}\r
-\r
-int epb_varint32_pack_size(uint16_t tag, uint32_t value, bool is_signed)\r
-{\r
- if (is_signed)\r
- value = (value << 1) ^ (value >> 31);\r
-\r
- int i = 0;\r
- do {\r
- value = value >> 7;\r
- ++i;\r
- } while (value!=0 && i<5);\r
-\r
- return sizeof_tag(tag) + i;\r
-}\r
-\r
-int epb_fixed32_pack_size(uint16_t tag)\r
-{\r
- return sizeof_tag(tag) + 4;\r
-}\r
-\r
-int epb_length_delimited_pack_size(uint16_t tag, int len)\r
-{\r
- return epb_varint32_pack_size(tag, len, false) + len;\r
-}\r
-\r
-\r
-#endif ///WX_AIRSYNC_CFG
\ No newline at end of file
+++ /dev/null
-// epb_MmBp.c\r
-// WeChat Embedded Proto Buffer\r
-//\r
-// Generated by harlliu@tencent.com on 14-11-26.\r
-// Copyright 2014 Tencent. All rights reserved.\r
-//\r
-\r
-// Version : 1.0.4\r
-\r
-#include "prf_defs.h"\r
-#if (WX_AIRSYNC_CFG)\r
-\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include "epb_MmBp.h"\r
-#include "gki.h"\r
-\r
-#define TAG_BaseResponse_ErrCode 0x08\r
-#define TAG_BaseResponse_ErrMsg 0x12\r
-\r
-#define TAG_AuthRequest_BaseRequest 0x0a\r
-#define TAG_AuthRequest_Md5DeviceTypeAndDeviceId 0x12\r
-#define TAG_AuthRequest_ProtoVersion 0x18\r
-#define TAG_AuthRequest_AuthProto 0x20\r
-#define TAG_AuthRequest_AuthMethod 0x28\r
-#define TAG_AuthRequest_AesSign 0x32\r
-#define TAG_AuthRequest_MacAddress 0x3a\r
-#define TAG_AuthRequest_TimeZone 0x52\r
-#define TAG_AuthRequest_Language 0x5a\r
-#define TAG_AuthRequest_DeviceName 0x62\r
-\r
-#define TAG_AuthResponse_BaseResponse 0x0a\r
-#define TAG_AuthResponse_AesSessionKey 0x12\r
-\r
-#define TAG_InitRequest_BaseRequest 0x0a\r
-#define TAG_InitRequest_RespFieldFilter 0x12\r
-#define TAG_InitRequest_Challenge 0x1a\r
-\r
-#define TAG_InitResponse_BaseResponse 0x0a\r
-#define TAG_InitResponse_UserIdHigh 0x10\r
-#define TAG_InitResponse_UserIdLow 0x18\r
-#define TAG_InitResponse_ChalleangeAnswer 0x20\r
-#define TAG_InitResponse_InitScence 0x28\r
-#define TAG_InitResponse_AutoSyncMaxDurationSecond 0x30\r
-#define TAG_InitResponse_UserNickName 0x5a\r
-#define TAG_InitResponse_PlatformType 0x60\r
-#define TAG_InitResponse_Model 0x6a\r
-#define TAG_InitResponse_Os 0x72\r
-#define TAG_InitResponse_Time 0x78\r
-#define TAG_InitResponse_TimeZone 0x8001\r
-#define TAG_InitResponse_TimeString 0x8a01\r
-\r
-#define TAG_SendDataRequest_BaseRequest 0x0a\r
-#define TAG_SendDataRequest_Data 0x12\r
-#define TAG_SendDataRequest_Type 0x18\r
-\r
-#define TAG_SendDataResponse_BaseResponse 0x0a\r
-#define TAG_SendDataResponse_Data 0x12\r
-\r
-#define TAG_RecvDataPush_BasePush 0x0a\r
-#define TAG_RecvDataPush_Data 0x12\r
-#define TAG_RecvDataPush_Type 0x18\r
-\r
-#define TAG_SwitchViewPush_BasePush 0x0a\r
-#define TAG_SwitchViewPush_SwitchViewOp 0x10\r
-#define TAG_SwitchViewPush_ViewId 0x18\r
-\r
-#define TAG_SwitchBackgroudPush_BasePush 0x0a\r
-#define TAG_SwitchBackgroudPush_SwitchBackgroundOp 0x10\r
-\r
-\r
-int epb_base_request_pack_size(BaseRequest *request)\r
-{\r
- int pack_size = 0;\r
-\r
- return pack_size;\r
-}\r
-\r
-int epb_pack_base_request(BaseRequest *request, uint8_t *buf, int buf_len)\r
-{\r
- Epb epb;\r
- epb_pack_init(&epb, buf, buf_len);\r
-\r
- return epb_get_packed_size(&epb);\r
-}\r
-\r
-BaseResponse *epb_unpack_base_response(const uint8_t *buf, int buf_len)\r
-{\r
- Epb epb;\r
- epb_unpack_init(&epb, buf, buf_len);\r
-\r
- if (!epb_has_tag(&epb, TAG_BaseResponse_ErrCode)) {\r
- return NULL;\r
- }\r
-\r
- BaseResponse *response = (BaseResponse *)GKI_getbuf(sizeof(BaseResponse));\r
- memset(response, 0, sizeof(BaseResponse));\r
- response->err_code = epb_get_int32(&epb, TAG_BaseResponse_ErrCode);\r
- if (epb_has_tag(&epb, TAG_BaseResponse_ErrMsg)) {\r
- response->err_msg.str = epb_get_string(&epb, TAG_BaseResponse_ErrMsg, &response->err_msg.len);\r
- response->has_err_msg = true;\r
- }\r
-\r
- return response;\r
-}\r
-\r
-void epb_unpack_base_response_free(BaseResponse *response)\r
-{\r
- GKI_freebuf(response);\r
-}\r
-\r
-BasePush *epb_unpack_base_push(const uint8_t *buf, int buf_len)\r
-{\r
- Epb epb;\r
- epb_unpack_init(&epb, buf, buf_len);\r
-\r
- BasePush *push = (BasePush *)GKI_getbuf(sizeof(BasePush));\r
- memset(push, 0, sizeof(BasePush));\r
-\r
- return push;\r
-}\r
-\r
-void epb_unpack_base_push_free(BasePush *push)\r
-{\r
- GKI_freebuf(push);\r
-}\r
-\r
-int epb_auth_request_pack_size(AuthRequest *request)\r
-{\r
- int pack_size = 0;\r
- int len = 0;\r
-\r
- len = epb_base_request_pack_size(request->base_request);\r
- pack_size += epb_length_delimited_pack_size(TAG_AuthRequest_BaseRequest, len);\r
- if (request->has_md5_device_type_and_device_id) {\r
- pack_size += epb_length_delimited_pack_size(TAG_AuthRequest_Md5DeviceTypeAndDeviceId, request->md5_device_type_and_device_id.len);\r
- }\r
- pack_size += epb_varint32_pack_size(TAG_AuthRequest_ProtoVersion, request->proto_version, false);\r
- pack_size += epb_varint32_pack_size(TAG_AuthRequest_AuthProto, request->auth_proto, false);\r
- pack_size += epb_varint32_pack_size(TAG_AuthRequest_AuthMethod, request->auth_method, false);\r
- if (request->has_aes_sign) {\r
- pack_size += epb_length_delimited_pack_size(TAG_AuthRequest_AesSign, request->aes_sign.len);\r
- }\r
- if (request->has_mac_address) {\r
- pack_size += epb_length_delimited_pack_size(TAG_AuthRequest_MacAddress, request->mac_address.len);\r
- }\r
- if (request->has_time_zone) {\r
- pack_size += epb_length_delimited_pack_size(TAG_AuthRequest_TimeZone, request->time_zone.len);\r
- }\r
- if (request->has_language) {\r
- pack_size += epb_length_delimited_pack_size(TAG_AuthRequest_Language, request->language.len);\r
- }\r
- if (request->has_device_name) {\r
- pack_size += epb_length_delimited_pack_size(TAG_AuthRequest_DeviceName, request->device_name.len);\r
- }\r
-\r
- return pack_size;\r
-}\r
-\r
-int epb_pack_auth_request(AuthRequest *request, uint8_t *buf, int buf_len)\r
-{\r
- Epb epb;\r
- epb_pack_init(&epb, buf, buf_len);\r
-\r
- int ret;\r
- int tmp_len;\r
- uint8_t *tmp;\r
-\r
- tmp_len = epb_base_request_pack_size(request->base_request);\r
- tmp = (uint8_t *)GKI_getbuf(tmp_len);\r
- ret = epb_pack_base_request(request->base_request, tmp, tmp_len);\r
- if (ret < 0) {\r
- GKI_freebuf(tmp);\r
- return ret;\r
- }\r
- ret = epb_set_message(&epb, TAG_AuthRequest_BaseRequest, tmp, tmp_len);\r
- GKI_freebuf(tmp);\r
- if (ret < 0) return ret;\r
- if (request->has_md5_device_type_and_device_id) {\r
- ret = epb_set_bytes(&epb, TAG_AuthRequest_Md5DeviceTypeAndDeviceId, request->md5_device_type_and_device_id.data, request->md5_device_type_and_device_id.len);\r
- if (ret < 0) return ret;\r
- }\r
- ret = epb_set_int32(&epb, TAG_AuthRequest_ProtoVersion, request->proto_version);\r
- if (ret < 0) return ret;\r
- ret = epb_set_int32(&epb, TAG_AuthRequest_AuthProto, request->auth_proto);\r
- if (ret < 0) return ret;\r
- ret = epb_set_enum(&epb, TAG_AuthRequest_AuthMethod, request->auth_method);\r
- if (ret < 0) return ret;\r
- if (request->has_aes_sign) {\r
- ret = epb_set_bytes(&epb, TAG_AuthRequest_AesSign, request->aes_sign.data, request->aes_sign.len);\r
- if (ret < 0) return ret;\r
- }\r
- if (request->has_mac_address) {\r
- ret = epb_set_bytes(&epb, TAG_AuthRequest_MacAddress, request->mac_address.data, request->mac_address.len);\r
- if (ret < 0) return ret;\r
- }\r
- if (request->has_time_zone) {\r
- ret = epb_set_string(&epb, TAG_AuthRequest_TimeZone, request->time_zone.str, request->time_zone.len);\r
- if (ret < 0) return ret;\r
- }\r
- if (request->has_language) {\r
- ret = epb_set_string(&epb, TAG_AuthRequest_Language, request->language.str, request->language.len);\r
- if (ret < 0) return ret;\r
- }\r
- if (request->has_device_name) {\r
- ret = epb_set_string(&epb, TAG_AuthRequest_DeviceName, request->device_name.str, request->device_name.len);\r
- if (ret < 0) return ret;\r
- }\r
-\r
- return epb_get_packed_size(&epb);\r
-}\r
-\r
-AuthResponse *epb_unpack_auth_response(const uint8_t *buf, int buf_len)\r
-{\r
- Epb epb;\r
- epb_unpack_init(&epb, buf, buf_len);\r
-\r
- const uint8_t *tmp;\r
- int tmp_len;\r
-\r
- if (!epb_has_tag(&epb, TAG_AuthResponse_BaseResponse)) {\r
- return NULL;\r
- }\r
- if (!epb_has_tag(&epb, TAG_AuthResponse_AesSessionKey)) {\r
- return NULL;\r
- }\r
-\r
- AuthResponse *response = (AuthResponse *)GKI_getbuf(sizeof(AuthResponse));\r
- memset(response, 0, sizeof(AuthResponse));\r
- tmp = epb_get_message(&epb, TAG_AuthResponse_BaseResponse, &tmp_len);\r
- response->base_response = epb_unpack_base_response(tmp, tmp_len);\r
- if (response->base_response == NULL) {\r
- GKI_freebuf(response);\r
- return NULL;\r
- }\r
- response->aes_session_key.data = epb_get_bytes(&epb, TAG_AuthResponse_AesSessionKey, &response->aes_session_key.len);\r
-\r
- return response;\r
-}\r
-\r
-void epb_unpack_auth_response_free(AuthResponse *response)\r
-{\r
- epb_unpack_base_response_free(response->base_response);\r
- GKI_freebuf(response);\r
-}\r
-\r
-int epb_init_request_pack_size(InitRequest *request)\r
-{\r
- int pack_size = 0;\r
- int len = 0;\r
-\r
- len = epb_base_request_pack_size(request->base_request);\r
- pack_size += epb_length_delimited_pack_size(TAG_InitRequest_BaseRequest, len);\r
- if (request->has_resp_field_filter) {\r
- pack_size += epb_length_delimited_pack_size(TAG_InitRequest_RespFieldFilter, request->resp_field_filter.len);\r
- }\r
- if (request->has_challenge) {\r
- pack_size += epb_length_delimited_pack_size(TAG_InitRequest_Challenge, request->challenge.len);\r
- }\r
-\r
- return pack_size;\r
-}\r
-\r
-int epb_pack_init_request(InitRequest *request, uint8_t *buf, int buf_len)\r
-{\r
- Epb epb;\r
- epb_pack_init(&epb, buf, buf_len);\r
-\r
- int ret;\r
- int tmp_len;\r
- uint8_t *tmp;\r
-\r
- tmp_len = epb_base_request_pack_size(request->base_request);\r
- tmp = (uint8_t *)GKI_getbuf(tmp_len);\r
- ret = epb_pack_base_request(request->base_request, tmp, tmp_len);\r
- if (ret < 0) {\r
- GKI_freebuf(tmp);\r
- return ret;\r
- }\r
- ret = epb_set_message(&epb, TAG_InitRequest_BaseRequest, tmp, tmp_len);\r
- GKI_freebuf(tmp);\r
- if (ret < 0) return ret;\r
- if (request->has_resp_field_filter) {\r
- ret = epb_set_bytes(&epb, TAG_InitRequest_RespFieldFilter, request->resp_field_filter.data, request->resp_field_filter.len);\r
- if (ret < 0) return ret;\r
- }\r
- if (request->has_challenge) {\r
- ret = epb_set_bytes(&epb, TAG_InitRequest_Challenge, request->challenge.data, request->challenge.len);\r
- if (ret < 0) return ret;\r
- }\r
-\r
- return epb_get_packed_size(&epb);\r
-}\r
-\r
-InitResponse *epb_unpack_init_response(const uint8_t *buf, int buf_len)\r
-{\r
- Epb epb;\r
- epb_unpack_init(&epb, buf, buf_len);\r
-\r
- const uint8_t *tmp;\r
- int tmp_len;\r
-\r
- if (!epb_has_tag(&epb, TAG_InitResponse_BaseResponse)) {\r
- return NULL;\r
- }\r
- if (!epb_has_tag(&epb, TAG_InitResponse_UserIdHigh)) {\r
- return NULL;\r
- }\r
- if (!epb_has_tag(&epb, TAG_InitResponse_UserIdLow)) {\r
- return NULL;\r
- }\r
-\r
- InitResponse *response = (InitResponse *)GKI_getbuf(sizeof(InitResponse));\r
- memset(response, 0, sizeof(InitResponse));\r
- tmp = epb_get_message(&epb, TAG_InitResponse_BaseResponse, &tmp_len);\r
- response->base_response = epb_unpack_base_response(tmp, tmp_len);\r
- if (response->base_response == NULL) {\r
- GKI_freebuf(response);\r
- return NULL;\r
- }\r
- response->user_id_high = epb_get_uint32(&epb, TAG_InitResponse_UserIdHigh);\r
- response->user_id_low = epb_get_uint32(&epb, TAG_InitResponse_UserIdLow);\r
- if (epb_has_tag(&epb, TAG_InitResponse_ChalleangeAnswer)) {\r
- response->challeange_answer = epb_get_uint32(&epb, TAG_InitResponse_ChalleangeAnswer);\r
- response->has_challeange_answer = true;\r
- }\r
- if (epb_has_tag(&epb, TAG_InitResponse_InitScence)) {\r
- response->init_scence = (EmInitScence)epb_get_enum(&epb, TAG_InitResponse_InitScence);\r
- response->has_init_scence = true;\r
- }\r
- if (epb_has_tag(&epb, TAG_InitResponse_AutoSyncMaxDurationSecond)) {\r
- response->auto_sync_max_duration_second = epb_get_uint32(&epb, TAG_InitResponse_AutoSyncMaxDurationSecond);\r
- response->has_auto_sync_max_duration_second = true;\r
- }\r
- if (epb_has_tag(&epb, TAG_InitResponse_UserNickName)) {\r
- response->user_nick_name.str = epb_get_string(&epb, TAG_InitResponse_UserNickName, &response->user_nick_name.len);\r
- response->has_user_nick_name = true;\r
- }\r
- if (epb_has_tag(&epb, TAG_InitResponse_PlatformType)) {\r
- response->platform_type = (EmPlatformType)epb_get_enum(&epb, TAG_InitResponse_PlatformType);\r
- response->has_platform_type = true;\r
- }\r
- if (epb_has_tag(&epb, TAG_InitResponse_Model)) {\r
- response->model.str = epb_get_string(&epb, TAG_InitResponse_Model, &response->model.len);\r
- response->has_model = true;\r
- }\r
- if (epb_has_tag(&epb, TAG_InitResponse_Os)) {\r
- response->os.str = epb_get_string(&epb, TAG_InitResponse_Os, &response->os.len);\r
- response->has_os = true;\r
- }\r
- if (epb_has_tag(&epb, TAG_InitResponse_Time)) {\r
- response->time = epb_get_int32(&epb, TAG_InitResponse_Time);\r
- response->has_time = true;\r
- }\r
- if (epb_has_tag(&epb, TAG_InitResponse_TimeZone)) {\r
- response->time_zone = epb_get_int32(&epb, TAG_InitResponse_TimeZone);\r
- response->has_time_zone = true;\r
- }\r
- if (epb_has_tag(&epb, TAG_InitResponse_TimeString)) {\r
- response->time_string.str = epb_get_string(&epb, TAG_InitResponse_TimeString, &response->time_string.len);\r
- response->has_time_string = true;\r
- }\r
-\r
- return response;\r
-}\r
-\r
-void epb_unpack_init_response_free(InitResponse *response)\r
-{\r
- epb_unpack_base_response_free(response->base_response);\r
- GKI_freebuf((void *)response);\r
-}\r
-\r
-int epb_send_data_request_pack_size(SendDataRequest *request)\r
-{\r
- int pack_size = 0;\r
- int len = 0;\r
-\r
- len = epb_base_request_pack_size(request->base_request);\r
- pack_size += epb_length_delimited_pack_size(TAG_SendDataRequest_BaseRequest, len);\r
- pack_size += epb_length_delimited_pack_size(TAG_SendDataRequest_Data, request->data.len);\r
- if (request->has_type) {\r
- pack_size += epb_varint32_pack_size(TAG_SendDataRequest_Type, request->type, false);\r
- }\r
-\r
- return pack_size;\r
-}\r
-\r
-int epb_pack_send_data_request(SendDataRequest *request, uint8_t *buf, int buf_len)\r
-{\r
- Epb epb;\r
- epb_pack_init(&epb, buf, buf_len);\r
-\r
- int ret;\r
- int tmp_len;\r
- uint8_t *tmp;\r
-\r
- tmp_len = epb_base_request_pack_size(request->base_request);\r
- tmp = (uint8_t *)GKI_getbuf(tmp_len);\r
- ret = epb_pack_base_request(request->base_request, tmp, tmp_len);\r
- if (ret < 0) {\r
- GKI_freebuf(tmp);\r
- return ret;\r
- }\r
- ret = epb_set_message(&epb, TAG_SendDataRequest_BaseRequest, tmp, tmp_len);\r
- GKI_freebuf(tmp);\r
- if (ret < 0) return ret;\r
- ret = epb_set_bytes(&epb, TAG_SendDataRequest_Data, request->data.data, request->data.len);\r
- if (ret < 0) return ret;\r
- if (request->has_type) {\r
- ret = epb_set_enum(&epb, TAG_SendDataRequest_Type, request->type);\r
- if (ret < 0) return ret;\r
- }\r
-\r
- return epb_get_packed_size(&epb);\r
-}\r
-\r
-SendDataResponse *epb_unpack_send_data_response(const uint8_t *buf, int buf_len)\r
-{\r
- Epb epb;\r
- epb_unpack_init(&epb, buf, buf_len);\r
-\r
- const uint8_t *tmp;\r
- int tmp_len;\r
-\r
- if (!epb_has_tag(&epb, TAG_SendDataResponse_BaseResponse)) {\r
- return NULL;\r
- }\r
-\r
- SendDataResponse *response = (SendDataResponse *)GKI_getbuf(sizeof(SendDataResponse));\r
- memset(response, 0, sizeof(SendDataResponse));\r
- tmp = epb_get_message(&epb, TAG_SendDataResponse_BaseResponse, &tmp_len);\r
- response->base_response = epb_unpack_base_response(tmp, tmp_len);\r
- if (response->base_response == NULL) {\r
- GKI_freebuf(response);\r
- return NULL;\r
- }\r
- if (epb_has_tag(&epb, TAG_SendDataResponse_Data)) {\r
- response->data.data = epb_get_bytes(&epb, TAG_SendDataResponse_Data, &response->data.len);\r
- response->has_data = true;\r
- }\r
-\r
- return response;\r
-}\r
-\r
-void epb_unpack_send_data_response_free(SendDataResponse *response)\r
-{\r
- epb_unpack_base_response_free(response->base_response);\r
- GKI_freebuf(response);\r
-}\r
-\r
-RecvDataPush *epb_unpack_recv_data_push(const uint8_t *buf, int buf_len)\r
-{\r
- Epb epb;\r
- epb_unpack_init(&epb, buf, buf_len);\r
-\r
- const uint8_t *tmp;\r
- int tmp_len;\r
-\r
- if (!epb_has_tag(&epb, TAG_RecvDataPush_BasePush)) {\r
- return NULL;\r
- }\r
- if (!epb_has_tag(&epb, TAG_RecvDataPush_Data)) {\r
- return NULL;\r
- }\r
-\r
- RecvDataPush *push = (RecvDataPush *)GKI_getbuf(sizeof(RecvDataPush));\r
- memset(push, 0, sizeof(RecvDataPush));\r
- tmp = epb_get_message(&epb, TAG_RecvDataPush_BasePush, &tmp_len);\r
- push->base_push = epb_unpack_base_push(tmp, tmp_len);\r
- if (push->base_push == NULL) {\r
- GKI_freebuf(push);\r
- return NULL;\r
- }\r
- push->data.data = epb_get_bytes(&epb, TAG_RecvDataPush_Data, &push->data.len);\r
- if (epb_has_tag(&epb, TAG_RecvDataPush_Type)) {\r
- push->type = (EmDeviceDataType)epb_get_enum(&epb, TAG_RecvDataPush_Type);\r
- push->has_type = true;\r
- }\r
-\r
- return push;\r
-}\r
-\r
-void epb_unpack_recv_data_push_free(RecvDataPush *push)\r
-{\r
- epb_unpack_base_push_free(push->base_push);\r
- push->base_push = NULL;\r
- GKI_freebuf(push);\r
-}\r
-\r
-SwitchViewPush *epb_unpack_switch_view_push(const uint8_t *buf, int buf_len)\r
-{\r
- Epb epb;\r
- epb_unpack_init(&epb, buf, buf_len);\r
-\r
- const uint8_t *tmp;\r
- int tmp_len;\r
-\r
- if (!epb_has_tag(&epb, TAG_SwitchViewPush_BasePush)) {\r
- return NULL;\r
- }\r
- if (!epb_has_tag(&epb, TAG_SwitchViewPush_SwitchViewOp)) {\r
- return NULL;\r
- }\r
- if (!epb_has_tag(&epb, TAG_SwitchViewPush_ViewId)) {\r
- return NULL;\r
- }\r
-\r
- SwitchViewPush *push = (SwitchViewPush *)GKI_getbuf(sizeof(SwitchViewPush));\r
- memset(push, 0, sizeof(SwitchViewPush));\r
- tmp = epb_get_message(&epb, TAG_SwitchViewPush_BasePush, &tmp_len);\r
- push->base_push = epb_unpack_base_push(tmp, tmp_len);\r
- if (push->base_push == NULL) {\r
- GKI_freebuf(push);\r
- return NULL;\r
- }\r
- push->switch_view_op = (EmSwitchViewOp)epb_get_enum(&epb, TAG_SwitchViewPush_SwitchViewOp);\r
- push->view_id = (EmViewId)epb_get_enum(&epb, TAG_SwitchViewPush_ViewId);\r
-\r
- return push;\r
-}\r
-\r
-void epb_unpack_switch_view_push_free(SwitchViewPush *push)\r
-{\r
- epb_unpack_base_push_free(push->base_push);\r
- GKI_freebuf(push);\r
-}\r
-\r
-SwitchBackgroudPush *epb_unpack_switch_backgroud_push(const uint8_t *buf, int buf_len)\r
-{\r
- Epb epb;\r
- epb_unpack_init(&epb, buf, buf_len);\r
-\r
- const uint8_t *tmp;\r
- int tmp_len;\r
-\r
- if (!epb_has_tag(&epb, TAG_SwitchBackgroudPush_BasePush)) {\r
- return NULL;\r
- }\r
- if (!epb_has_tag(&epb, TAG_SwitchBackgroudPush_SwitchBackgroundOp)) {\r
- return NULL;\r
- }\r
-\r
- SwitchBackgroudPush *push = (SwitchBackgroudPush *)GKI_getbuf(sizeof(SwitchBackgroudPush));\r
- memset(push, 0, sizeof(SwitchBackgroudPush));\r
- tmp = epb_get_message(&epb, TAG_SwitchBackgroudPush_BasePush, &tmp_len);\r
- push->base_push = epb_unpack_base_push(tmp, tmp_len);\r
- if (push->base_push == NULL) {\r
- GKI_freebuf(push);\r
- return NULL;\r
- }\r
- push->switch_background_op = (EmSwitchBackgroundOp)epb_get_enum(&epb, TAG_SwitchBackgroudPush_SwitchBackgroundOp);\r
-\r
- return push;\r
-}\r
-\r
-void epb_unpack_switch_backgroud_push_free(SwitchBackgroudPush *push)\r
-{\r
- epb_unpack_base_push_free(push->base_push);\r
- GKI_freebuf(push);\r
-}\r
-\r
-#endif ///WX_AIRSYNC_CFG\r
-\r
+++ /dev/null
-/*\r
-* WeChat mpbledemo2 \r
-*\r
-* author by anqiren 2014/12/02 V1.0bat\r
-*\r
-**/\r
-\r
-#include "prf_defs.h"\r
-\r
-#if (WX_AIRSYNC_CFG)\r
-\r
-#include <string.h>\r
-#include <stdlib.h>\r
-#include <stdint.h>\r
-#include <stdio.h>\r
-#include "app_airsync_prf.h"\r
-#include "wechat_aes.h"\r
-#include "epb_MmBp.h"\r
-#include "wechar_crc.h"\r
-#include "app_wechat_util.h"\r
-#include "app_airsync_md5.h"\r
-#include "mpbledemo2.h"\r
-#include "gki.h"\r
-\r
-\r
-mpbledemo2_info m_info = {CMD_NULL, {NULL, 0}};\r
-\r
-#if defined EAM_md5AndNoEnrypt || EAM_md5AndAesEnrypt\r
- uint8_t md5_type_and_id[16];\r
-#endif\r
-\r
-uint8_t challeange[CHALLENAGE_LENGTH] = {0x11,0x22,0x33,0x44}; //ΪÁË·½±ãÕâÀïÌîÁËÒ»×éÈ·¶¨µÄÊý×飬ʹÓùý³ÌÖÐÇë×ÔÐÐÉú³ÉËæ»úÊý\r
-\r
-mpbledemo2_state mpbledemo2Sta = {false, false, false, false, false, false,0,0,0};\r
-const uint8_t key[16] = DEVICE_KEY;\r
-uint8_t session_key[32] = {0};\r
-data_handler *m_mpbledemo2_handler = NULL;\r
-uint8_t isLightOn;\r
-/**** NOTIFICATION BITS ***********/\r
-uint8_t FirstNotificationBit ;\r
-uint8_t SecondNotificationBit;\r
-\r
-\r
-//static void mpbledemo2_handleCmdFromServer(BleDemo2CmdID cmd, uint8_t *ptrData, uint32_t lengthInByte);\r
-\r
-/**@brief Function for the light initialization.\r
- *\r
- * @details Initializes all lights used by this application.\r
- */\r
-\r
-int32_t mpbledemo2_get_md5(void)\r
-{\r
- int32_t error_code = 0;\r
-#if defined EAM_md5AndNoEnrypt || EAM_md5AndAesEnrypt\r
- char device_type[] = DEVICE_TYPE;\r
- char device_id[] = DEVICE_ID;\r
- char argv[sizeof(DEVICE_TYPE) + sizeof(DEVICE_ID) - 1];\r
- memcpy(argv,device_type,sizeof(DEVICE_TYPE));\r
-/*when add the DEVICE_ID to DEVICE_TYPE, the offset shuld -1 to overwrite '\0' at the end of DEVICE_TYPE */\r
- memcpy(argv + sizeof(DEVICE_TYPE)-1,device_id,sizeof(DEVICE_ID));\r
-\r
- error_code = wechat_md5(argv, md5_type_and_id);\r
-\r
-#endif\r
- return error_code;\r
-}\r
-\r
-void mpbledemo2_reset()\r
-{\r
- mpbledemo2Sta.auth_send = false;\r
- mpbledemo2Sta.auth_state = false;\r
- mpbledemo2Sta.indication_state = false;\r
- mpbledemo2Sta.init_send = false;\r
- mpbledemo2Sta.init_state = false;\r
- mpbledemo2Sta.send_data_seq = 0;\r
- mpbledemo2Sta.push_data_seq = 0;\r
- mpbledemo2Sta.seq = 0;\r
-}\r
- \r
-int32_t mpbledemo2_init(void)\r
-{\r
- mpbledemo2_reset();\r
- return (mpbledemo2_get_md5());\r
-}\r
-\r
-\r
-void mpbledemo2_indication_state(bool isEnable)\r
-{\r
- mpbledemo2Sta.indication_state = isEnable;\r
- if (false == isEnable)\r
- {\r
- mpbledemo2Sta.auth_send = false;\r
- }\r
-}\r
-\r
-int32_t device_auth()\r
-{ \r
- if (m_mpbledemo2_handler == NULL) {\r
- m_mpbledemo2_handler = get_handler_by_type(PRODUCT_TYPE_MPBLEDEMO2);\r
- }\r
- uint8_t *data = NULL;\r
- uint32_t len = 0;\r
- \r
- ARGS_ITEM_SET(mpbledemo2_info, m_mpbledemo2_handler->m_data_produce_args, cmd, CMD_AUTH); \r
- m_mpbledemo2_handler->m_data_produce_func(m_mpbledemo2_handler->m_data_produce_args, &data, &len);\r
- if(data == NULL)\r
- {\r
- return errorCodeProduce;\r
- }\r
- \r
- //sent data\r
- ble_wechat_indicate_data(data, len);\r
- return 0;\r
- }\r
- \r
-\r
-int32_t device_init()\r
- {\r
- uint8_t *data = NULL;\r
- uint32_t len = 0;\r
- ARGS_ITEM_SET(mpbledemo2_info, m_mpbledemo2_handler->m_data_produce_args, cmd, CMD_INIT);\r
- m_mpbledemo2_handler->m_data_produce_func(m_mpbledemo2_handler->m_data_produce_args, &data, &len);\r
- if(data == NULL)\r
- {\r
- return errorCodeProduce;\r
- }\r
- \r
- //sent data\r
- ble_wechat_indicate_data(data, len);\r
- \r
- return 0;\r
-}\r
-\r
-void mpbledemo2_main_process()\r
-{\r
- int error_code = 0;\r
- if((mpbledemo2Sta.indication_state) && (!mpbledemo2Sta.auth_state) && (!mpbledemo2Sta.auth_send) )\r
- {\r
- error_code = device_auth();\r
- if (0 == error_code)\r
- {\r
- mpbledemo2Sta.auth_send = true; \r
- }\r
- }\r
- if((mpbledemo2Sta.auth_state) && (!mpbledemo2Sta.init_state) && (!mpbledemo2Sta.init_send))\r
- {\r
- error_code = device_init();\r
- if (0 == error_code)\r
- {\r
- mpbledemo2Sta.init_send = true; \r
- }\r
- }\r
-}\r
-\r
-void mpbledemo2_data_free_func(uint8_t *data, uint32_t len)\r
-{\r
- if(data)\r
- {\r
- GKI_freebuf(data);\r
- data = NULL;\r
- }\r
-}\r
-\r
-void mpbledemo2_data_produce_func(void *args, uint8_t **r_data, uint32_t *r_len)\r
-{ \r
- static uint16_t bleDemoHeadLen = sizeof(BlueDemoHead);\r
- mpbledemo2_info *info = (mpbledemo2_info *)args;\r
- BaseRequest basReq = {NULL};\r
- static uint8_t fix_head_len = sizeof(BpFixHead);\r
- BpFixHead fix_head = {0xFE, 1, 0, htons(ECI_req_auth), 0};\r
- mpbledemo2Sta.seq++;\r
- switch (info->cmd)\r
- {\r
- case CMD_AUTH:\r
- {\r
- #if defined EAM_md5AndAesEnrypt\r
- uint8_t deviceid[] = DEVICE_ID;\r
- static uint32_t seq = 0x00000001; //\r
- uint32_t ran = 0x11223344; //ΪÁË·½±ãÆð¼ûÕâÀï·ÅÁËÒ»¸ö¹Ì¶¨Öµ×öΪËæ»úÊý£¬ÔÚʹÓÃʱÇë×ÔÐÐÉú³ÉËæ»úÊý¡£\r
- ran = t_htonl(ran);\r
- seq = t_htonl(seq);\r
- uint8_t id_len = strlen(DEVICE_ID);\r
- uint8_t* data = GKI_getbuf(id_len+8);\r
- if(!data){return;}\r
- memcpy(data,deviceid,id_len);\r
- memcpy(data+id_len,(uint8_t*)&ran,4);\r
- memcpy(data+id_len+4,(uint8_t*)&seq,4);\r
- uint32_t crc = crc32(0, data, id_len+8);\r
- crc = t_htonl(crc);\r
- memset(data,0x00,id_len+8);\r
- memcpy(data,(uint8_t*)&ran,4);\r
- memcpy(data+4,(uint8_t*)&seq,4);\r
- memcpy(data+8,(uint8_t*)&crc,4); \r
- uint8_t CipherText[16];\r
- AES_Init(key);\r
- AES_Encrypt_PKCS7 (data, CipherText, 12, key);\r
- if(data){GKI_freebuf(data);data = NULL;}\r
- AuthRequest authReq = {&basReq, true,{md5_type_and_id, MD5_TYPE_AND_ID_LENGTH}, \r
- PROTO_VERSION, AUTH_PROTO, (EmAuthMethod)AUTH_METHOD, true ,\r
- {CipherText, CIPHER_TEXT_LENGTH}, false, {NULL, 0}, false, {NULL, 0}, false, \r
- {NULL, 0},true,{DEVICE_ID,sizeof(DEVICE_ID)}};\r
- seq++;\r
- #endif\r
- \r
- #if defined EAM_macNoEncrypt\r
- static uint8_t mac_address[MAC_ADDRESS_LENGTH];\r
- //get_mac_addr(mac_address);\r
- AuthRequest authReq = {&basReq, false,{NULL, 0}, PROTO_VERSION, AUTH_PROTO, (EmAuthMethod)AUTH_METHOD, false,{NULL, 0}, true, {mac_address, MAC_ADDRESS_LENGTH}, false, {NULL, 0}, false, {NULL, 0},true,{DEVICE_ID,sizeof(DEVICE_ID)}};\r
- #endif\r
- \r
- #if defined EAM_md5AndNoEnrypt\r
- AuthRequest authReq = {&basReq, true,{md5_type_and_id, MD5_TYPE_AND_ID_LENGTH}, PROTO_VERSION, (EmAuthMethod)AUTH_PROTO, (EmAuthMethod)AUTH_METHOD, false ,{NULL, 0}, false, {NULL, 0}, false, {NULL, 0}, false, {NULL, 0},true,{DEVICE_ID,sizeof(DEVICE_ID)}};\r
- #endif\r
- *r_len = epb_auth_request_pack_size(&authReq) + fix_head_len;\r
- *r_data = (uint8_t *)GKI_getbuf(*r_len);\r
- if(!(*r_data)){return;}\r
- if(epb_pack_auth_request(&authReq, *r_data+fix_head_len, *r_len-fix_head_len)<0)\r
- {\r
- *r_data = NULL;\r
- return;\r
- }\r
- fix_head.nCmdId = htons(ECI_req_auth);\r
- fix_head.nLength = htons(*r_len);\r
- fix_head.nSeq = htons(mpbledemo2Sta.seq);\r
- memcpy(*r_data, &fix_head, fix_head_len); \r
- return ;\r
- }\r
- case CMD_INIT:\r
- {\r
- //has challeange\r
- InitRequest initReq = {&basReq,false, {NULL, 0},true, {challeange, CHALLENAGE_LENGTH}};\r
- *r_len = epb_init_request_pack_size(&initReq) + fix_head_len;\r
- #if defined EAM_md5AndAesEnrypt\r
- uint8_t length = *r_len; \r
- uint8_t *p = GKI_getbuf(AES_get_length( *r_len-fix_head_len));\r
- if(!p){return;}\r
- *r_len = AES_get_length( *r_len-fix_head_len)+fix_head_len;\r
- #endif\r
- //pack data\r
- *r_data = (uint8_t *)GKI_getbuf(*r_len);\r
- if(!(*r_data)){return;}\r
- if(epb_pack_init_request(&initReq, *r_data+fix_head_len, *r_len-fix_head_len)<0)\r
- {*r_data = NULL;return;}\r
- //encrypt body\r
- #if defined EAM_md5AndAesEnrypt\r
- AES_Init(session_key);\r
- AES_Encrypt_PKCS7(*r_data+fix_head_len,p,length-fix_head_len,session_key);//ÔʼÊý¾Ý³¤¶È\r
- memcpy(*r_data + fix_head_len, p, *r_len-fix_head_len);\r
- if(p)GKI_freebuf(p);\r
- #endif\r
- fix_head.nCmdId = htons(ECI_req_init);\r
- fix_head.nLength = htons(*r_len);\r
- fix_head.nSeq = htons(mpbledemo2Sta.seq);\r
- memcpy(*r_data, &fix_head, fix_head_len);\r
- return ;\r
- }\r
- case CMD_SENDDAT:\r
- {\r
- \r
- BlueDemoHead *bleDemoHead = (BlueDemoHead*)GKI_getbuf(bleDemoHeadLen+info->send_msg.len);\r
- if (!bleDemoHead)\r
- {\r
- return;\r
- }\r
- \r
- // header of sent data\r
- bleDemoHead->m_magicCode[0] = MPBLEDEMO2_MAGICCODE_H;\r
- bleDemoHead->m_magicCode[1] = MPBLEDEMO2_MAGICCODE_L;\r
- bleDemoHead->m_version = htons(MPBLEDEMO2_VERSION);\r
- bleDemoHead->m_totalLength = htons(bleDemoHeadLen + info->send_msg.len);\r
- bleDemoHead->m_cmdid = htons(sendTextReq);\r
- bleDemoHead->m_seq = htons(mpbledemo2Sta.seq);\r
- bleDemoHead->m_errorCode = 0; \r
- \r
- /*connect body and head.*/\r
- /*turn to uint8_t* befort offset.*/\r
- memcpy((uint8_t*)bleDemoHead + bleDemoHeadLen, info->send_msg.str, info->send_msg.len); \r
- \r
- SendDataRequest sendDatReq = \r
- {\r
- &basReq, \r
- { (uint8_t*) bleDemoHead, (bleDemoHeadLen + info->send_msg.len)}, // define the data content wrapped in epb\r
- false, // no type, the data is directly sent to vendor server\r
- (EmDeviceDataType)NULL\r
- };\r
- *r_len = epb_send_data_request_pack_size(&sendDatReq) + fix_head_len;\r
- \r
- #if defined EAM_md5AndAesEnrypt\r
- uint16_t length = *r_len;\r
- uint8_t *p = GKI_getbuf(AES_get_length( *r_len-fix_head_len));\r
- if(!p){return;}\r
- *r_len = AES_get_length( *r_len-fix_head_len)+fix_head_len;\r
- #endif\r
- \r
- *r_data = (uint8_t *)GKI_getbuf(*r_len);\r
- if(!(*r_data)){return;}\r
- if(epb_pack_send_data_request(&sendDatReq, *r_data+fix_head_len, *r_len-fix_head_len)<0)\r
- {\r
- *r_data = NULL;\r
- #if defined EAM_md5AndAesEnrypt\r
- if(p){GKI_freebuf(p);\r
- p = NULL;}\r
- #endif\r
- return;\r
- }\r
- \r
- #if defined EAM_md5AndAesEnrypt\r
- //encrypt body\r
- AES_Init(session_key);\r
- AES_Encrypt_PKCS7(*r_data+fix_head_len,p,length-fix_head_len,session_key);//ÔʼÊý¾Ý³¤¶È\r
- memcpy(*r_data + fix_head_len, p, *r_len-fix_head_len);\r
- if(p){GKI_freebuf(p); p = NULL;}\r
- #endif\r
- \r
- // header of epb\r
- fix_head.nCmdId = htons(ECI_req_sendData);\r
- fix_head.nLength = htons(*r_len);\r
- fix_head.nSeq = htons(mpbledemo2Sta.seq);\r
- \r
- memcpy(*r_data, &fix_head, fix_head_len);\r
- if(bleDemoHead){GKI_freebuf(bleDemoHead);bleDemoHead = NULL;}\r
- \r
- // increase sequence by 1\r
- mpbledemo2Sta.send_data_seq++; \r
- return ;\r
- }\r
- } \r
-}\r
-\r
-int mpbledemo2_data_consume_func(uint8_t *data, uint32_t len)\r
-{\r
- BpFixHead *fix_head = (BpFixHead *)data;\r
- uint8_t fix_head_len = sizeof(BpFixHead);\r
- switch(ntohs(fix_head->nCmdId))\r
- {\r
- case ECI_none:\r
- {\r
-\r
-\r
- }\r
- break;\r
- case ECI_resp_auth:\r
- {\r
- AuthResponse* authResp;\r
- authResp = epb_unpack_auth_response(data+fix_head_len,len-fix_head_len);\r
- if(authResp->base_response)\r
- {\r
- if(authResp->base_response->err_code == 0)\r
- {\r
- mpbledemo2Sta.auth_state = true;\r
- }\r
- else\r
- {\r
- int32_t returnedErrCode = authResp->base_response->err_code;\r
- epb_unpack_auth_response_free(authResp);\r
- return returnedErrCode;\r
- }\r
- }\r
- #if defined EAM_md5AndAesEnrypt // get sessionkey\r
- if(authResp->aes_session_key.len)\r
- {\r
- AES_Init(key);\r
- AES_Decrypt(session_key,authResp->aes_session_key.data,authResp->aes_session_key.len,key);\r
- }\r
- #endif\r
- epb_unpack_auth_response_free(authResp);\r
- }\r
- break;\r
- case ECI_resp_sendData:\r
- {\r
- \r
- #if defined EAM_md5AndAesEnrypt \r
- uint32_t length = len- fix_head_len;//¼ÓÃܺóÊý¾Ý³¤¶È\r
- uint8_t *p = GKI_getbuf (length);\r
- if(!p){ if(data)GKI_freebuf(data);data = NULL; return 0;}\r
- AES_Init(session_key);\r
- //½âÃÜÊý¾Ý\r
- AES_Decrypt(p,data+fix_head_len,len- fix_head_len,session_key);\r
- \r
- uint8_t temp;\r
- temp = p[length - 1];//Ëã³öÌî³ä³¤¶È\r
- len = len - temp;//È¡¼ÓÃÜÇ°Êý¾Ý×ܳ¤¶È\r
- memcpy(data + fix_head_len, p ,length -temp);//°ÑÃ÷ÎÄ·Å»Ø\r
- if(p){GKI_freebuf(p);p = NULL;}\r
- #endif \r
- SendDataResponse *sendDataResp;\r
- sendDataResp = epb_unpack_send_data_response(data+fix_head_len,len-fix_head_len);\r
- if (!sendDataResp)\r
- {\r
- return errorCodeUnpackSendDataResp;\r
- }\r
-\r
- if(sendDataResp->base_response->err_code)\r
- {\r
- epb_unpack_send_data_response_free(sendDataResp);\r
- return sendDataResp->base_response->err_code;\r
- }\r
- epb_unpack_send_data_response_free(sendDataResp);\r
- }\r
- break;\r
- case ECI_resp_init:\r
- {\r
- FirstNotificationBit = 0;\r
- SecondNotificationBit = 0; \r
- \r
- #if defined EAM_md5AndAesEnrypt \r
- uint32_t length = len- fix_head_len; //¼ÓÃܺóÊý¾Ý³¤¶È\r
- uint8_t *p = GKI_getbuf (length);\r
- if(!p){if(data)GKI_freebuf(data);data = NULL; return 0;}\r
- AES_Init(session_key);\r
- //½âÃÜÊý¾Ý\r
- AES_Decrypt(p,data+fix_head_len,len- fix_head_len,session_key);\r
- \r
- uint8_t temp;\r
- temp = p[length - 1]; //Ëã³öÌî³ä³¤¶È\r
- len = len - temp; //È¡¼ÓÃÜÇ°Êý¾Ý×ܳ¤¶È\r
- memcpy(data + fix_head_len, p ,length -temp); //°ÑÃ÷ÎÄ·Å»Ø\r
- if(p){GKI_freebuf(p);p = NULL;}\r
- #endif \r
- InitResponse *initResp = epb_unpack_init_response(data+fix_head_len, len-fix_head_len);\r
- if(!initResp)\r
- {\r
- return errorCodeUnpackInitResp;\r
- }\r
- \r
- if(initResp->base_response)\r
- {\r
- if(initResp->base_response->err_code == 0)\r
- {\r
- if(initResp->has_challeange_answer)\r
- {\r
- if(crc32(0,challeange,CHALLENAGE_LENGTH) == initResp->challeange_answer)\r
- {\r
- mpbledemo2Sta.init_state = true;\r
- }\r
- }\r
- else mpbledemo2Sta.init_state = true;\r
- mpbledemo2Sta.wechats_switch_state = true;\r
- }\r
- else\r
- {\r
- epb_unpack_init_response_free(initResp);\r
- return initResp->base_response->err_code;\r
- }\r
- }\r
- epb_unpack_init_response_free(initResp);\r
- }\r
- break;\r
- case ECI_push_recvData:\r
- {\r
- #if defined EAM_md5AndAesEnrypt\r
- uint32_t length = len- fix_head_len;//¼ÓÃܺóÊý¾Ý³¤¶È\r
- uint8_t *p = GKI_getbuf (length);\r
- if(!p){if(data)GKI_freebuf(data); data =NULL; return 0;}\r
- AES_Init(session_key);\r
- //½âÃÜÊý¾Ý\r
- AES_Decrypt(p,data+fix_head_len,len- fix_head_len,session_key);\r
- \r
- uint8_t temp;\r
- temp = p[length - 1];//Ëã³öÌî³ä³¤¶È\r
- len = len - temp;//È¡¼ÓÃÜÇ°Êý¾Ý×ܳ¤¶È\r
- memcpy(data + fix_head_len, p ,length -temp);//°ÑÃ÷ÎÄ·Å»Ø\r
- if(p){GKI_freebuf(p);p = NULL;}\r
- #endif\r
- RecvDataPush *recvDatPush;\r
- recvDatPush = epb_unpack_recv_data_push(data+fix_head_len, len-fix_head_len);\r
- \r
- if(!recvDatPush)\r
- {\r
- return errorCodeUnpackRecvDataPush;\r
- }\r
- \r
- BlueDemoHead *bledemohead = (BlueDemoHead*)recvDatPush->data.data;\r
- \r
- \r
- // ble demo command handle\r
- \r
- epb_unpack_recv_data_push_free(recvDatPush);\r
- mpbledemo2Sta.push_data_seq++;\r
- }\r
- break;\r
- case ECI_push_switchView:\r
- {\r
- \r
- mpbledemo2Sta.wechats_switch_state = !mpbledemo2Sta.wechats_switch_state;\r
- \r
- #if defined EAM_md5AndAesEnrypt \r
- uint32_t length = len- fix_head_len;//¼ÓÃܺóÊý¾Ý³¤¶È\r
- uint8_t *p = GKI_getbuf (length);\r
- if(!p){if(data)GKI_freebuf(data);data = NULL; return 0;}\r
- AES_Init(session_key);\r
- //½âÃÜÊý¾Ý\r
- AES_Decrypt(p,data+fix_head_len,len- fix_head_len,session_key);\r
- \r
- uint8_t temp;\r
- temp = p[length - 1];//Ëã³öÌî³ä³¤¶È\r
- len = len - temp;//È¡¼ÓÃÜÇ°Êý¾Ý×ܳ¤¶È\r
- memcpy(data + fix_head_len, p ,length -temp);//°ÑÃ÷ÎÄ·Å»Ø\r
- if(p){GKI_freebuf(p);p = NULL;}\r
- #endif \r
- SwitchViewPush *swichViewPush;\r
- swichViewPush = epb_unpack_switch_view_push(data+fix_head_len,len-fix_head_len);\r
- if(!swichViewPush)\r
- {\r
- return errorCodeUnpackSwitchViewPush;\r
- }\r
- epb_unpack_switch_view_push_free(swichViewPush);\r
- }\r
- break;\r
- case ECI_push_switchBackgroud:\r
- {\r
- \r
- #if defined EAM_md5AndAesEnrypt\r
- uint32_t length = len- fix_head_len;//¼ÓÃܺóÊý¾Ý³¤¶È\r
- uint8_t *p = GKI_getbuf (length);\r
- if(!p){if(data)GKI_freebuf(data);data = NULL; return 0;}\r
- AES_Init(session_key);\r
- //½âÃÜÊý¾Ý\r
- AES_Decrypt(p,data+fix_head_len,len- fix_head_len,session_key);\r
- uint8_t temp;\r
- temp = p[length - 1];//Ëã³öÌî³ä³¤¶È\r
- len = len - temp;//È¡¼ÓÃÜÇ°Êý¾Ý×ܳ¤¶È\r
- memcpy(data + fix_head_len, p ,length -temp);//°ÑÃ÷ÎÄ·Å»Ø\r
- if(data){GKI_freebuf(p);p = NULL;}\r
- #endif\r
- SwitchBackgroudPush *switchBackgroundPush = epb_unpack_switch_backgroud_push(data+fix_head_len,len-fix_head_len);\r
- if(! switchBackgroundPush)\r
- {\r
- return errorCodeUnpackSwitchBackgroundPush;\r
- } \r
- epb_unpack_switch_backgroud_push_free(switchBackgroundPush);\r
- }\r
- break;\r
- case ECI_err_decode:\r
- break;\r
- default:\r
- {\r
- \r
- }\r
- break;\r
- }\r
- return 0;\r
-}\r
-void mpbledemo2_data_error_func(int error_code)\r
-{\r
- if(error_code)\r
- {\r
- \r
- //NVIC_SystemReset();\r
- }\r
-}\r
-\r
-data_handler mpbledemo2_data_handler = {\r
- .m_product_type = PRODUCT_TYPE_MPBLEDEMO2,\r
- .m_data_produce_func = &mpbledemo2_data_produce_func,\r
- .m_data_free_func = &mpbledemo2_data_free_func,\r
- .m_data_consume_func = &mpbledemo2_data_consume_func,\r
- .m_data_error_func = &mpbledemo2_data_error_func,\r
- .m_data_init_peripheral_func = NULL,\r
- .m_data_init_func = &mpbledemo2_init,\r
- .m_data_main_process_func = &mpbledemo2_main_process,\r
- .m_data_button_handler_func = NULL,\r
- .m_data_produce_args = &m_info,\r
- .next = NULL\r
-};\r
-\r
-// send data to wechat server\r
-int32_t mpbledemo2_sendData(uint8_t* ptrData, uint32_t lengthInByte)\r
-{\r
- uint8_t *data = NULL;\r
- uint32_t len = 0;\r
- ARGS_ITEM_SET(mpbledemo2_info, m_mpbledemo2_handler->m_data_produce_args, cmd, CMD_SENDDAT); \r
- ARGS_ITEM_SET(mpbledemo2_info, m_mpbledemo2_handler->m_data_produce_args, send_msg.len, lengthInByte);\r
- ARGS_ITEM_SET(mpbledemo2_info, m_mpbledemo2_handler->m_data_produce_args, send_msg.str, (const char *)ptrData); \r
- \r
- m_mpbledemo2_handler->m_data_produce_func(m_mpbledemo2_handler->m_data_produce_args, &data, &len);\r
- if(data == NULL)\r
- {\r
- return errorCodeProduce;\r
- }\r
- ble_wechat_indicate_data(data, len);\r
- return 0;\r
-}\r
-\r
-#endif ///WX_AIRSYNC_CFG\r
-\r
+++ /dev/null
-// crc32.c\r
-// WeChat Embedded\r
-//\r
-// Created by harlliu on 14-03-03.\r
-// Copyright 2014 Tencent. All rights reserved.\r
-//\r
-\r
-\r
-#include "prf_defs.h"\r
-#if (WX_AIRSYNC_CFG)\r
-\r
-#include <stdio.h>\r
-#include "wechar_crc.h"\r
-\r
-#define DO1(buf) crc = crc_table(((int)crc ^ (*buf++)) & 0xff) ^ (crc >> 8);\r
-#define DO2(buf) DO1(buf); DO1(buf);\r
-#define DO4(buf) DO2(buf); DO2(buf);\r
-#define DO8(buf) DO4(buf); DO4(buf);\r
-\r
-\r
-static uint32_t crc_table(uint32_t index)\r
-{\r
- uint32_t c = index;\r
- uint32_t poly = 0xedb88320L;\r
- int k;\r
-\r
- for (k = 0; k < 8; k++)\r
- c = c & 1 ? poly ^ (c >> 1) : c >> 1;\r
-\r
- return c;\r
-}\r
-\r
-uint32_t crc32(uint32_t crc, const uint8_t *buf, int len)\r
-{\r
- if (buf == NULL) return 0L;\r
-\r
- crc = crc ^ 0xffffffffL;\r
- while (len >= 8)\r
- {\r
- DO8(buf);\r
- len -= 8;\r
- }\r
- if (len) do {\r
- DO1(buf);\r
- } while (--len);\r
- return crc ^ 0xffffffffL;\r
-}\r
-\r
-\r
-#endif ///WX_AIRSYNC_CFG\r
-\r
+++ /dev/null
-///////////////////////////////////////////////////////////////////////////////\r
-// ÎÄ ¼þ Ãû£ºwechat_aes.c\r
-// Ãè Êö£ºAES¼ÓÃÜËã·¨\r
-// ´´ ½¨ ÈË£ºLiangbofu\r
-// ´´½¨ÈÕÆÚ£º2009-07-17\r
-///////////////////////////////////////////////////////////////////////////////\r
-\r
-#include "prf_defs.h"\r
-#if (WX_AIRSYNC_CFG)\r
-\r
-#include "wechat_aes.h"\r
-#include <string.h>\r
-#include <stdlib.h>\r
-#include <stdint.h>\r
-#include <stdio.h>\r
-\r
-// ΪÁËÄÜÕë¶ÔC51½øÐÐÓÅ»¯£¬²¢ÇÒÓÖʹ´úÂë¿ÉÓÃÓÚARMºÍPCµÈ»·¾³£¬\r
-// ÔÚ·ÇC51»·¾³£¨Ã»Óж¨Òå__C51__£©ÏÂÐèÒª°ÑC51Ìض¨µÄ¹Ø¼ü×Ö¶¨ÒåΪ¿Õ\r
-#ifndef __C51__\r
- #define code\r
- #define data\r
- #define idata\r
- #define xdata\r
- #define pdata\r
- typedef unsigned char BOOL;\r
-#else\r
- typedef bit BOOL;\r
-#endif\r
-\r
-\r
-#define Nk (AES_KEY_LENGTH / 32) // ÒÔ¡°×Ö¡±£¨4×Ö½Ú£©Îªµ¥Î»µÄÃÜÔ¿³¤¶È\r
-#define Nb 4 // ÒÔ¡°×Ö¡±£¨4×Ö½Ú£©Îªµ¥Î»µÄ¼Ó½âÃÜÊý¾Ý¿é´óС£¬¹Ì¶¨Îª4\r
-\r
-// Nr£º¼ÓÃܵÄÂÖÊý\r
-#if AES_KEY_LENGTH == 128\r
- #define Nr 10\r
-#elif AES_KEY_LENGTH == 192\r
- #define Nr 12\r
-#elif AES_KEY_LENGTH == 256\r
- #define Nr 14\r
-#else\r
- #error AES_KEY_LENGTH must be 128, 192 or 256 BOOLs!\r
-#endif\r
-\r
-// GF(28) ¶àÏîʽ\r
-#define BPOLY 0x1B // Lower 8 BOOLs of (x^8 + x^4 + x^3 + x + 1), ie. (x^4 + x^3 + x + 1).\r
-\r
-// AES×ÓÃÜÔ¿±í£¬µ±ÃÜÔ¿³¤¶ÈΪ128λʱ£¬Õ¼ÓÃ176×Ö½Ú¿Õ¼ä\r
-static xdata unsigned char g_roundKeyTable[4*Nb*(Nr+1)];\r
-\r
-// ¼ÓÃÜÓõÄSBox\r
-static code const unsigned char SBox[256] = \r
-{\r
- 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,\r
- 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,\r
- 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,\r
- 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,\r
- 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,\r
- 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,\r
- 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,\r
- 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,\r
- 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,\r
- 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,\r
- 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,\r
- 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,\r
- 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,\r
- 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,\r
- 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,\r
- 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 \r
-};\r
-\r
-// ½âÃÜÓõÄSBox\r
-static code const unsigned char InvSBox[256] = \r
-{\r
- 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,\r
- 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,\r
- 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,\r
- 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,\r
- 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,\r
- 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,\r
- 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,\r
- 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,\r
- 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,\r
- 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,\r
- 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,\r
- 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,\r
- 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,\r
- 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,\r
- 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,\r
- 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d \r
-};\r
-\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º RotationWord\r
-// ÃèÊö£º ¶ÔÒ»¸ö¡°×Ö¡±Êý¾Ý½øÐÐÑ»·ÓÒÒÆ¡£\r
-// ÊäÈë²ÎÊý£º pWord -- ÒªÓÒÒƵÄ4×Ö½ÚÊý¾Ý¡£\r
-// Êä³ö²ÎÊý£º pWord -- ÓÒÒƺóµÄ4×Ö½ÚÊý¾Ý¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-///////////////////////////////////////////////////////////////////////////////\r
-static void RotationWord(unsigned char *pWord)\r
-{\r
- unsigned char temp = pWord[0];\r
- pWord[0] = pWord[1];\r
- pWord[1] = pWord[2];\r
- pWord[2] = pWord[3];\r
- pWord[3] = temp;\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º XorBytes\r
-// ÃèÊö£º ÅúÁ¿Òì»òÁ½×éÊý¾Ý¡£\r
-// ÊäÈë²ÎÊý£º pData1 -- ÒªÒì»òµÄµÚÒ»×éÊý¾Ý¡£\r
-// pData1 -- ÒªÒì»òµÄµÚ¶þ×éÊý¾Ý¡£\r
-// nCount -- ÒªÒì»òµÄÊý¾Ý³¤¶È¡£\r
-// Êä³ö²ÎÊý£º pData1 -- Òì»òºóµÄ½á¹û¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-///////////////////////////////////////////////////////////////////////////////\r
-static void XorBytes(unsigned char *pData1, const unsigned char *pData2, unsigned char nCount)\r
-{\r
- unsigned char i;\r
- \r
- for (i = 0; i < nCount; i++)\r
- {\r
- pData1[i] ^= pData2[i];\r
- }\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º AddRoundKey\r
-// ÃèÊö£º °Ñ Öмä״̬Êý¾Ý ¼ÓÉÏ£¨Òì»ò£©×ÓÃÜÔ¿£¬Êý¾Ý³¤¶ÈΪ16×Ö½Ú¡£\r
-// ÊäÈë²ÎÊý£º pState -- ״̬Êý¾Ý¡£\r
-// pRoundKey -- ×ÓÃÜÔ¿Êý¾Ý¡£\r
-// Êä³ö²ÎÊý£º pState -- ¼ÓÉÏ×ÓÃÜÔ¿ºóµÄ״̬Êý¾Ý¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-///////////////////////////////////////////////////////////////////////////////\r
-// static void AddRoundKey(unsigned char *pState, const unsigned char *pRoundKey)\r
-// {\r
-// XorBytes(pState, pRoundKey, 4*Nb);\r
-// }\r
-\r
-// AddRoundKeyµÄºêÐÎʽ£¬±Èº¯ÊýÐÎʽ¿ÉÒÔ½ÚÊ¡4×Ö½ÚµÄdataÊý¾Ý\r
-#define AddRoundKey(pState, pRoundKey) \\r
- XorBytes((pState), (pRoundKey), 4*Nb)\r
-\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º SubBytes\r
-// ÃèÊö£º ͨ¹ýSºÐ×ÓÖû»×´Ì¬Êý¾Ý¡£\r
-// ÊäÈë²ÎÊý£º pState -- ״̬Êý¾Ý¡£\r
-// nCount -- ״̬Êý¾Ý³¤¶È¡£\r
-// bInvert -- ÊÇ·ñʹÓ÷´ÏòSºÐ×Ó£¨½âÃÜʱʹÓã©¡£\r
-// Êä³ö²ÎÊý£º pState -- Öû»ºóµÄ״̬Êý¾Ý¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-///////////////////////////////////////////////////////////////////////////////\r
-static void SubBytes(unsigned char *pState, unsigned char nCount, BOOL bInvert)\r
-{\r
- unsigned char i;\r
- const unsigned char code *pSBox = bInvert ? InvSBox : SBox;\r
- \r
- for (i = 0; i < nCount; i++)\r
- {\r
- pState[i] = pSBox[pState[i]];\r
- }\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º ShiftRows\r
-// ÃèÊö£º °Ñ״̬Êý¾ÝÒÆÐС£\r
-// ÊäÈë²ÎÊý£º pState -- ״̬Êý¾Ý¡£\r
-// bInvert -- ÊÇ·ñ·´ÏòÒÆÐУ¨½âÃÜʱʹÓã©¡£\r
-// Êä³ö²ÎÊý£º pState -- ÒÆÐкóµÄ״̬Êý¾Ý¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-///////////////////////////////////////////////////////////////////////////////\r
-static void ShiftRows(unsigned char *pState, BOOL bInvert)\r
-{\r
- // ×¢Ò⣺״̬Êý¾ÝÒÔÁÐÐÎʽ´æ·Å£¡\r
-\r
- unsigned char r; // row£¬ ÐÐ\r
- unsigned char c; // column£¬ÁÐ\r
- unsigned char temp;\r
- unsigned char rowData[4];\r
- \r
- for (r = 1; r < 4; r++)\r
- {\r
- // ±¸·ÝÒ»ÐÐÊý¾Ý\r
- for (c = 0; c < 4; c++)\r
- {\r
- rowData[c] = pState[r + 4*c];\r
- }\r
- \r
- temp = bInvert ? (4 - r) : r;\r
- for (c = 0; c < 4; c++)\r
- {\r
- pState[r + 4*c] = rowData[(c + temp) % 4];\r
- }\r
- }\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º GfMultBy02\r
-// ÃèÊö£º ÔÚGF(28)ÓòµÄ ³Ë2 ÔËËã¡£\r
-// ÊäÈë²ÎÊý£º num -- ³ËÊý¡£\r
-// Êä³ö²ÎÊý£º ÎÞ¡£\r
-// ·µ»ØÖµ£º num³ËÒÔ2µÄ½á¹û¡£\r
-///////////////////////////////////////////////////////////////////////////////\r
-static unsigned char GfMultBy02(unsigned char num)\r
-{\r
- if ((num & 0x80) == 0)\r
- {\r
- num = num << 1;\r
- }\r
- else\r
- {\r
- num = (num << 1) ^ BPOLY;\r
- }\r
- \r
- return num;\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º MixColumns\r
-// ÃèÊö£º »ìºÏ״̬¸÷ÁÐÊý¾Ý¡£\r
-// ÊäÈë²ÎÊý£º pState -- ״̬Êý¾Ý¡£\r
-// bInvert -- ÊÇ·ñ·´Ïò»ìºÏ£¨½âÃÜʱʹÓã©¡£\r
-// Êä³ö²ÎÊý£º pState -- »ìºÏÁкóµÄ״̬Êý¾Ý¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-///////////////////////////////////////////////////////////////////////////////\r
-static void MixColumns(unsigned char *pState, BOOL bInvert)\r
-{\r
- unsigned char i;\r
- unsigned char temp;\r
- unsigned char a0Pa2_M4; // 4(a0 + a2)\r
- unsigned char a1Pa3_M4; // 4(a1 + a3)\r
- unsigned char result[4];\r
-\r
- for (i = 0; i < 4; i++, pState += 4)\r
- {\r
- // b0 = 2a0 + 3a1 + a2 + a3 \r
- // = (a0 + a1 + a2 + a3) + 2(a0 + a1) + a0\r
-\r
- temp = pState[0] ^ pState[1] ^ pState[2] ^ pState[3];\r
- result[0] = temp ^ pState[0] ^ GfMultBy02((unsigned char) (pState[0] ^ pState[1]));\r
- result[1] = temp ^ pState[1] ^ GfMultBy02((unsigned char) (pState[1] ^ pState[2]));\r
- result[2] = temp ^ pState[2] ^ GfMultBy02((unsigned char) (pState[2] ^ pState[3]));\r
- result[3] = temp ^ pState[3] ^ GfMultBy02((unsigned char) (pState[3] ^ pState[0]));\r
-\r
- if (bInvert)\r
- {\r
- // b0' = 14a0 + 11a1 + 13a2 + 9a3 \r
- // = (a0 + a1 + a2 + a3) + 2(a0 + a1) + a0 £¨Õⲿ·ÖΪb0£©\r
- // + 2(4(a0 + a2) + 4(a1 + a3))\r
- // + 4(a0 + a2)\r
-\r
- a0Pa2_M4 = GfMultBy02(GfMultBy02((unsigned char) (pState[0] ^ pState[2])));\r
- a1Pa3_M4 = GfMultBy02(GfMultBy02((unsigned char) (pState[1] ^ pState[3])));\r
- temp = GfMultBy02((unsigned char) (a0Pa2_M4 ^ a1Pa3_M4));\r
- result[0] ^= temp ^ a0Pa2_M4;\r
- result[1] ^= temp ^ a1Pa3_M4;\r
- result[2] ^= temp ^ a0Pa2_M4;\r
- result[3] ^= temp ^ a1Pa3_M4;\r
- }\r
-\r
- memcpy(pState, result, 4);\r
- }\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º BlockEncrypt\r
-// ÃèÊö£º ¶Ôµ¥¿éÊý¾Ý¼ÓÃÜ¡£\r
-// ÊäÈë²ÎÊý£º pState -- ״̬Êý¾Ý¡£\r
-// Êä³ö²ÎÊý£º pState -- ¼ÓÃܺóµÄ״̬Êý¾Ý¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-///////////////////////////////////////////////////////////////////////////////\r
-static void BlockEncrypt(unsigned char *pState)\r
-{\r
- unsigned char i;\r
- \r
- AddRoundKey(pState, g_roundKeyTable);\r
- \r
- for (i = 1; i <= Nr; i++) // i = [1, Nr]\r
- {\r
- SubBytes(pState, 4*Nb, 0);\r
- ShiftRows(pState, 0);\r
-\r
- if (i != Nr)\r
- {\r
- MixColumns(pState, 0);\r
- }\r
-\r
- AddRoundKey(pState, &g_roundKeyTable[4*Nb*i]);\r
- }\r
- \r
-// ΪÁ˽ÚÊ¡´úÂ룬ºÏ²¢µ½Ñ»¯Ö´ÐÐ\r
-// SubBytes(pState, 4*Nb);\r
-// ShiftRows(pState, 0);\r
-// AddRoundKey(pState, &g_roundKeyTable[4*Nb*Nr]);\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º BlockDecrypt\r
-// ÃèÊö£º ¶Ôµ¥¿éÊý¾Ý½âÃÜ¡£\r
-// ÊäÈë²ÎÊý£º pState -- ״̬Êý¾Ý¡£\r
-// Êä³ö²ÎÊý£º pState -- ½âÃܺóµÄ״̬Êý¾Ý¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-///////////////////////////////////////////////////////////////////////////////\r
-static void BlockDecrypt(unsigned char *pState)\r
-{\r
- unsigned char i;\r
- \r
- AddRoundKey(pState, &g_roundKeyTable[4*Nb*Nr]);\r
- \r
- for (i = Nr; i > 0; i--) // i = [Nr, 1]\r
- {\r
- ShiftRows(pState, 1);\r
- SubBytes(pState, 4*Nb, 1);\r
- AddRoundKey(pState, &g_roundKeyTable[4*Nb*(i-1)]);\r
-\r
- if (i != 1)\r
- {\r
- MixColumns(pState, 1);\r
- }\r
- }\r
-}\r
-\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º AES_Init\r
-// ÃèÊö£º ³õʼ»¯£¬ÔÚ´ËÖ´ÐÐÀ©Õ¹ÃÜÔ¿²Ù×÷¡£\r
-// ÊäÈë²ÎÊý£º pKey -- ÔʼÃÜÔ¿£¬Æ䳤¶È±ØÐëΪ AES_KEY_LENGTH/8 ×Ö½Ú¡£\r
-// Êä³ö²ÎÊý£º ÎÞ¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-///////////////////////////////////////////////////////////////////////////////\r
-void AES_Init(const void *pKey)\r
-{\r
- // À©Õ¹ÃÜÔ¿\r
- unsigned char i;\r
- unsigned char *pRoundKey;\r
- unsigned char Rcon[4] = {0x01, 0x00, 0x00, 0x00};\r
-\r
- memcpy(g_roundKeyTable, pKey, 4*Nk);\r
-\r
- pRoundKey = &g_roundKeyTable[4*Nk];\r
-\r
- for (i = Nk; i < Nb*(Nr+1); pRoundKey += 4, i++)\r
- {\r
- memcpy(pRoundKey, pRoundKey - 4, 4);\r
-\r
- if (i % Nk == 0)\r
- {\r
- RotationWord(pRoundKey);\r
- SubBytes(pRoundKey, 4, 0);\r
- XorBytes(pRoundKey, Rcon, 4);\r
-\r
- Rcon[0] = GfMultBy02(Rcon[0]);\r
- }\r
- else if (Nk > 6 && i % Nk == Nb)\r
- {\r
- SubBytes(pRoundKey, 4, 0);\r
- }\r
-\r
- XorBytes(pRoundKey, pRoundKey - 4*Nk, 4);\r
- }\r
-}\r
-\r
-unsigned int AES_get_length(unsigned int length)\r
-{\r
- return ((length>>4) + 1)<<4;\r
-}\r
-//////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º AES_Encrypt\r
-// ÃèÊö£º ¼ÓÃÜÊý¾Ý\r
-// ÊäÈë²ÎÊý£º pPlainText -- Ã÷ÎÄ£¬¼´Ðè¼ÓÃܵÄÊý¾Ý£¬Æ䳤¶ÈΪnDataLen×Ö½Ú¡£\r
-// nDataLen -- Êý¾Ý³¤¶È£¬ÒÔ×Ö½ÚΪµ¥Î»\r
-// pIV -- ³õʼ»¯ÏòÁ¿£¬Èç¹ûʹÓÃECBģʽ£¬¿ÉÉèΪNULL¡£\r
-// Êä³ö²ÎÊý£º pCipherText -- ÃÜÎÄ£¬¼´ÓÉÃ÷ÎļÓÃܺóµÄÊý¾Ý£¬¿ÉÒÔÓëpPlainTextÏàͬ¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-//////////////////////////////////////////////////////////////////////////\r
-unsigned int AES_Encrypt_PKCS7(const unsigned char *pPlainText, unsigned char *pCipherText, \r
- unsigned int nDataLen, const unsigned char *pIV)\r
-{\r
- unsigned int i;\r
- //³¤¶Èµ÷Õû\r
- unsigned int length = nDataLen;\r
- nDataLen = ((nDataLen>>4) + 1)<<4;\r
- uint8_t p=(Nb<<2)-(length%(Nb<<2));\r
- if (pPlainText != pCipherText){memcpy(pCipherText,pPlainText,length);}\r
- //Ìî³ä\r
- unsigned char temp[16];\r
- memset(temp,p,16);\r
- if(length<nDataLen)\r
- {\r
- memcpy(pCipherText + length,temp,nDataLen - length);\r
- }\r
- if(length == nDataLen)\r
- {\r
- memcpy(pCipherText + length,temp,16);\r
- }\r
-\r
- for (i = nDataLen/(4*Nb); i > 0 ; i--, pCipherText += 4*Nb)\r
- {\r
- #if AES_MODE == AES_MODE_CBC\r
- XorBytes(pCipherText, pIV, 4*Nb);\r
- #endif\r
- BlockEncrypt(pCipherText);\r
- pIV = pCipherText;\r
- }\r
- return(nDataLen);\r
-}\r
-//////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º AES_Decrypt\r
-// ÃèÊö£º ½âÃÜÊý¾Ý\r
-// ÊäÈë²ÎÊý£º pCipherText -- ÃÜÎÄ£¬¼´Ðè½âÃܵÄÊý¾Ý£¬Æ䳤¶ÈΪnDataLen×Ö½Ú¡£\r
-// nDataLen -- Êý¾Ý³¤¶È£¬ÒÔ×Ö½ÚΪµ¥Î»£¬±ØÐëΪAES_KEY_LENGTH/8µÄÕû±¶Êý¡£\r
-// pIV -- ³õʼ»¯ÏòÁ¿£¬Èç¹ûʹÓÃECBģʽ£¬¿ÉÉèΪNULL¡£\r
-// Êä³ö²ÎÊý£º pPlainText -- Ã÷ÎÄ£¬¼´ÓÉÃÜÎĽâÃܺóµÄÊý¾Ý£¬¿ÉÒÔÓëpCipherTextÏàͬ¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-//////////////////////////////////////////////////////////////////////////\r
-void AES_Decrypt(unsigned char *pPlainText, const unsigned char *pCipherText, \r
- unsigned int nDataLen, const unsigned char *pIV)\r
-{\r
- unsigned int i;\r
-\r
- if (pPlainText != pCipherText)\r
- {\r
- memcpy(pPlainText, pCipherText, nDataLen);\r
- }\r
-\r
- // ´Ó×îºóÒ»¿éÊý¾Ý¿ªÊ¼½âÃÜ£¬ÕâÑù²»Óÿª±Ù¿Õ¼äÀ´±£´æIV\r
- pPlainText += nDataLen - 4*Nb;\r
- for (i = nDataLen/(4*Nb); i > 0 ; i--, pPlainText -= 4*Nb)\r
- {\r
- BlockDecrypt(pPlainText);\r
-\r
- #if AES_MODE == AES_MODE_CBC\r
- if (i == 1)\r
- {// ×îºóÒ»¿éÊý¾Ý\r
- XorBytes(pPlainText, pIV, 4*Nb);\r
- }\r
- else\r
- {\r
- XorBytes(pPlainText, pPlainText - 4*Nb, 4*Nb);\r
- }\r
- #endif\r
- }\r
-}\r
-\r
-\r
-#endif ///WX_AIRSYNC_CFG\r
-\r
+++ /dev/null
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-
-#include "prf_defs.h"
-
-#if (BUT_PROFILE_CFG)
-
-
-#include <stdint.h>
-#include <string.h>
-#include <stdbool.h>
-#include <stdio.h>
-
-
-#include "rom/gpio.h"
-#include "app_button.h"
-#include "bt_trace.h"
-#include "freertos/FreeRTOS.h"
-#include "freertos/timers.h"
-#include "freertos/task.h"
-#include "freertos/xtensa_api.h"
-#include "thread.h"
-
-#include "allocator.h"
-#include "button_pro.h"
-#include "app_button_int.h"
-
-static const tBT_PRF_SYS_REG but_prf_reg =
-{
- ble_but_prf_hdl_event,
- ble_but_prf_disable
-};
-
-
-
-/*******************************************************************************
-**
-** Function ble_but_prf_hdl_event
-**
-** Description button profile main event handling function.
-**
-**
-** Returns BOOLEAN
-**
-*******************************************************************************/
-BOOLEAN ble_but_prf_hdl_event(prf_hdr_evt_t *msg_data)
-{
- LOG_ERROR("###################ble_but_prf_hdl_event#####################################\n");
-
- UINT16 connid = 0;
- switch(msg_data->event)
- {
- case BLE_BUT_CREATE_DB_REQ_EVT:
- Button_CreateService();
- break;
- case BLE_BUT_VAL_SEND_CFM_EVT:
- break;
- case BLE_BUT_SET_CHAR_VAL_REQ_EVT:
- button_msg_notify(msg_data->len,msg_data->data);
- break;
- case BLE_BUT_ENABLE_REQ_EVT:
- button_init(NULL);
- break;
- case BLE_BUT_DISABLE_IND_EVT:
- button_disable(connid);
- break;
- case BLE_BUT_CHAR_WRITE_IND_EVT:
-
- break;
- case BLE_BUT_ERROR_IND_EVT:
- break;
- default:
- break;
- }
-}
-
-
-/*******************************************************************************
-**
-** Function ble_but_prf_disable
-**
-** Description This function is called to disable the button profile modlue
-**
-** Parameters None.
-**
-** Returns None
-**
-*******************************************************************************/
-void ble_but_prf_disable(void)
-{
- prf_hdr_evt_t *p_buf;
- LOG_ERROR("ble_but_prf_disable\n");
-
- if (bt_prf_sys_is_register(PRF_ID_BUT_LE) == FALSE)
- {
- APPL_TRACE_WARNING("button profile Module not enabled/already disabled\n");
- return;
- }
-
- if ((p_buf = (prf_hdr_evt_t *) GKI_getbuf(sizeof(prf_hdr_evt_t))) != NULL)
- {
- p_buf->event = BLE_BUT_DISABLE_IND_EVT;
- bta_sys_sendmsg(p_buf);
- }
- bta_sys_deregister(PRF_ID_BUT_LE);
-
-}
-
-void ble_but_prf_enable(void)
-{
- bt_prf_sys_register(PRF_ID_BUT_LE,&but_prf_reg);
-}
-
-void ble_but_create_svc(void)
-{
- prf_hdr_evt_t *p_msg;
-
- LOG_ERROR("ble_but_create_svc\n"); //todo
- if ((p_msg = (prf_hdr_evt_t *) GKI_getbuf(sizeof(prf_hdr_evt_t))) != NULL)
- {
- memset(p_msg, 0, sizeof(prf_hdr_evt_t));
-
- p_msg->event = BLE_BUT_ENABLE_REQ_EVT;
-
- bt_prf_sys_sendmsg(p_msg);
- }
-}
-
-
-
-
-
-
-#endif ///BUT_PROFILE_CFG
-
-#if 0
-
-#define GPIO_INUM 8
-#define TABLE_ELEMENT_CNT(table) ((sizeof(table))/(sizeof(table[0])));
-app_key_env key_press;
-
-uint8_t gpio_test_table[]={0,2,4,5,12,13,14,15,16,17,18,19,20,21,22,23,25,26,27,33,34,35,36,37,38,39};
-
-struct gpio_test_info{
- uint8_t *gpio_test_table;
- uint8_t gpio_test_num;
- void *time_s;
-};
-
-static void gpio_irq_init(uint64_t gpio_num);
-
-void gpio_check_register(enum_gpio_num_t gpio_num)
-{
- if(gpio_num>=GPIO_PIN_COUNT||0==GPIO_PIN_MUX_REG[gpio_num]){
- ets_printf("io_num=%d not exits\n",gpio_num);
- return;
- }
- LOG_ERROR("---------gpio_num %d reg----------\n",gpio_num);
-LOG_ERROR("GPIO_IOMUX_%d=0x%08x\n",gpio_num,READ_PERI_REG(GPIO_PIN_MUX_REG[gpio_num]));
- LOG_ERROR("GPIO_PIN%d_ADDR=0x%08x\n",gpio_num,READ_PERI_REG(GPIO_PIN_ADDR(gpio_num)));
- LOG_ERROR("GPIO_OUT_REG=0x%08x\n",READ_PERI_REG(GPIO_OUT_REG));
- LOG_ERROR("GPIO_OUT1_REG=0x%08x\n",READ_PERI_REG(GPIO_OUT1_REG));
- LOG_ERROR("GPIO_ENABLE_REG=0x%08x\n",READ_PERI_REG(GPIO_ENABLE_REG));
- LOG_ERROR("GPIO_ENABLE1_REG=0x%08x\n",READ_PERI_REG(GPIO_ENABLE1_REG));
- LOG_ERROR("GPIO_IN_REG=0x%08x\n",READ_PERI_REG(GPIO_IN_REG));
- LOG_ERROR("GPIO_IN1_REG=0x%08x\n",READ_PERI_REG(GPIO_IN1_REG));
- LOG_ERROR("GPIO_STATUS_REG=0x%08x\n",READ_PERI_REG(GPIO_STATUS_REG));
- LOG_ERROR("GPIO_STATUS1_REG=0x%08x\n",READ_PERI_REG(GPIO_STATUS1_REG));
-}
-
-void t1_callback(void *arg)
-{
- static uint8_t level=0;
- static uint8_t cnt=0;
- uint8_t err_flag=0;
- struct gpio_test_info *gpio_test=(struct gpio_test_info*)(arg);
- uint8_t i=0;
- while(1){
- gpio_check_register(35);
- vTaskDelay(2*1000);
- /*
- level=~level;
- LOG_ERROR("Test cnt %u, level %u\n",cnt+1,level&0x01);
- for(i=0;i<gpio_test->gpio_test_num;i++){
- gpio_set_output_level(gpio_test->gpio_test_table[i],level&0x01);
- if(gpio_get_input_level(gpio_test->gpio_test_table[i])!=(level&0x01))
- {
- err_flag=1;
- LOG_ERROR("[ERR] GPIO%u set_level %u get_level %u\n",gpio_test->gpio_test_table[i],level&0x01,gpio_get_input_level(gpio_test->gpio_test_table[i]));
- }
- else{
- LOG_ERROR("GPIO%u OK\n",gpio_test->gpio_test_table[i]);
- }
- }
- cnt++;
- if(err_flag==0){
- LOG_ERROR("cnt %u test ok\n",cnt);
- }
- err_flag=0;
- if(cnt>=10){
- LOG_ERROR("Gpio input and output test end\n");
- vTaskDelete(NULL);*/
- // }
-
- //vTaskDelay(2*1000);
-
- }
-}
-
- void app_button_init(void)
-{
- uint64_t gpio_num = GPIO_Pin_27|GPIO_Pin_35|GPIO_Pin_34|GPIO_Pin_36|GPIO_Pin_39;
- // Reset environment
- memset(&key_press, 0, sizeof(key_press));
- gpio_irq_init(gpio_num);
- static struct gpio_test_info gpio_test_infor;
- LOG_ERROR("app_button_init.");
-/* TimerHandle_t t1=NULL;
- t1=xTimerCreate("t1_time",(1000/portTICK_PERIOD_MS),pdTRUE,&gpio_test_infor,t1_callback);
- do{
- gpio_test_infor.gpio_test_table=gpio_test_table;
- gpio_test_infor.gpio_test_num=TABLE_ELEMENT_CNT(gpio_test_table);
- gpio_test_infor.time_s=t1;
- }while(0);*/
-
- // xTaskCreate(t1_callback,"t1_callback",1024,&gpio_test_infor,30,NULL);
- LOG_ERROR("gpio_input_output_demo\n");
- return;
-}
-
-static void gpio_irq_init(uint64_t gpio_num)
-{
- gpio_config_t gpio_config_prot;
- memset(&gpio_config_prot,0,sizeof(gpio_config_prot));
- gpio_config_prot.GPIO_Pin= gpio_num;
-
- gpio_config_prot.GPIO_Mode=GPIO_Mode_Input;
- gpio_config_prot.GPIO_IntrType=GPIO_PIN_INTR_NEGEDGE;
- gpio_config_prot.GPIO_Pullup=GPIO_PullUp_EN;
- gpio_config_prot.GPIO_Pulldown=GPIO_PullDown_DIS;
- gpio_config(&gpio_config_prot);
- //Register gpio handler
- gpio_intr_handler_register(GPIO_isr_callback,NULL);
- //Enable gpio intr
- xt_ints_on(1<<GPIO_INUM);
- //ETS_GPIO_INTR_ENABLE(); //Enable intr
-}
-
-
-void GPIO_isr_callback(void* arg)
-{
- /*GPIO interrupt process*/
- uint32_t gpio_intr_status = 0;
- uint32_t gpio_intr_status_h = 0;
- uint32_t gpio_num =0;
- //disable the pending interrupt
- xt_ints_off(1<<GPIO_INUM);
- gpio_intr_status = READ_PERI_REG(GPIO_STATUS_REG);
- gpio_intr_status_h = READ_PERI_REG(GPIO_STATUS1_REG);
- LOG_ERROR("the interrupt come in,gpio_intr_staus = %d,gpio_intr_status_h=%d\n",gpio_intr_status,gpio_intr_status_h);
- //clear intr for gpio0-gpio31
- WRITE_PERI_REG((GPIO_STATUS_W1TC_REG),(READ_PERI_REG(GPIO_STATUS_W1TC_REG)|(gpio_intr_status)));
- //clear intr for gpio32-39
- WRITE_PERI_REG((GPIO_STATUS1_W1TC_REG),(READ_PERI_REG(GPIO_STATUS1_W1TC_REG)|(gpio_intr_status_h)));
- do{
- if(gpio_num < 32){
- if(gpio_intr_status&BIT(gpio_num))
- {
- LOG_ERROR("Intr GPIO= %d\n",gpio_num);
- break;
- }
- }
- else{
- if(gpio_intr_status_h&BIT(gpio_num - 32)){
- LOG_ERROR("Intr GPIO = %d\n",gpio_num);
- break;
- }
- }
-
- }while(++gpio_num<GPIO_PIN_COUNT);
- TaskEvt_t *evt = (TaskEvt_t *)osi_malloc(sizeof(TaskEvt_t));
- if(evt == NULL)
- {
- return;
- }
-
- switch(gpio_num)
- {
- case GPIO_NUM_35:
- evt->par = Button_Voice;
- break;
- case GPIO_NUM_34:
- evt->par = Button_OK;
- break;
- case GPIO_NUM_39:
- evt->par = Button_Down;
- break;
- case GPIO_NUM_36:
- evt->par = Button_Up;
- break;
- default:
- evt->par = Button_Back;
- break;
- }
- evt->sig = BUTTON_PRESS_EVT;
- if(xQueueSend(xBtaApp1Queue,&evt,10/portTICK_RATE_MS)!=pdTRUE){
- LOG_ERROR("btdm_post_failed\n");
- }
- //enable the interrupt
- xt_ints_on(1<<GPIO_INUM);
- LOG_ERROR("the interrupt come in arg = %s\n",arg);
-}
-
-
-uint8_t check_sum(uint8_t *check_array,uint8_t len)
-{
- uint8_t i,sum = 0;
- for(i = 0;i < len; i++)
- {
- sum ^= check_array[i];
- }
- sum += 1;
-
- return sum;
-}
-
-#endif
+++ /dev/null
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-
-
-/****************************************************************************
-*
-* This file is for gatt client. It can scan ble device, connect one device,
-*
-****************************************************************************/
-
-#include <stdint.h>
-#include <string.h>
-#include <stdbool.h>
-#include <stdio.h>
-
-#include "bta_api.h"
-#include "bta_gatt_api.h"
-#include "controller.h"
-
-#include "bt_trace.h"
-#include "btm_api.h"
-#include "bt_types.h"
-#include "gattc_profile.h"
-
-#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
-#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
-
-tBTA_GATTC_IF client_if;
-BD_ADDR obj_addr;
-static unsigned char BASE_UUID[16] = {
- 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
- 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
- };
-
-int uuidType(unsigned char* p_uuid)
-{
- int i = 0;
- int match = 0;
- int all_zero = 1;
-
- for(i = 0; i != 16; ++i)
- {
- if (i == 12 || i == 13)
- continue;
-
- if (p_uuid[i] == BASE_UUID[i])
- ++match;
-
- if (p_uuid[i] != 0)
- all_zero = 0;
- }
- if (all_zero)
- return 0;
- if (match == 12)
- return LEN_UUID_32;
- if (match == 14)
- return LEN_UUID_16;
- return LEN_UUID_128;
-}
-
-static void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src)
-{
- char *p_byte = (char*)p_src;
-
- int i = 0;
-
- p_dest->len = uuidType(p_src->uu);
-
- switch (p_dest->len)
- {
- case LEN_UUID_16:
- p_dest->uu.uuid16 = (p_src->uu[13] << 8) + p_src->uu[12];
- break;
-
- case LEN_UUID_32:
- p_dest->uu.uuid32 = (p_src->uu[13] << 8) + p_src->uu[12];
- p_dest->uu.uuid32 += (p_src->uu[15] << 24) + (p_src->uu[14] << 16);
- break;
-
- case LEN_UUID_128:
- for(i = 0; i != 16; ++i)
- p_dest->uu.uuid128[i] = p_byte[i];
- break;
-
- default:
- LOG_ERROR("%s: Unknown UUID length %d!", __FUNCTION__, p_dest->len);
- break;
- }
-}
-/*
-uint16_t get_uuid16(tBT_UUID* p_uuid)
-{
- if(p_uuid->len == LEN_UUID_16)
- {
- return p_uuid->uu.uuid16;
- }
- else if(p_uuid->len == LEN_UUID_128)
- {
- UINT16 u16;
- UINT8 *p = &p_uuid->uu.uuid128[LEN_UUID_128 - 4];
- STREAM_TO_UINT16(u16, p);
- return u16;
- }
- else
- {
- return (UINT16)p_uuid->uu.uuid32;
- }
-}
-
-//fill a GATT ID structure
-void bta_le_fill_16bits_gatt_id(UINT8 inst_id, UINT16 uuid, tBTA_GATT_ID* p_output)
-{
- p_output->inst_id = inst_id;
- p_output->uuid.len = LEN_UUID_16;
- p_output->uuid.uu.uuid16 = uuid;
-}
-
-//fill a service ID structure with a 16 bits service UUID
-void bta_le_fill_16bits_srvc_id(bool is_pri, UINT8 inst_id, UINT16 srvc_uuid, tBTA_GATT_SRVC_ID* p_output)
-{
- memset((void *)p_output, 0, sizeof(tBTA_GATT_SRVC_ID));
- p_output->is_primary = is_pri;
- bta_le_fill_16bits_gatt_id(inst_id, srvc_uuid, &p_output->id);
-}
-
-//fill a char ID structure with a 16 bits char UUID
-void bta_le_fill_16bits_char_id(UINT8 inst_id, UINT16 char_uuid, tBTA_GATT_ID* p_output)
-{
- memset((void *)p_output, 0, sizeof(tBTA_GATT_ID));
- bta_le_fill_16bits_gatt_id(inst_id, char_uuid, p_output);
-}
-*/
-/*get remote name*/
-static bool check_remote_name(tBTA_DM_INQ_RES* result, uint8_t* rmt_name, uint8_t* rmt_name_len)
-{
- uint8_t *p_rmt_name = NULL;
- uint8_t remote_name_len = 0;
-
- if (result->p_eir) {
- p_rmt_name = BTM_CheckEirData(result->p_eir,
- BTM_EIR_COMPLETE_LOCAL_NAME_TYPE,
- &remote_name_len);
- if (!p_rmt_name)
- p_rmt_name = BTM_CheckEirData(result->p_eir,
- BTM_EIR_SHORTENED_LOCAL_NAME_TYPE,
- &remote_name_len);
- if (p_rmt_name) {
- if (remote_name_len > BD_NAME_LEN)
- remote_name_len = BD_NAME_LEN;
- if (rmt_name && rmt_name_len) {
- memcpy(rmt_name, p_rmt_name, remote_name_len);
- *(rmt_name + remote_name_len) = 0;
- *rmt_name_len = remote_name_len;
- }
- return true;
- }
- }
- return false;
-}
-
-/************************************************************************************
-* * Function bta_scan_recult_callback
-* *
-* * Description scan result.it will be called when device scaned a peer device
-* *
-* * Return NULL
-**************************************************************************************/
-static void bta_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data)
-{
- uint8_t len;
- BD_ADDR bd_addr;
- char dev_name[32];
- tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
- //char obj_name[] = "Find Me";
- char obj_name[] = "SimpleBLEClient";
- uint8_t dev_name_len;
-
- switch (event)
- {
- case BTA_DM_INQ_RES_EVT:
- {
- LOG_ERROR("scan result: event=%d, "BT_BD_ADDR_STR", device_type=%d\n",
- event, BT_BD_ADDR_HEX(p_data->inq_res.bd_addr), p_data->inq_res.device_type);
-
- bdcpy(bd_addr, p_data->inq_res.bd_addr);
- if (p_data->inq_res.p_eir)
- {
- if (BTM_CheckEirData(p_data->inq_res.p_eir, BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &len))
- {
- p_data->inq_res.remt_name_not_required = TRUE;
- }
- }
-
- if(check_remote_name(&(p_data->inq_res), dev_name, &dev_name_len))
- {
- LOG_ERROR("scan device name len=%d, name = %s\n", dev_name_len, dev_name);
- }
-
- if(strcmp(dev_name, obj_name) == 0)
- {
- bdcpy(obj_addr, bd_addr);
- LOG_ERROR("find the device, obj_addr="BT_BD_ADDR_STR"\n", BT_BD_ADDR_HEX(obj_addr));
-// BTA_GATTC_Open(client_if, obj_addr, true, transport);
- }
- }
- break;
-
- case BTA_DM_INQ_CMPL_EVT:
- {
- LOG_ERROR("%s-BLE observe complete. Num Resp %d\n", __FUNCTION__, p_data->inq_cmpl.num_resps);
-
- LOG_ERROR("connect the device "BT_BD_ADDR_STR", client_if=%d\n",
- BT_BD_ADDR_HEX(obj_addr), client_if);
-
- /* scan complete, start connect*/
- BTA_GATTC_Open(client_if, obj_addr, true, transport);
- }
- break;
-
- default:
- LOG_ERROR("%s : unknown event 0x%x", __FUNCTION__, event);
- }
-}
-
-/************************************************************************************
-* * Function bta_scan_param_setup_cback
-* *
-* * Description set scan param callback.it will be called after setting scan parameter
-* *
-* * Return NULL
-**************************************************************************************/
-static void bta_scan_param_setup_cback(tGATT_IF c_client_if, tBTM_STATUS status)
-{
- client_if = c_client_if;
- LOG_ERROR("\nset scan params complete: status=%d, client_if=%d\n", status, client_if);
- /*start scan*/
- BTA_DmBleObserve(true, 8, bta_scan_result_callback);
-}
-
-/************************************************************************************
-* * Function bta_gattc_callback
-* *
-* * Description app register callback
-* *
-* * Return NULL
-**************************************************************************************/
-static void bta_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data)
-{
- switch (event)
- {
- case BTA_GATTC_REG_EVT:
- {
- tBTA_GATT_STATUS status = p_data->reg_oper.status;
- client_if = p_data->reg_oper.client_if;
- LOG_ERROR("%s:register complete: event=%d, status=%d, client_if=%d\n", __FUNCTION__, event, status, client_if);
- UINT8 scan_interval = 0x50;
- UINT8 scan_window = 0x30;
- tBLE_SCAN_MODE scan_mode = BTM_BLE_SCAN_MODE_ACTI;
-
- bac_register();
- /*register complete,set scan parameter*/
- BTA_DmSetBleScanParams(client_if, scan_interval, scan_window, scan_mode,
- bta_scan_param_setup_cback);
-
- }
- break;
-
- /*connect callback*/
- case BTA_GATTC_OPEN_EVT:
- {
-
- LOG_ERROR("\n%s:device is connected "BT_BD_ADDR_STR", client_if=%d, status=%d, connect_id=%d\n",
- __FUNCTION__, BT_BD_ADDR_HEX(p_data->open.remote_bda), p_data->open.client_if,
- p_data->open.status, p_data->open.conn_id);
- /*return whether the remote device is currently connected*/
- int is_connected = BTA_DmGetConnectionState(p_data->open.remote_bda);
- LOG_ERROR("is_connected=%d\n",is_connected);
- /*get the energy info of the controller*/
-
- /*read battery level*/
- int conn_id = p_data->open.conn_id;
-
- /*discover service*/
- // BTA_GATTC_ServiceSearchRequest(conn_id, NULL);
-
- }
- break;
-/*
- case BTA_GATTC_SEARCH_RES_EVT:
- {
- // tBTA_GATTC_SRVC_RES service_result;
- LOG_ERROR("find the service,uuid=0x%x, is_primary=%d\n",
- get_uuid16(&p_data->srvc_res.service_uuid.id.uuid),
- p_data->srvc_res.service_uuid.is_primary);
- }
- break;
-
- case BTA_GATTC_SEARCH_CMPL_EVT:
- {
- LOG_ERROR("search service complete, conn_id=%d,status=%d\n", p_data->search_cmpl.conn_id,
- p_data->search_cmpl.status);
-
- //get first characteristic of battey service
- LOG_ERROR("get first characteristic of battery service\n");
- tBTA_GATT_STATUS status;
- tBTA_GATT_SRVC_ID battery_srvc_id;
- tBTA_GATTC_CHAR_ID out_char_id;
- tGATT_CHAR_PROP out_char_prop;
- bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_srvc_id);
- status = BTA_GATTC_GetFirstChar(p_data->search_cmpl.conn_id, &battery_srvc_id, NULL,
- &out_char_id, &out_char_prop);
- if(status == 0)
- {
- LOG_ERROR("the first char:srvc_id=0x%x,char_id=0x%x, property = %d\n",
- get_uuid16(&out_char_id.srvc_id.id.uuid), get_uuid16(&out_char_id.char_id.uuid),
- out_char_prop);
- //read battery level
- tBTA_GATTC_CHAR_ID battery_char_id;
- bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_char_id.srvc_id);
- bta_le_fill_16bits_char_id(0, GATT_UUID_BATTERY_LEVEL, &battery_char_id.char_id);
-
- BTA_GATTC_ReadCharacteristic(p_data->search_cmpl.conn_id, &battery_char_id,
- BTA_GATT_AUTH_REQ_NONE);
- }
- }
- break;
-
- case BTA_GATTC_READ_CHAR_EVT:
- {
-
- LOG_ERROR("\nread characteristic:connect_id=%d, status=%d\n",
- p_data->read.conn_id, p_data->read.status);
- LOG_ERROR("srvc_id=0x%x,char_id=0x%x,descr_type=0x%x\n",
- get_uuid16(&p_data->read.srvc_id.id.uuid),
- get_uuid16(&p_data->read.char_id.uuid),
- get_uuid16(&p_data->read.descr_type.uuid));
- if(get_uuid16(&p_data->read.descr_type.uuid) != GATT_UUID_CHAR_AGG_FORMAT
- && p_data->read.p_value->unformat.len > 0
- && p_data->read.p_value->unformat.p_value != NULL)
- {
- LOG_ERROR("read the value: len=%d, value=%d\n", p_data->read.p_value->unformat.len,
- *(p_data->read.p_value->unformat.p_value));
- }
- }
- break;
-*/
- default:
- LOG_ERROR("%s:unknown event: %d\n", __FUNCTION__, event);
- }
-
-}
-
-/************************************************************************************
-* * Function ble_client_appRegister
-* *
-* * Description app register function
-* *
-* * Return NULL
-**************************************************************************************/
-void ble_client_appRegister(void)
-{
-
- bt_uuid_t uuid;
- tBT_UUID t_uuid;
- memcpy(&uuid, BASE_UUID, sizeof(bt_uuid_t));
- btif_to_bta_uuid(&t_uuid, &uuid);
-
- LOG_ERROR("register application\n");
- BTA_GATTC_AppRegister(&t_uuid, bta_gattc_callback);
-
- /*battery service register*/
-// bac_register();
-
-}
-
-void gattc_client_test(void)
-{
- BTM_SetTraceLevel(BT_TRACE_LEVEL_DEBUG);
-
- ble_client_appRegister();
-}
+++ /dev/null
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-/***************************************************************
-*
-* This file is for gatt server device. It instantiates BATTERY
-* sevice. It can be scanned and connected by central device,
-* and the client will get the BAS value. It calls the API bta
-* layer provides.
-*
-****************************************************************/
-
-#include <stdint.h>
-#include <string.h>
-#include <stdbool.h>
-#include <stdio.h>
-
-#include "prf_defs.h"
-
-#include "bta_api.h"
-#include "bta_gatt_api.h"
-#include "controller.h"
-
-#include "gatt_int.h"
-#include "bt_trace.h"
-#include "btm_api.h"
-#include "bt_types.h"
-#include "dis_api.h"
-#include "bt_app_common.h"
-
-//#include "prf_defs.h"
-
-#include "wx_airsync_prf.h"
-
-#include "button_pro.h"
-#include "app_button.h"
-#include "hid_le_prf.h"
-
-#include "esp_gatt_api.h"
-
-//
-
-#include "hcimsgs.h"
-#include "esp_bt_defs.h"
-
-
-#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
-#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
-tBTA_GATTS_IF server_if;
-
-static unsigned char DIS_UUID[16] = {
- 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
- 0x00, 0x10, 0x00, 0x00, 0x0a, 0x18, 0x00, 0x00
- };
-static unsigned char BASE_UUID[16] = {
- 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
- 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
- };
-
-UINT16 ijiazu_uuid = 0xffff;
-UINT16 wechat_uuid = 0xfee7;
-tBTA_BLE_SERVICE ijiazu_service = {
- 0x01, //only one service in the ijiazu button profile
- false,
- &ijiazu_uuid
- }; /* 16 bits services */
-
-tBTA_BLE_SERVICE wechat_service = {
- 0x01, //only one service in the ijiazu button profile
- false,
- &wechat_uuid
- }; /* 16 bits services */
-
-
-
-UINT8 beacon_manu[25] = {0x4c, 0x00,0x02, 0x15, 0xfd, 0xa5, 0x06, 0x93, 0xa4, 0xe2,
- 0x4f, 0xb1, 0xaf, 0xcf, 0xc6, 0xeb, 0x07, 0x64, 0x78, 0x25,
- 0x27, 0x32, 0xe6, 0x08, 0xc5};
-
-//UINT8 ijiazu_manu[17] = {0xff,0x20,0x14,0x07,0x22,0x00,0x02,0x5B,0x00,0x33,0x49,0x31,0x30,0x4a,0x30,0x30,0x31};
-UINT8 ijiazu_manu[17] = {0xff,0x20,0x14,0x07,0x22,0x00,0x02,0x5B,0x00,0x33,0x49,0x31,0x30,0x4a,0x30,0x30,0x31};
-UINT8 wechat_manu[] = {0x00,0x00,0x18,0xfe,0x34,0x6a,0x86,0x2e};
-tBTA_BLE_MANU p_ijiazu_manu = {sizeof(ijiazu_manu),ijiazu_manu}; /* manufacturer data */
-tBTA_BLE_MANU p_wechat_manu = {sizeof(wechat_manu),wechat_manu};
-
-
-tBLE_BD_ADDR p_peer_bda = {
- .type = API_PUBLIC_ADDR,
- .bda = {0}
-};
-
-esp_ble_adv_params_all_t adv_params =
-{
- .adv_int_min = BTM_BLE_ADV_INT_MIN + 0x100,
- .adv_int_max = BTM_BLE_ADV_INT_MIN + 0x100,
- .adv_type = API_NON_DISCOVERABLE,
- .addr_type_own = API_PUBLIC_ADDR,
- .channel_map = ESP_BLE_ADV_CHNL_MAP,
- .adv_filter_policy = ADV_ALLOW_SCAN_ANY_CON_ANY,
- .p_dir_bda = &p_peer_bda
-};
-
-
-
-
-
-BD_ADDR rand_ijiazu_addr = {0x00,0x02,0x5B,0x00,0x32,0x55};
-
-esp_ble_adv_data_cfg_t ijiazu_adv_data[ADV_SCAN_IDX_MAX] =
-{
- [BLE_ADV_DATA_IDX] = {
- .adv_name = "Espressif_007",
- {
- {0,0},
- NULL, //no manufature data to be setting in the ijiazu adervetisiing datas
- &ijiazu_service,
- NULL, //the 128 bits service uuid set to null(not used)
- NULL, //the 32 bits Service UUID set to null(not used)
- NULL, //16 bits services Solicitation UUIDs set to null(not used)
- NULL, //List of 32 bit Service Solicitation UUIDs set to null(not used)
- NULL, //List of 128 bit Service Solicitation UUIDs set to null(not used)
- NULL, //proprietary data set to null(not used)
- NULL, //service data set not null(no service data to be sent)
- 0x0200, //device type : generic display
- BTA_DM_GENERAL_DISC, // General discoverable.
- 0xFE //the tx power value,defult value is 0
- },
-
- },
- [BLE_SCAN_RSP_DATA_IDX] = {
- .adv_name = NULL,
- {
- {0,0},
- &p_ijiazu_manu,
- NULL,
- NULL, //the 128 bits service uuid set to null(not used)
- NULL, //the 32 bits Service UUID set to null(not used)
- NULL, //16 bits services Solicitation UUIDs set to null(not used)
- NULL, //List of 32 bit Service Solicitation UUIDs set to null(not used)
- NULL, //List of 128 bit Service Solicitation UUIDs set to null(not used)
- NULL, //proprietary data set to null(not used)
- NULL, //service data set not null(no service data to be sent)
- 0x0000, //device type : generic display
- 0x00, // General discoverable.
- 0x00}, //the tx power value,defult value is 0
-
- }
-};
-
-esp_ble_adv_data_cfg_t wechat_adv_data[ADV_SCAN_IDX_MAX] =
-{
- [BLE_ADV_DATA_IDX] = {
- .adv_name = NULL,
- {
- {0,0},
- NULL, //no manufature data to be setting in the ijiazu adervetisiing datas
- &wechat_service,
- NULL, //the 128 bits service uuid set to null(not used)
- NULL, //the 32 bits Service UUID set to null(not used)
- NULL, //16 bits services Solicitation UUIDs set to null(not used)
- NULL, //List of 32 bit Service Solicitation UUIDs set to null(not used)
- NULL, //List of 128 bit Service Solicitation UUIDs set to null(not used)
- NULL, //proprietary data set to null(not used)
- NULL, //service data set not null(no service data to be sent)
- 0x0200, //device type : generic display
- BTA_DM_GENERAL_DISC, // General discoverable.
- 0xFE //the tx power value,defult value is 0
- },
-
- },
- [BLE_SCAN_RSP_DATA_IDX] = {
- .adv_name = "wechat_demo",
- {
- {0,0},
- &p_wechat_manu,
- NULL,
- NULL, //the 128 bits service uuid set to null(not used)
- NULL, //the 32 bits Service UUID set to null(not used)
- NULL, //16 bits services Solicitation UUIDs set to null(not used)
- NULL, //List of 32 bit Service Solicitation UUIDs set to null(not used)
- NULL, //List of 128 bit Service Solicitation UUIDs set to null(not used)
- NULL, //proprietary data set to null(not used)
- NULL, //service data set not null(no service data to be sent)
- 0x0000, //device type : generic display
- 0x00, // General discoverable.
- 0x00}, //the tx power value,defult value is 0
-
- }
-};
-
-#if (BUT_PROFILE_CFG)
-static void SimpleDataCallBack(uint8_t app_id, uint8_t event, uint16_t len, uint8_t *p_data);
-#endif
-
-int uuidType(unsigned char* p_uuid)
-{
- int i = 0;
- int match = 0;
- int all_zero = 1;
-
- for(i = 0; i != 16; ++i)
- {
- if (i == 12 || i == 13)
- continue;
-
- if (p_uuid[i] == BASE_UUID[i])
- ++match;
-
- if (p_uuid[i] != 0)
- all_zero = 0;
- }
- if (all_zero)
- return 0;
- if (match == 12)
- return LEN_UUID_32;
- if (match == 14)
- return LEN_UUID_16;
- return LEN_UUID_128;
-}
-
-/*16-bits uuid to the structure of holding any type of UUID*/
-void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src)
-{
- char *p_byte = (char*)p_src;
-
- int i = 0;
-
- p_dest->len = uuidType(p_src->uu);
-
- switch (p_dest->len)
- {
- case LEN_UUID_16:
- p_dest->uu.uuid16 = (p_src->uu[13] << 8) + p_src->uu[12];
- break;
-
- case LEN_UUID_32:
- p_dest->uu.uuid32 = (p_src->uu[13] << 8) + p_src->uu[12];
- p_dest->uu.uuid32 += (p_src->uu[15] << 24) + (p_src->uu[14] << 16);
- break;
-
- case LEN_UUID_128:
- for(i = 0; i != 16; ++i)
- p_dest->uu.uuid128[i] = p_byte[i];
- break;
-
- default:
- LOG_ERROR("%s: Unknown UUID length %d!", __FUNCTION__, p_dest->len);
- break;
- }
-}
-
-
-/*set advertising config callback*/
-static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status)
-{
- LOG_ERROR("set advertising config:status=%d\n", call_status);
- /*dis init*/
-/* tDIS_ATTR_MASK dis_attr_mask;
- dis_attr_mask = DIS_ATTR_SYS_ID_BIT | DIS_ATTR_MODEL_NUM_BIT | DIS_ATTR_SERIAL_NUM_BIT |
- DIS_ATTR_FW_NUM_BIT | DIS_ATTR_HW_NUM_BIT | DIS_ATTR_SW_NUM_BIT | DIS_ATTR_MANU_NAME_BIT |
- DIS_ATTR_IEEE_DATA_BIT | DIS_ATTR_PNP_ID_BIT;
- DIS_SrInit(dis_attr_mask);
-*/
- //ble_but_create_svc();
- /*instantiate a battery service*/
- bas_register();
- /*instantiate the driver for button profile*/
- //app_button_init();
-#if (BUT_PROFILE_CFG)
- /*instantiate a button service*/
- //button_init(SimpleDataCallBack);
-#endif ///BUT_PROFILE_CFG
-
-#if (HIDD_LE_PROFILE_CFG)
- /*instantiate a hid device service*/
- hidd_le_init();
-#endif ///HIDD_LE_PROFILE_CFG
-
-#if (WX_AIRSYNC_CFG)
- AirSync_Init(NULL);
-#endif ///WX_AIRSYNC_CFG
- esp_ble_start_advertising(&adv_params);
- //API_Ble_AppStartAdvertising(&adv_params);
- /*start advetising*/
-// BTA_GATTS_Listen(server_if, true, NULL);
-}
-
-/*register callback*/
-void bta_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data)
-{
- switch (event)
- {
- case BTA_GATTS_REG_EVT:
- {
- tBTA_GATT_STATUS status = p_data->reg_oper.status;
- server_if = p_data->reg_oper.server_if;
- LOG_ERROR("register complete: event=%d, status=%d, server_if=%d\n",
- event, status, server_if);
-
- LOG_ERROR("set advertising parameters\n");
- //set the advertising data to the btm layer
- esp_ble_config_adv_data(&wechat_adv_data[BLE_ADV_DATA_IDX],
- bta_gatts_set_adv_data_cback);
-
- }
- break;
- /*connect callback*/
- case BTA_GATTS_CONNECT_EVT:
- {
- ///Stop the advertising when the connection is establish
- esp_ble_stop_advertising();
- LOG_ERROR("\ndevice is connected "BT_BD_ADDR_STR", server_if=%d,reason=0x%x,connect_id=%d\n",
- BT_BD_ADDR_HEX(p_data->conn.remote_bda), p_data->conn.server_if,
- p_data->conn.reason, p_data->conn.conn_id);
- /*return whether the remote device is currently connected*/
- int is_connected = BTA_DmGetConnectionState(p_data->conn.remote_bda);
- LOG_ERROR("is_connected=%d\n",is_connected);
- }
- break;
-
- case BTA_GATTS_DISCONNECT_EVT:
- ///start the advertising again when lose the connection
- esp_ble_start_advertising(&adv_params);
- break;
- default:
- LOG_ERROR("unsettled event: %d\n", event);
- }
-
-}
-
-#if (BUT_PROFILE_CFG)
-static void SimpleDataCallBack(uint8_t app_id, uint8_t event, uint16_t len, uint8_t *p_data)
-{
- LOG_ERROR("the event value is:%x\n",event);
- switch(event)
- {
- case RECEIVE_NET_PASSWD_EVT:
- LOG_ERROR("Received the network passwork");
- break;
- case RECEIVE_NET_SSD_EVT:
- LOG_ERROR("Received the network SSID");
- break;
- default:
- break;
- }
-}
-#endif ///BUT_PROFILE_CFG
-
-
-static void ble_server_appRegister(void)
-{
- bt_uuid_t uuid;
- tBT_UUID t_uuid;
- memcpy(&uuid, BASE_UUID, sizeof(bt_uuid_t));
- //memcpy(&uuid, DIS_UUID, sizeof(bt_uuid_t));
- btif_to_bta_uuid(&t_uuid, &uuid);
-
- LOG_ERROR("register gatts application\n");
- esp_ble_gatts_app_register(&t_uuid, bta_gatts_callback);
-
- bt_prf_sys_init();
- ble_but_prf_enable();
-}
-
-void gatts_server_test(void)
-{
- BTM_SetTraceLevel(BT_TRACE_LEVEL_DEBUG);
-
- ble_server_appRegister();
-}
+++ /dev/null
-#
-# Main Makefile. This is basically the same as a component makefile.
-#
-# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default,
-# this will take the sources in the src/ directory, compile them and link them into
-# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
-# please read the ESP-IDF documents if you need to do this.
-#
-
-COMPONENT_SRCDIRS := \
- app_core \
- app_client_profiles/battery_c \
- app_client_profiles \
- app_profiles/app_sample_button \
- app_profiles/app_WX_airsync \
- app_profiles \
- app_project
-
-CFLAGS += -Wno-error=unused-label -Wno-error=return-type -Wno-error=missing-braces -Wno-error=pointer-sign -Wno-error=parentheses -I./include
-
-
-include $(IDF_PATH)/make/component_common.mk
+++ /dev/null
-#ifndef __APP_AIRSYNC_MD5__
-#define __APP_AIRSYNC_MD5__
-
-#include "prf_defs.h"
-#if (WX_AIRSYNC_CFG)
-
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <math.h>
-
-#define SINGLE_ONE_BIT 0x80
-#define BLOCK_SIZE 512
-#define MOD_SIZE 448
-#define APP_SIZE 64
-#define BITS 8
-
-// MD5 Chaining Variable
-#define A 0x67452301UL
-#define B 0xEFCDAB89UL
-#define C 0x98BADCFEUL
-#define D 0x10325476UL
-
-typedef struct
-{
- char *str;
- uint32_t len;
-}MD5String;
-
-
-int32_t wechat_md5 ( char *argv, uint8_t *md5_32);
-
-
-#endif ///WX_AIRSYNC_CFG
-
-#endif /// __APP_AIRSYNC_MD5__
-
-
+++ /dev/null
-#ifndef _APP_AIRSYNC_PRF_H__
-#define _APP_AIRSYNC_PRF_H__
-
-#include "prf_defs.h"
-#if (WX_AIRSYNC_CFG)
-
-
-#include "app_wechat_util.h"
-#include <stdint.h>
-#include <stdbool.h>
-
-#define MAGIC_NUMBER 0xFE
-
-/**
- ****************************************************************************************
- * @brief Create Wechat Database
- *
- ****************************************************************************************
- */
-void app_wechat_create_db(void);
-
-void app_wechat_SetDatahandler(data_handler* pHandler);
-int ble_wechat_indicate_data(uint8_t *data, int len);
-int ble_wechat_indicate_data_chunk(void);
-void ble_wechat_process_received_data(uint8_t* pData, uint32_t length);
-data_handler* app_wechat_datahandler(void);
-bool ble_wechat_is_last_data_sent_out(void);
-
-
-#endif ///WX_AIRSYNC_CFG
-
-#endif ///_APP_AIRSYNC_PRF_H__
-
-
-
+++ /dev/null
- /*
- * DEFINES
- ****************************************************************************************
- */
-#define BUTTON_HEAD (0x01)
-#define BUTTON_PRESS_EVT (0x10)
-
-//the key value enum
-enum
-{
- Button_Up = 0x01,
- Button_Voice = 0x02,
- Button_OK = 0x04,
- Button_Down = 0x08,
- Button_Back = 0x10,
-};
-
-
-typedef struct {
- uint8_t key_val; //button val
- uint8_t head; //the head of the frame
-}key_frame;
-
-
-typedef struct
-{
- bool button_press;
- key_frame key_msg;
-}app_key_env;
-
-
-
-extern app_key_env key_press;
-
-/*
- * FUNCTIONS DECLARATION
- ****************************************************************************************
- */
-
- void app_button_init(void);
-
- void GPIO_isr_callback(void* arg);
-
- uint8_t check_sum(uint8_t *check_array,uint8_t len);
-
- void ble_but_prf_enable(void);
-
- void ble_but_create_svc(void);
-
-
-
+++ /dev/null
-#include "prf_defs.h"
-#include "bt_prf_sys.h"
-#include "bt_types.h"
-
-#if (BUT_PROFILE_CFG)
-
-/// Messages for Device Information Service Server
-enum
-{
- ///Add a BUTTON instance into the database
- BLE_BUT_CREATE_DB_REQ_EVT = BT_PRF_SYS_EVT_START(PRF_ID_BUT_LE),
- ///Send key value confirm to APP so stable values can be erased
- ///if correctly sent.
- BLE_BUT_VAL_SEND_CFM_EVT,
- ///Set the value of an attribute
- BLE_BUT_SET_CHAR_VAL_REQ_EVT,
-
- ///Start the button notify Service Task - at connection
- BLE_BUT_ENABLE_REQ_EVT,
-
- /// Inform the application that the profile service role task has been disabled after a disconnection
- BLE_BUT_DISABLE_IND_EVT,
- /// Inform the application that the profile service has been reiceivd the charateristic write commamd from Client
- BLE_BUT_CHAR_WRITE_IND_EVT,
- ///Error indication to Host
- BLE_BUT_ERROR_IND_EVT,
-};
-
-/// Parameters of the @ref KEY_CREATE_DB_REQ message
-typedef struct
-{
- ///Database configuration
- uint16_t features;
-}tBUT_CRT_DB_REQ;
-
-/// Parameters of the @ref KEY_CREATE_DB_CFM message
-typedef struct
-{
- ///Status
- uint8_t status;
-}tBUT_CRT_DB_CFM;
-
-///Parameters of the @ref key_CFG_INDNTF_IND message
-typedef struct
-{
- ///Connection handle
- uint16_t conhdl;
- ///Stop/notify/indicate value to configure into the peer characteristic
- uint16_t cfg_val;
- /// characteristics
- uint8_t char_code;
-}tBUT_CFG_NTF_IND;
-
-
-/// Parameters of the @ref KEY_SET_CHAR_VAL_REQ message - shall be dynamically allocated
-typedef struct
-{
- /// Characteristic Code
- //uint8_t char_code;
- uint8_t conhdl;
- uint8_t key_val_len;
- uint8_t key_val[2];
-}tBUT_SND_CHAR_VAL_REQ;
-
-/// Parameters of the @ref KEY_ENABLE_REQ message
-typedef struct
-{
- ///Connection handle
- uint16_t conhdl;
- /// security level: b0= nothing, b1=unauthenticated, b2=authenticated, b3=authorized; b1 or b2 and b3 can go together
- uint8_t sec_lvl;
- ///Type of connection
- uint8_t con_type;
-}tBUT_ENABLE_REQ;
-
-///Parameters of the @ref KEY_VAL_SEND_CFM message
-typedef struct
-{
- ///Connection handle
- uint16_t conhdl;
- ///Status
- uint8_t status;
-}tBUT_VAL_SND_CFM;
-
-
-/// Parameters of the @ref KEY_DISABLE_IND message
-typedef struct
-{
- ///Connection handle
- uint16_t conhdl;
-}tBUT_DISABLE_IND;
-
-typedef union
-{
- uint16_t conhdl;
- tBUT_CRT_DB_REQ but_crt_db_req;
- tBUT_CRT_DB_CFM but_crt_db_cfm;
- tBUT_CFG_NTF_IND but_cfg_ntf_ind;
- tBUT_SND_CHAR_VAL_REQ but_snd_char_val_req;
- tBUT_ENABLE_REQ but_enable_req;
- tBUT_VAL_SND_CFM but_val_snd_cfm;
- tBUT_DISABLE_IND but_disable_ind;
-}tBUT_PRF_MSG;
-
-
-
-BOOLEAN ble_but_prf_hdl_event(prf_hdr_evt_t *msg_data);
-
-void ble_but_prf_disable(void);
-
-
-
-#endif ///BUT_PROFILE_CFG
-
-
-
+++ /dev/null
-#ifndef __APP_WECHAT_UTIL_H__\r
-#define __APP_WECHAT_UTIL_H__\r
-\r
-#include "prf_defs.h"\r
-#if (WX_AIRSYNC_CFG)\r
-#include <stdint.h>\r
-#include <string.h>\r
-\r
-#define PRODUCT_TYPE_UNKNOWN 0\r
-#define PRODUCT_TYPE_MPBLEDEMO2 1\r
-\r
-typedef void (*data_produce_func)(void *args, uint8_t **r_data, uint32_t *r_len);\r
-typedef void (*data_free_func)(uint8_t *data, uint32_t len);\r
-typedef int (*data_consume_func)(uint8_t *data, uint32_t len);\r
-typedef void (*data_error_func)(int error_code);\r
-\r
-typedef int32_t (*data_button_handler_func)(uint8_t pin_no);\r
-typedef void (*data_main_process_func)(void);\r
-typedef int32_t (*data_init_func)(void);\r
-typedef int32_t (*data_init_peripheral_func)(void);\r
-\r
-typedef struct data_handler{\r
- int m_product_type;\r
- data_produce_func m_data_produce_func;\r
- data_free_func m_data_free_func;\r
- data_consume_func m_data_consume_func;\r
- data_error_func m_data_error_func;\r
- data_init_peripheral_func m_data_init_peripheral_func;\r
- data_init_func m_data_init_func;\r
- data_main_process_func m_data_main_process_func;\r
- data_button_handler_func m_data_button_handler_func;\r
- void *m_data_produce_args;\r
- struct data_handler *next;\r
-} data_handler;\r
-\r
-extern data_handler first_handler;\r
-\r
-#define REGISTER(NAME) \\r
- do { \\r
- data_handler *tmp = &NAME##_data_handler; \\r
- tmp->next = first_handler.next; \\r
- first_handler.next = tmp; \\r
- } while(0)\r
-\r
-#define ARGS_ITEM_SET(ARGS_TYPE, ARGS_POINTER, ITEM_NAME, ITEM_VALUE) \\r
- do { \\r
- ARGS_TYPE *tmp = (ARGS_TYPE *)(ARGS_POINTER); \\r
- tmp->ITEM_NAME = (ITEM_VALUE); \\r
- } while(0)\r
-\r
-\r
-typedef struct\r
-{\r
- unsigned char bMagicNumber;\r
- unsigned char bVer;\r
- unsigned short nLength;\r
- unsigned short nCmdId;\r
- unsigned short nSeq;\r
-} BpFixHead;\r
-\r
-/*\r
- * TYPE DEFINITIONS\r
- ****************************************************************************************\r
- */\r
-\r
-typedef struct\r
-{\r
- uint8_t *data;\r
- uint16_t len;\r
- uint16_t offset;\r
-} data_info;\r
-\r
-data_handler* get_handler_by_type(int type);\r
-unsigned short htons(unsigned short val);\r
-unsigned short ntohs(unsigned short val);\r
-unsigned long t_htonl(unsigned long h);\r
-unsigned long t_ntohl(unsigned long n);\r
-\r
-void wechat_error_chack(data_handler *p_data_handler, int error_code);\r
-void data_handler_init(data_handler** p_data_handler, uint8_t product_type);\r
-\r
-#endif ///WX_AIRSYNC_CFG\r
-\r
-#endif ///__APP_WECHAT_UTIL_H__\r
-\r
+++ /dev/null
-#ifndef __BT_APP_COMMON_H__
-#define __BT_APP_COMMON_H__
-
-#include <stdint.h>
-#include "osi.h"
-#include "bt_common_types.h"
-#include "bt_defs.h"
-
-/* BT APP Events */
-#define BT_EVT_APP (0xB000)
-#define BT_EVT_APP_CONTEXT_SWITCH (0x0001 | BT_EVT_APP)
-
-typedef void (tBTAPP_CBACK) (uint16_t event, char *p_param);
-typedef void (tBTAPP_COPY_CBACK) (uint16_t event, char *p_dest, char *p_src);
-
-typedef struct
-{
- BT_HDR hdr;
- tBTAPP_CBACK* p_cb; /* context switch callback */
-
- /* parameters passed to callback */
- UINT16 event; /* message event id */
- char p_param[0]; /* parameter area needs to be last */
-} tBTAPP_CONTEXT_SWITCH_CBACK;
-
-bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTAPP_COPY_CBACK *p_copy_cback);
-
-void bt_app_init_ok(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);
-
-void bt_app_task_start_up(void);
-#endif /* __BT_APP_COMMON_H__ */
+++ /dev/null
-// epb.h\r
-// MicroMessenger\r
-//\r
-// Created by harlliu@tencent.com on 14-02-15.\r
-// Copyright 2014 Tencent. All rights reserved.\r
-//\r
-\r
-// Version : 1.0.2\r
-\r
-#ifndef __EPB_H__\r
-#define __EPB_H__\r
-\r
-#include "prf_defs.h"\r
-#if (WX_AIRSYNC_CFG)\r
-\r
-\r
-#include <stdint.h>\r
-#include <stdbool.h>\r
-\r
-typedef struct\r
-{\r
- uint8_t *data;\r
- int len;\r
-} Bytes;\r
-\r
-typedef struct\r
-{\r
- const uint8_t *data;\r
- int len;\r
-} CBytes;\r
-\r
-typedef struct\r
-{\r
- char *str;\r
- int len;\r
-} String;\r
-\r
-typedef struct\r
-{\r
- const char *str;\r
- int len;\r
-} CString;\r
-\r
-typedef uint8_t Message;\r
-\r
-typedef struct \r
-{\r
- const uint8_t *unpack_buf;\r
- uint8_t *pack_buf;\r
- int buf_len;\r
- int buf_offset;\r
-} Epb;\r
-\r
-/*\r
- * embeded protobuf unpack functions\r
- */\r
-\r
-void epb_unpack_init(Epb *e, const uint8_t *buf, int len);\r
-bool epb_has_tag(Epb *e, uint16_t tag);\r
-\r
-//Varint\r
-int32_t epb_get_int32(Epb *e, uint16_t tag);\r
-uint32_t epb_get_uint32(Epb *e, uint16_t tag);\r
-int32_t epb_get_sint32(Epb *e, uint16_t tag);\r
-bool epb_get_bool(Epb *e, uint16_t tag);\r
-int epb_get_enum(Epb *e, uint16_t tag);\r
-\r
-//Length Delimited\r
-const char *epb_get_string(Epb *e, uint16_t tag, int *len);\r
-const uint8_t *epb_get_bytes(Epb *e, uint16_t tag, int *len);\r
-const Message *epb_get_message(Epb *e, uint16_t tag, int *len);\r
-\r
-//Length Delimited Packed Repeadted Field\r
-//TODO\r
-\r
-//Fixed32\r
-uint32_t epb_get_fixed32(Epb *e, uint16_t tag);\r
-int32_t epb_get_sfixed32(Epb *e, uint16_t tag);\r
-float epb_get_float(Epb *e, uint16_t tag);\r
-\r
-/*\r
- * embeded protobuf pack functions\r
- */\r
-\r
-void epb_pack_init(Epb *e, uint8_t *buf, int len);\r
-int epb_get_packed_size(Epb *e);\r
-\r
-//Varint\r
-int epb_set_int32(Epb *e, uint16_t tag, int32_t value);\r
-int epb_set_uint32(Epb *e, uint16_t tag, uint32_t value);\r
-int epb_set_sint32(Epb *e, uint16_t tag, int32_t value);\r
-int epb_set_bool(Epb *e, uint16_t tag, bool value);\r
-int epb_set_enum(Epb *e, uint16_t tag, int value);\r
-\r
-//Length Delimited\r
-int epb_set_string(Epb *e, uint16_t tag, const char *data, int len);\r
-int epb_set_bytes(Epb *e, uint16_t tag, const uint8_t *data, int len);\r
-int epb_set_message(Epb *e, uint16_t tag, const Message *data, int len);\r
-\r
-//Length Delimited Packed Repeadted Field\r
-//TODO\r
-\r
-//Fixed32\r
-int epb_set_fixed32(Epb *e, uint16_t tag, uint32_t value);\r
-int epb_set_sfixed32(Epb *e, uint16_t tag, int32_t value);\r
-int epb_set_float(Epb *e, uint16_t tag, float value);\r
-\r
-//Pack size\r
-int epb_varint32_pack_size(uint16_t tag, uint32_t value, bool is_signed);\r
-int epb_fixed32_pack_size(uint16_t tag);\r
-int epb_length_delimited_pack_size(uint16_t tag, int len);\r
-\r
-\r
-#endif ///WX_AIRSYNC_CFG\r
-\r
-#endif ///__EPB_H__\r
-\r
+++ /dev/null
-// epb_MmBp.h\r
-// WeChat Embedded Proto Buffer\r
-//\r
-// Generated by harlliu@tencent.com on 14-11-26.\r
-// Copyright 2014 Tencent. All rights reserved.\r
-//\r
-\r
-// Version : 1.0.4\r
-\r
-#ifndef __EPB_MMBP_H__\r
-#define __EPB_MMBP_H__\r
-\r
-#include "prf_defs.h"\r
-#if (WX_AIRSYNC_CFG)\r
-\r
-\r
-#include "epb.h"\r
-\r
-typedef enum\r
-{\r
- ECI_none = 0,\r
- ECI_req_auth = 10001,\r
- ECI_req_sendData = 10002,\r
- ECI_req_init = 10003,\r
- ECI_resp_auth = 20001,\r
- ECI_resp_sendData = 20002,\r
- ECI_resp_init = 20003,\r
- ECI_push_recvData = 30001,\r
- ECI_push_switchView = 30002,\r
- ECI_push_switchBackgroud = 30003,\r
- ECI_err_decode = 29999\r
-} EmCmdId;\r
-\r
-typedef enum\r
-{\r
- EEC_system = -1,\r
- EEC_needAuth = -2,\r
- EEC_sessionTimeout = -3,\r
- EEC_decode = -4,\r
- EEC_deviceIsBlock = -5,\r
- EEC_serviceUnAvalibleInBackground = -6,\r
- EEC_deviceProtoVersionNeedUpdate = -7,\r
- EEC_phoneProtoVersionNeedUpdate = -8,\r
- EEC_maxReqInQueue = -9,\r
- EEC_userExitWxAccount = -10\r
-} EmErrorCode;\r
-\r
-typedef enum\r
-{\r
- EAM_md5 = 1,\r
- EAM_macNoEncrypt = 2\r
-} EmAuthMethod;\r
-\r
-typedef enum\r
-{\r
- EIRFF_userNickName = 0x1,\r
- EIRFF_platformType = 0x2,\r
- EIRFF_model = 0x4,\r
- EIRFF_os = 0x8,\r
- EIRFF_time = 0x10,\r
- EIRFF_timeZone = 0x20,\r
- EIRFF_timeString = 0x40\r
-} EmInitRespFieldFilter;\r
-\r
-typedef enum\r
-{\r
- EIS_deviceChat = 1,\r
- EIS_autoSync = 2\r
-} EmInitScence;\r
-\r
-typedef enum\r
-{\r
- EPT_ios = 1,\r
- EPT_andriod = 2,\r
- EPT_wp = 3,\r
- EPT_s60v3 = 4,\r
- EPT_s60v5 = 5,\r
- EPT_s40 = 6,\r
- EPT_bb = 7\r
-} EmPlatformType;\r
-\r
-typedef enum\r
-{\r
- EDDT_manufatureSvr = 0,\r
- EDDT_wxWristBand = 1,\r
- EDDT_wxDeviceHtmlChatView = 10001\r
-} EmDeviceDataType;\r
-\r
-typedef enum\r
-{\r
- ESVO_enter = 1,\r
- ESVO_exit = 2\r
-} EmSwitchViewOp;\r
-\r
-typedef enum\r
-{\r
- EVI_deviceChatView = 1,\r
- EVI_deviceChatHtmlView = 2\r
-} EmViewId;\r
-\r
-typedef enum\r
-{\r
- ESBO_enterBackground = 1,\r
- ESBO_enterForground = 2,\r
- ESBO_sleep = 3\r
-} EmSwitchBackgroundOp;\r
-\r
-typedef struct\r
-{\r
- void *none;\r
-} BaseRequest;\r
-\r
-typedef struct\r
-{\r
- int32_t err_code;\r
- bool has_err_msg;\r
- CString err_msg;\r
-} BaseResponse;\r
-\r
-typedef struct\r
-{\r
- void *none;\r
-} BasePush;\r
-\r
-typedef struct\r
-{\r
- BaseRequest *base_request;\r
- bool has_md5_device_type_and_device_id;\r
- Bytes md5_device_type_and_device_id;\r
- int32_t proto_version;\r
- int32_t auth_proto;\r
- EmAuthMethod auth_method;\r
- bool has_aes_sign;\r
- Bytes aes_sign;\r
- bool has_mac_address;\r
- Bytes mac_address;\r
- bool has_time_zone;\r
- String time_zone;\r
- bool has_language;\r
- String language;\r
- bool has_device_name;\r
- String device_name;\r
-} AuthRequest;\r
-\r
-typedef struct\r
-{\r
- BaseResponse *base_response;\r
- CBytes aes_session_key;\r
-} AuthResponse;\r
-\r
-typedef struct\r
-{\r
- BaseRequest *base_request;\r
- bool has_resp_field_filter;\r
- Bytes resp_field_filter;\r
- bool has_challenge;\r
- Bytes challenge;\r
-} InitRequest;\r
-\r
-typedef struct\r
-{\r
- BaseResponse *base_response;\r
- uint32_t user_id_high;\r
- uint32_t user_id_low;\r
- bool has_challeange_answer;\r
- uint32_t challeange_answer;\r
- bool has_init_scence;\r
- EmInitScence init_scence;\r
- bool has_auto_sync_max_duration_second;\r
- uint32_t auto_sync_max_duration_second;\r
- bool has_user_nick_name;\r
- CString user_nick_name;\r
- bool has_platform_type;\r
- EmPlatformType platform_type;\r
- bool has_model;\r
- CString model;\r
- bool has_os;\r
- CString os;\r
- bool has_time;\r
- int32_t time;\r
- bool has_time_zone;\r
- int32_t time_zone;\r
- bool has_time_string;\r
- CString time_string;\r
-} InitResponse;\r
-\r
-typedef struct\r
-{\r
- BaseRequest *base_request;\r
- Bytes data;\r
- bool has_type;\r
- EmDeviceDataType type;\r
-} SendDataRequest;\r
-\r
-typedef struct\r
-{\r
- BaseResponse *base_response;\r
- bool has_data;\r
- CBytes data;\r
-} SendDataResponse;\r
-\r
-typedef struct\r
-{\r
- BasePush *base_push;\r
- CBytes data;\r
- bool has_type;\r
- EmDeviceDataType type;\r
-} RecvDataPush;\r
-\r
-typedef struct\r
-{\r
- BasePush *base_push;\r
- EmSwitchViewOp switch_view_op;\r
- EmViewId view_id;\r
-} SwitchViewPush;\r
-\r
-typedef struct\r
-{\r
- BasePush *base_push;\r
- EmSwitchBackgroundOp switch_background_op;\r
-} SwitchBackgroudPush;\r
-\r
-BaseResponse *epb_unpack_base_response(const uint8_t *buf, int buf_len);\r
-void epb_unpack_base_response_free(BaseResponse *response);\r
-int epb_auth_request_pack_size(AuthRequest *request);\r
-int epb_pack_auth_request(AuthRequest *request, uint8_t *buf, int buf_len);\r
-AuthResponse *epb_unpack_auth_response(const uint8_t *buf, int buf_len);\r
-void epb_unpack_auth_response_free(AuthResponse *response);\r
-int epb_init_request_pack_size(InitRequest *request);\r
-int epb_pack_init_request(InitRequest *request, uint8_t *buf, int buf_len);\r
-InitResponse *epb_unpack_init_response(const uint8_t *buf, int buf_len);\r
-void epb_unpack_init_response_free(InitResponse *response);\r
-int epb_send_data_request_pack_size(SendDataRequest *request);\r
-int epb_pack_send_data_request(SendDataRequest *request, uint8_t *buf, int buf_len);\r
-SendDataResponse *epb_unpack_send_data_response(const uint8_t *buf, int buf_len);\r
-void epb_unpack_send_data_response_free(SendDataResponse *response);\r
-RecvDataPush *epb_unpack_recv_data_push(const uint8_t *buf, int buf_len);\r
-void epb_unpack_recv_data_push_free(RecvDataPush *push);\r
-SwitchViewPush *epb_unpack_switch_view_push(const uint8_t *buf, int buf_len);\r
-void epb_unpack_switch_view_push_free(SwitchViewPush *push);\r
-SwitchBackgroudPush *epb_unpack_switch_backgroud_push(const uint8_t *buf, int buf_len);\r
-void epb_unpack_switch_backgroud_push_free(SwitchBackgroudPush *push);\r
-\r
-\r
-#endif ///WX_AIRSYNC_CFG\r
-\r
-#endif ///__EPB_MMBP_H__\r
-\r
+++ /dev/null
-/******************************************************************************
- *
- * Copyright (C) 1999-2013 Broadcom Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-/*******************************************************************************
-**
-** Header file for gatt client.
-**
-********************************************************************************/
-
-#include "bt_target.h"
-#include "gatt_api.h"
-#include "gattdefs.h"
-
-/*******************************************************************************
-** BATTERY CLIENT API
-*******************************************************************************/
-/***************************************************************
-**
-** Function bac_register
-**
-** Description register app for battery service
-**
-****************************************************************/
-extern void bac_register(void);
-
-extern void gattc_client_test(void);
-#ifdef __cplusplus
-
-}
-#endif
-
+++ /dev/null
-\r
-#ifndef __MPBLEDEMO2_H__\r
-#define __MPBLEDEMO2_H__\r
-\r
-#include "prf_defs.h"\r
-\r
-#if (WX_AIRSYNC_CFG)\r
-\r
-\r
-#include <string.h>\r
-#include <stdlib.h>\r
-#include <stdint.h>\r
-#include <stdio.h>\r
-#include <stdbool.h>\r
-#include "epb_MmBp.h"\r
-#include "app_airsync_prf.h"\r
-\r
-#define CMD_NULL 0\r
-#define CMD_AUTH 1\r
-#define CMD_INIT 2\r
-#define CMD_SENDDAT 3\r
-\r
-#define DEVICE_TYPE "gh_b57f1be552dd" \r
-#define DEVICE_ID "gh_b57f1be552dd_8ecc3b117f8c05112638289b0952c797" //"wechat_dialog" \r
-#define PROTO_VERSION 0x010004\r
-#define AUTH_PROTO 1\r
-\r
-#define MAC_ADDRESS_LENGTH 6\r
-\r
-//#define EAM_md5AndNoEnrypt 1 \r
-#define EAM_md5AndAesEnrypt 1\r
-//#define EAM_macNoEncrypt 2\r
-\r
-#define DEVICE_KEY {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};\r
-\r
-#ifdef EAM_macNoEncrypt\r
- #define AUTH_METHOD EAM_macNoEncrypt\r
- #define MD5_TYPE_AND_ID_LENGTH 0\r
- #define CIPHER_TEXT_LENGTH 0\r
-#endif\r
-\r
-#ifdef EAM_md5AndAesEnrypt\r
- #define AUTH_METHOD EAM_md5AndAesEnrypt\r
- #define MD5_TYPE_AND_ID_LENGTH 16\r
- #define CIPHER_TEXT_LENGTH 16\r
-#endif\r
-#ifdef EAM_md5AndNoEnrypt\r
- #define AUTH_METHOD EAM_md5AndNoEnrypt\r
- #define MD5_TYPE_AND_ID_LENGTH 16\r
- #define CIPHER_TEXT_LENGTH 0\r
-#endif\r
-\r
-#define CHALLENAGE_LENGTH 4\r
-\r
-#define MPBLEDEMO2_MAGICCODE_H 0xfe\r
-#define MPBLEDEMO2_MAGICCODE_L 0xcf\r
-#define MPBLEDEMO2_VERSION 0x01\r
-#define SEND_HELLO_WECHAT "Hello, WeChat!"\r
-\r
-/* Hardware Resources define */\r
-#define MPBLEDEMO2_LIGHT 19\r
-#define MPBLEDEMO2_BUTTON_1 17\r
-\r
-typedef enum\r
-{\r
- errorCodeUnpackAuthResp = 0x9990,\r
- errorCodeUnpackInitResp = 0x9991,\r
- errorCodeUnpackSendDataResp = 0x9992,\r
- errorCodeUnpackCtlCmdResp = 0x9993,\r
- errorCodeUnpackRecvDataPush = 0x9994,\r
- errorCodeUnpackSwitchViewPush = 0x9995,\r
- errorCodeUnpackSwitchBackgroundPush = 0x9996,\r
- errorCodeUnpackErrorDecode = 0x9997,\r
-} mpbledemo2UnpackErrorCode;\r
-\r
-typedef enum\r
-{\r
- errorCodeProduce = 0x9980,\r
-} mpbledemo2PackErrorCode;\r
-\r
-\r
-// command ID between device and vendor server\r
-typedef enum\r
-{\r
- sendTextReq = 0x01,\r
- \r
- sendTextResp = 0x1001,\r
- openLightPush = 0x2001,\r
- closeLightPush = 0x2002,\r
-} BleDemo2CmdID;\r
-\r
-typedef struct\r
-{\r
- uint8_t m_magicCode[2];\r
- uint16_t m_version;\r
- uint16_t m_totalLength;\r
- uint16_t m_cmdid;\r
- uint16_t m_seq;\r
- uint16_t m_errorCode;\r
-} BlueDemoHead;\r
-\r
-typedef struct \r
-{\r
- int cmd;\r
- CString send_msg;\r
-} mpbledemo2_info;\r
-\r
- typedef struct \r
-{\r
- bool wechats_switch_state; //¹«ÖÚÕ˺ÅÇл»µ½Ç°Ì¨µÄ״̬\r
- bool indication_state;\r
- bool auth_state;\r
- bool init_state;\r
- bool auth_send;\r
- bool init_send;\r
- unsigned short send_data_seq;\r
- unsigned short push_data_seq;\r
- unsigned short seq; \r
-}mpbledemo2_state;\r
-\r
-typedef void (*mpbledemo2_handler_func)(uint8_t *ptrData, uint32_t lengthInByte);\r
-\r
-typedef struct\r
-{\r
- BleDemo2CmdID commandCode;\r
- mpbledemo2_handler_func handler; \r
-} MPBLEDEMO2_RECEIVED_CMD_HANDLER_T;\r
-\r
-extern data_handler mpbledemo2_data_handler;\r
-extern data_handler *m_mpbledemo2_handler;\r
-\r
-extern void mpbledemo2_reset(void);\r
-extern void mpbledemo2_indication_state(bool isEnable);\r
-extern int32_t mpbledemo2_sendData(uint8_t* ptrData, uint32_t lengthInByte);\r
-\r
-\r
-#endif ///WX_AIRSYNC_CFG\r
-\r
-#endif ///__MPBLEDEMO2_H__\r
-\r
+++ /dev/null
-// crc32.h\r
-// WeChat Embedded\r
-//\r
-// Created by harlliu on 14-03-03.\r
-// Copyright 2014 Tencent. All rights reserved.\r
-//\r
-\r
-#ifndef __CRC32_H__\r
-#define __CRC32_H__\r
-\r
-\r
-#include "prf_defs.h"\r
-#if (WX_AIRSYNC_CFG)\r
-\r
-#include <stdint.h>\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-uint32_t crc32(uint32_t crc, const uint8_t *buf, int len);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif ///__cplusplus\r
-\r
-#endif ///WX_AIRSYNC_CFG\r
-\r
-#endif ///__CRC32_H__\r
-\r
+++ /dev/null
-///////////////////////////////////////////////////////////////////////////////\r
-// ÎÄ ¼þ Ãû£ºAES.h\r
-// Ãè Êö£ºAES¼ÓÃÜËã·¨\r
-// ´´ ½¨ ÈË£ºLiangbofu\r
-// ´´½¨ÈÕÆÚ£º2009-07-17\r
-///////////////////////////////////////////////////////////////////////////////\r
-#ifndef __WECHAT_AES_H\r
-#define __WECHAT_AES_H\r
-\r
-#include "prf_defs.h"\r
-#if (WX_AIRSYNC_CFG)\r
-\r
-#ifdef __cplusplus\r
- extern "C" {\r
-#endif\r
-\r
-// ÒÔbitΪµ¥Î»µÄÃÜÔ¿³¤¶È£¬Ö»ÄÜΪ 128£¬192 ºÍ 256 ÈýÖÖ\r
-#define AES_KEY_LENGTH 128\r
-\r
-// ¼Ó½âÃÜģʽ\r
-#define AES_MODE_ECB 0 // µç×ÓÃÜÂ뱾ģʽ£¨Ò»°ãģʽ£©\r
-#define AES_MODE_CBC 1 // ÃÜÂë·Ö×éÁ´½Óģʽ\r
-#define AES_MODE AES_MODE_CBC\r
-\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º AES_Init\r
-// ÃèÊö£º ³õʼ»¯£¬ÔÚ´ËÖ´ÐÐÀ©Õ¹ÃÜÔ¿²Ù×÷¡£\r
-// ÊäÈë²ÎÊý£º pKey -- ÔʼÃÜÔ¿£¬Æ䳤¶È±ØÐëΪ AES_KEY_LENGTH/8 ×Ö½Ú¡£\r
-// Êä³ö²ÎÊý£º ÎÞ¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-///////////////////////////////////////////////////////////////////////////////\r
-void AES_Init(const void *pKey);\r
-\r
-//////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º AES_Encrypt\r
-// ÃèÊö£º ¼ÓÃÜÊý¾Ý\r
-// ÊäÈë²ÎÊý£º pPlainText -- Ã÷ÎÄ£¬¼´Ðè¼ÓÃܵÄÊý¾Ý£¬Æ䳤¶ÈΪnDataLen×Ö½Ú¡£\r
-// nDataLen -- Êý¾Ý³¤¶È£¬ÒÔ×Ö½ÚΪµ¥Î»£¬±ØÐëΪAES_KEY_LENGTH/8µÄÕû±¶Êý¡£\r
-// pIV -- ³õʼ»¯ÏòÁ¿£¬Èç¹ûʹÓÃECBģʽ£¬¿ÉÉèΪNULL¡£\r
-// Êä³ö²ÎÊý£º pCipherText -- ÃÜÎÄ£¬¼´ÓÉÃ÷ÎļÓÃܺóµÄÊý¾Ý£¬¿ÉÒÔÓëpPlainTextÏàͬ¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-//////////////////////////////////////////////////////////////////////////\r
-void AES_Encrypt(const unsigned char *pPlainText, unsigned char *pCipherText, \r
- unsigned int nDataLen, const unsigned char *pIV);\r
-\r
-//////////////////////////////////////////////////////////////////////////\r
-// º¯ÊýÃû£º AES_Decrypt\r
-// ÃèÊö£º ½âÃÜÊý¾Ý\r
-// ÊäÈë²ÎÊý£º pCipherText -- ÃÜÎÄ£¬¼´Ðè½âÃܵÄÊý¾Ý£¬Æ䳤¶ÈΪnDataLen×Ö½Ú¡£\r
-// nDataLen -- Êý¾Ý³¤¶È£¬ÒÔ×Ö½ÚΪµ¥Î»£¬±ØÐëΪAES_KEY_LENGTH/8µÄÕû±¶Êý¡£\r
-// pIV -- ³õʼ»¯ÏòÁ¿£¬Èç¹ûʹÓÃECBģʽ£¬¿ÉÉèΪNULL¡£\r
-// Êä³ö²ÎÊý£º pPlainText -- Ã÷ÎÄ£¬¼´ÓÉÃÜÎĽâÃܺóµÄÊý¾Ý£¬¿ÉÒÔÓëpCipherTextÏàͬ¡£\r
-// ·µ»ØÖµ£º ÎÞ¡£\r
-//////////////////////////////////////////////////////////////////////////\r
-void AES_Decrypt(unsigned char *pPlainText, const unsigned char *pCipherText, \r
- unsigned int nDataLen, const unsigned char *pIV);\r
-\r
-//¶ÔÊý¾Ý½øÐнâÃܲÙ×÷£¬³É¹¦·µ»Ø1£¬Ê§°Ü·µ»Ø0\r
-unsigned char app_data_encode_aes(char *input, char *output, unsigned short *slen);\r
-unsigned char app_data_decode_aes(unsigned char *input, char *output, unsigned short *slen);\r
-unsigned int AES_Encrypt_PKCS7(const unsigned char *pPlainText, unsigned char *pCipherText, \r
- unsigned int nDataLen, const unsigned char *pIV);\r
-unsigned int AES_get_length(unsigned int length);\r
-void AES_free(unsigned char* p);\r
-#ifdef __cplusplus\r
- }\r
-#endif ///__cplusplus\r
-\r
-#endif ///WX_AIRSYNC_CFG\r
-\r
-#endif // __WECHAT_AES_H\r
-\r
+++ /dev/null
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "bt.h"
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "string.h"
-
-
-extern void bte_main_boot_entry(void *);
-extern void bt_app_task_start_up(void);
-extern void bt_app_core_start(void);
-
-void pingTask(void *pvParameters)
-{
- while (1) {
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- //printf("ping\n");
- }
-}
-
-void app_main()
-{
- bt_controller_init();
- xTaskCreatePinnedToCore(&pingTask, "pingTask", 2048, NULL, 5, NULL, 0);
- bt_app_task_start_up();
- bte_main_boot_entry(bt_app_core_start);
-}
+++ /dev/null
-#
-# This is a project Makefile. It is assumed the directory this Makefile resides in is a
-# project subdirectory.
-#
-
-PROJECT_NAME := bluedroid_demos
-
-COMPONENT_ADD_INCLUDEDIRS := components/include
-
-include $(IDF_PATH)/make/project.mk
-
+++ /dev/null
-#
-# Main Makefile. This is basically the same as a component makefile.
-#
-# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default,
-# this will take the sources in the src/ directory, compile them and link them into
-# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
-# please read the ESP-IDF documents if you need to do this.
-#
-
-include $(IDF_PATH)/make/component_common.mk