mirror of
https://github.com/openharmony/device_soc_winnermicro.git
synced 2026-06-30 22:17:56 -04:00
@@ -59,10 +59,10 @@ void tls_bt_dump_hexstring(const char *info, uint8_t *p, int length)
|
||||
{
|
||||
int i = 0, j = 0;
|
||||
printf("%s\r\n", info);
|
||||
for (i = 0; i<length; i++) {
|
||||
for (i = 0; i < length; i++) {
|
||||
j++;
|
||||
printf("%02x ", p[i]);
|
||||
if ((j%16) == 0) {
|
||||
if ((j % 16) == 0) { // 16:byte alignment
|
||||
printf("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ static int gap_event(struct ble_gap_event *event, void *arg);
|
||||
|
||||
static void app_adapter_state_changed_callback(tls_bt_state_t status)
|
||||
{
|
||||
BLE_IF_DEBUG("adapter status = %s\r\n", status==WM_BT_STATE_ON?"bt_state_on":"bt_state_off");
|
||||
BLE_IF_DEBUG("adapter status = %s\r\n", status == WM_BT_STATE_ON ? "bt_state_on" : "bt_state_off");
|
||||
|
||||
bt_adapter_state = status;
|
||||
|
||||
@@ -92,7 +92,6 @@ static void app_adapter_state_changed_callback(tls_bt_state_t status)
|
||||
static void on_sync(void)
|
||||
{
|
||||
/* Make sure we have proper identity address set (public preferred) */
|
||||
|
||||
app_adapter_state_changed_callback(WM_BT_STATE_ON);
|
||||
}
|
||||
static void on_reset(int reason)
|
||||
@@ -118,10 +117,8 @@ static void on_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
|
||||
btuuid.uuidLen = ctxt->svc.svc_def->uuid->type;
|
||||
ble_uuid_flat(ctxt->svc.svc_def->uuid, buf);
|
||||
btuuid.uuid = buf;
|
||||
|
||||
if (gatts_struct_func_ptr_cb->serviceAddCb) {
|
||||
gatts_struct_func_ptr_cb->serviceAddCb(0 /* Always success */, server_if /* */, \
|
||||
&btuuid, ctxt->svc.handle);
|
||||
gatts_struct_func_ptr_cb->serviceAddCb(0, server_if, &btuuid, ctxt->svc.handle);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -141,8 +138,8 @@ static void on_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
|
||||
ble_uuid_flat(ctxt->chr.chr_def->uuid, buf);
|
||||
btuuid.uuid = buf;
|
||||
if (gatts_struct_func_ptr_cb->characteristicAddCb) {
|
||||
gatts_struct_func_ptr_cb->characteristicAddCb(0 /* Always success */, server_if /* */, &btuuid , \
|
||||
service_handle /* msg->ser_add_char.service_id */, ctxt->chr.val_handle);
|
||||
gatts_struct_func_ptr_cb->characteristicAddCb(0, server_if, &btuuid , \
|
||||
service_handle, ctxt->chr.val_handle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,8 +157,8 @@ static void on_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
|
||||
ble_uuid_flat(ctxt->dsc.dsc_def->uuid, buf);
|
||||
btuuid.uuid = buf;
|
||||
if (gatts_struct_func_ptr_cb->descriptorAddCb) {
|
||||
gatts_struct_func_ptr_cb->descriptorAddCb(0 /* Always success */, server_if /* */, &btuuid , \
|
||||
service_handle /* msg->ser_add_char.service_id */, ctxt->dsc.handle);
|
||||
gatts_struct_func_ptr_cb->descriptorAddCb(0, server_if, &btuuid , \
|
||||
service_handle, ctxt->dsc.handle);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -179,10 +176,10 @@ static void ble_server_conn_param_update_slave(void)
|
||||
int rc;
|
||||
struct ble_l2cap_sig_update_params params;
|
||||
|
||||
params.itvl_min = 26;
|
||||
params.itvl_max = 42;
|
||||
params.itvl_min = 26; // 26:byte alignment
|
||||
params.itvl_max = 42; // 42:byte alignment
|
||||
params.slave_latency = 0;
|
||||
params.timeout_multiplier = 500;
|
||||
params.timeout_multiplier = 500; // 500:byte alignment
|
||||
rc = ble_l2cap_sig_update(g_conn_handle, ¶ms, conn_param_update_cb, NULL);
|
||||
BLE_IF_DEBUG("ble_l2cap_sig_update, rc=%d\n", rc);
|
||||
}
|
||||
@@ -237,7 +234,7 @@ static int ble_server_start_adv(void)
|
||||
}
|
||||
|
||||
peer_addr.type = g_adv_param.peerAddrType;
|
||||
memcpy_s(&peer_addr.val[0], sizeof(&peer_addr.val), &g_adv_param.peerAddr.addr[0], 6);
|
||||
memcpy_s(&peer_addr.val[0], sizeof(&peer_addr.val), &g_adv_param.peerAddr.addr[0], 6); // 6:size
|
||||
|
||||
BLE_IF_DEBUG("Starting advertising\r\n");
|
||||
|
||||
@@ -269,12 +266,11 @@ static int gap_event(struct ble_gap_event *event, void *arg)
|
||||
if (event->connect.status == 0) {
|
||||
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
|
||||
assert(rc == 0);
|
||||
memcpy_s(bdaddr.addr, sizeof(bdaddr.addr), desc.peer_id_addr.val, 6);
|
||||
memcpy_s(bdaddr.addr, sizeof(bdaddr.addr), desc.peer_id_addr.val, 6); // 6:size
|
||||
g_conn_handle = event->connect.conn_handle;
|
||||
/* see nble_server.c ble_server_gap_event will handle this callback */
|
||||
if (gatts_struct_func_ptr_cb->connectServerCb) {
|
||||
gatts_struct_func_ptr_cb->connectServerCb(event->connect.conn_handle, \
|
||||
0 /* Always 0,nimble does not care server if */, &bdaddr);
|
||||
gatts_struct_func_ptr_cb->connectServerCb(event->connect.conn_handle, 0, &bdaddr);
|
||||
}
|
||||
/* 200 ticks later, perform l2cap level connect param update */
|
||||
}
|
||||
@@ -286,15 +282,14 @@ static int gap_event(struct ble_gap_event *event, void *arg)
|
||||
case BLE_GAP_EVENT_DISCONNECT:
|
||||
BLE_IF_DEBUG("disconnect reason=%d\r\n", event->disconnect.reason);
|
||||
|
||||
memcpy_s(bdaddr.addr, sizeof(bdaddr.addr), event->disconnect.conn.peer_id_addr.val, 6);
|
||||
memcpy_s(bdaddr.addr, sizeof(bdaddr.addr), event->disconnect.conn.peer_id_addr.val, 6); // 6:size
|
||||
/* see nble_server.c ble_server_gap_event will handle this callback */
|
||||
if (gatts_struct_func_ptr_cb->disconnectServerCb) {
|
||||
gatts_struct_func_ptr_cb->disconnectServerCb(event->disconnect.conn.conn_handle, \
|
||||
0 /* Always 0, nimble does not care server if */, &bdaddr);
|
||||
gatts_struct_func_ptr_cb->disconnectServerCb(event->disconnect.conn.conn_handle, 0, &bdaddr);
|
||||
}
|
||||
|
||||
if (event->disconnect.reason == 534) {
|
||||
// hci error code: 0x16 + 0x200 = 534; // local host terminate the connection;
|
||||
if (event->disconnect.reason == 534) { // 534:hci error code: 0x16 + 0x200 = 534
|
||||
// local host terminate the connection;
|
||||
} else {
|
||||
ble_server_start_adv();
|
||||
}
|
||||
@@ -303,8 +298,7 @@ static int gap_event(struct ble_gap_event *event, void *arg)
|
||||
if (event->notify_tx.status == BLE_HS_EDONE) {
|
||||
// Note, the first param conn__handle, conn_id??? all servcie share one conn_id, so it is not proper
|
||||
if (gatts_struct_func_ptr_cb->indicationSentCb) {
|
||||
gatts_struct_func_ptr_cb->indicationSentCb(event->notify_tx.conn_handle, \
|
||||
0 /* event->notify_tx.status */);
|
||||
gatts_struct_func_ptr_cb->indicationSentCb(event->notify_tx.conn_handle, 0);
|
||||
}
|
||||
} else {
|
||||
/* Application will handle other cases */
|
||||
@@ -345,7 +339,7 @@ static int gap_event(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
rc = ble_gap_conn_find(event->enc_change.conn_handle, &desc);
|
||||
assert(rc == 0);
|
||||
memcpy_s(bdaddr.addr, sizeof(bdaddr.addr), desc.peer_id_addr.val, 6);
|
||||
memcpy_s(bdaddr.addr, sizeof(bdaddr.addr), desc.peer_id_addr.val, 6); // 6:size
|
||||
if (gap_func_ptr_cb && gap_func_ptr_cb->securityRespondCb)gap_func_ptr_cb->securityRespondCb(&bdaddr);
|
||||
return 0;
|
||||
}
|
||||
@@ -407,7 +401,7 @@ int EnableBtStack(void)
|
||||
tls_nimble_start();
|
||||
|
||||
while (bt_adapter_state != WM_BT_STATE_ON) {
|
||||
tls_os_time_delay(100);
|
||||
tls_os_time_delay(100); // 100:time unit
|
||||
}
|
||||
|
||||
bt_system_action = WM_BT_SYSTEM_ACTION_IDLE;
|
||||
@@ -447,7 +441,7 @@ int DisableBtStack(void)
|
||||
|
||||
/* Application levels resource cleanup */
|
||||
while (bt_adapter_state == WM_BT_STATE_ON) {
|
||||
tls_os_time_delay(10);
|
||||
tls_os_time_delay(10); // 10:time unit
|
||||
}
|
||||
|
||||
bt_system_action = WM_BT_SYSTEM_ACTION_IDLE;
|
||||
@@ -685,7 +679,7 @@ int BleGattsSendIndication(int serverId, GattsSendIndParam *param)
|
||||
|
||||
int ReadBtMacAddr(unsigned char *mac, unsigned int len)
|
||||
{
|
||||
if (len != 6) {
|
||||
if (len != 6) { // 6:byte alignment
|
||||
return OHOS_BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
@@ -860,5 +854,4 @@ int BleGattsStopServiceEx(int srvcHandle)
|
||||
}
|
||||
}
|
||||
return OHOS_BT_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -83,7 +83,7 @@ void ble_server_gap_event(struct ble_gap_event *event, void *arg)
|
||||
if (event->connect.status == 0) {
|
||||
int rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
|
||||
assert(rc == 0);
|
||||
memcpy(bdaddr.addr, desc.peer_id_addr.val, 6);
|
||||
memcpy(bdaddr.addr, desc.peer_id_addr.val, 6); // 6:size
|
||||
|
||||
if (gatts_struct_func_ptr_cb && gatts_struct_func_ptr_cb->connectServerCb) {
|
||||
dl_list_for_each(svr_item, &server_list.list, server_elem_t, list)
|
||||
@@ -93,7 +93,7 @@ void ble_server_gap_event(struct ble_gap_event *event, void *arg)
|
||||
}
|
||||
break;
|
||||
case BLE_GAP_EVENT_DISCONNECT:
|
||||
memcpy(bdaddr.addr, event->disconnect.conn.peer_id_addr.val, 6);
|
||||
memcpy(bdaddr.addr, event->disconnect.conn.peer_id_addr.val, 6); // 6:size
|
||||
if (gatts_struct_func_ptr_cb && gatts_struct_func_ptr_cb->disconnectServerCb) {
|
||||
dl_list_for_each(svr_item, &server_list.list, server_elem_t, list)
|
||||
gatts_struct_func_ptr_cb->disconnectServerCb(event->disconnect.conn.conn_handle, \
|
||||
@@ -213,14 +213,14 @@ static int ble_server_gatt_svc_access_func(uint16_t conn_handle, uint16_t attr_h
|
||||
assert(offset <= sizeof(cache_buffer));
|
||||
om = SLIST_NEXT(om, om_next);
|
||||
}
|
||||
if (offset>0)ble_server_func_by_attr_handle(attr_handle, ctxt->op, cache_buffer, &offset);
|
||||
|
||||
if (offset > 0)
|
||||
ble_server_func_by_attr_handle(attr_handle, ctxt->op, cache_buffer, &offset);
|
||||
return 0;
|
||||
}
|
||||
case BLE_GATT_ACCESS_OP_READ_CHR:
|
||||
{
|
||||
ble_server_func_by_attr_handle(attr_handle, ctxt->op, cache_buffer, &length);
|
||||
if (length>0) {
|
||||
if (length > 0) {
|
||||
int rc = os_mbuf_append(ctxt->om, &cache_buffer[0], length);
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
@@ -244,7 +244,7 @@ int ble_server_uuid_init_from_buf(ble_uuid_any_t *uuid, const void *buf, size_t
|
||||
return 0;
|
||||
case OHOS_UUID_TYPE_128_BIT:
|
||||
uuid->u.type = BLE_UUID_TYPE_128;
|
||||
memcpy_s(uuid->u128.value, sizeof(uuid->u128.value), buf, 16);
|
||||
memcpy_s(uuid->u128.value, sizeof(uuid->u128.value), buf, 16); // 16:size
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
@@ -285,7 +285,7 @@ int ble_server_alloc(BleGattService *srvcinfo)
|
||||
serv_elem->srvc_count = 0;
|
||||
|
||||
// presearch to get the counter of character and descriptor;
|
||||
for (i = 0; i<srvcinfo->attrNum; i++) {
|
||||
for (i = 0; i < srvcinfo->attrNum; i++) {
|
||||
if (srvcinfo->attrList[i].attrType == OHOS_BLE_ATTRIB_TYPE_SERVICE) {
|
||||
srvc_counter++;
|
||||
} else if (srvcinfo->attrList[i].attrType == OHOS_BLE_ATTRIB_TYPE_CHAR) {
|
||||
@@ -304,14 +304,14 @@ int ble_server_alloc(BleGattService *srvcinfo)
|
||||
BLE_IF_DEBUG("Adding service srvc=%d, char=%d, dsc=%d\r\n", srvc_counter, char_counter, desc_counter);
|
||||
|
||||
/* alloc service array */
|
||||
gatt_svc_array = (struct ble_gatt_svc_def *)tls_mem_alloc(2*sizeof(struct ble_gatt_svc_def));
|
||||
gatt_svc_array = (struct ble_gatt_svc_def *)tls_mem_alloc(2 * sizeof(struct ble_gatt_svc_def)); // 2:byte alignment
|
||||
assert(gatt_svc_array != NULL);
|
||||
memset_s(gatt_svc_array, sizeof(gatt_svc_array), 0, 2*sizeof(struct ble_gatt_svc_def));
|
||||
memset_s(gatt_svc_array, sizeof(gatt_svc_array), 0, 2 * sizeof(struct ble_gatt_svc_def)); // 2:byte alignment
|
||||
|
||||
/* prealloc charactertistic array */
|
||||
gatt_chr_array = (struct ble_gatt_chr_def *)tls_mem_alloc((1+char_counter) * sizeof(struct ble_gatt_chr_def));
|
||||
gatt_chr_array = (struct ble_gatt_chr_def *)tls_mem_alloc((1 + char_counter) * sizeof(struct ble_gatt_chr_def));
|
||||
assert(gatt_chr_array != NULL);
|
||||
memset_s(gatt_chr_array, sizeof(gatt_chr_array), 0, (1+char_counter) * sizeof(struct ble_gatt_chr_def));
|
||||
memset_s(gatt_chr_array, sizeof(gatt_chr_array), 0, (1 + char_counter) * sizeof(struct ble_gatt_chr_def));
|
||||
|
||||
/* preappending to character array */
|
||||
gatt_svc_array[0].characteristics = gatt_chr_array;
|
||||
@@ -346,10 +346,8 @@ int ble_server_alloc(BleGattService *srvcinfo)
|
||||
/* process stack env */
|
||||
gatt_chr_array[serv_elem->srvc_count].uuid = &srvc_sub_elem->uuid;
|
||||
gatt_chr_array[serv_elem->srvc_count].access_cb = ble_server_gatt_svc_access_func;
|
||||
// gatt_chr_array[serv_elem->srvc_count].flags = srvcinfo->attrList[i].properties \
|
||||
|srvcinfo->attrList[i].permission<<8;
|
||||
gatt_chr_array[serv_elem->srvc_count].flags = srvcinfo->attrList[i].properties;
|
||||
gatt_chr_array[serv_elem->srvc_count].min_key_size = 16;
|
||||
gatt_chr_array[serv_elem->srvc_count].min_key_size = 16; // 16:byte alignment
|
||||
gatt_chr_array[serv_elem->srvc_count].val_handle = &srvc_sub_elem->attr_handle;
|
||||
gatt_chr_array[serv_elem->srvc_count].arg = (void*)&srvc_elem->attr_handle; \
|
||||
// give the service handle as arg, char added callback will handle it;
|
||||
@@ -370,12 +368,15 @@ int ble_server_alloc(BleGattService *srvcinfo)
|
||||
(gatt_chr_array[serv_elem->srvc_count].flags & BLE_GATT_CHR_F_INDICATE)) {
|
||||
// NimBLE stack will auto add the cccd.
|
||||
} else {
|
||||
gatt_dsc_array = (struct ble_gatt_dsc_def *)tls_mem_alloc(2*sizeof(struct ble_gatt_dsc_def));
|
||||
memset_s(gatt_dsc_array, sizeof(gatt_dsc_array), 0, 2*sizeof(struct ble_gatt_dsc_def));
|
||||
gatt_dsc_array =
|
||||
(struct ble_gatt_dsc_def *)tls_mem_alloc(2 * sizeof(struct ble_gatt_dsc_def)); // 2:byte alignment
|
||||
memset_s(gatt_dsc_array, sizeof(gatt_dsc_array), 0,
|
||||
2 * sizeof(struct ble_gatt_dsc_def)); // 2:byte alignment
|
||||
gatt_dsc_array[0].uuid = &srvc_sub_elem->uuid;
|
||||
gatt_dsc_array[0].access_cb = ble_server_gatt_svc_access_func;
|
||||
gatt_dsc_array[0].att_flags = srvcinfo->attrList[i].properties |srvcinfo->attrList[i].permission<<8;
|
||||
gatt_dsc_array[0].min_key_size = 16;
|
||||
gatt_dsc_array[0].att_flags =
|
||||
srvcinfo->attrList[i].properties |srvcinfo->attrList[i].permission << 8; // 8:byte alignment
|
||||
gatt_dsc_array[0].min_key_size = 16; // 16:byte alignment
|
||||
gatt_dsc_array[0].arg = (void*)&srvc_elem->attr_handle;
|
||||
// give the service handle as arg, char added callback will handle it;
|
||||
gatt_chr_array[serv_elem->srvc_count].descriptors = gatt_dsc_array;
|
||||
|
||||
@@ -113,14 +113,14 @@ WifiErrorCode EnableHotspot()
|
||||
apinfo.keyinfo.index = 1; // 1-4 (only wep)
|
||||
}
|
||||
struct tls_ip_info_t ipinfo = {0};
|
||||
ipinfo.ip_addr[0] = 192;
|
||||
ipinfo.ip_addr[1] = 168;
|
||||
ipinfo.ip_addr[2] = 1;
|
||||
ipinfo.ip_addr[3] = 1;
|
||||
ipinfo.netmask[0] = 255;
|
||||
ipinfo.netmask[1] = 255;
|
||||
ipinfo.netmask[2] = 255;
|
||||
ipinfo.netmask[3] = 0;
|
||||
ipinfo.ip_addr[0] = 192; // 192:byte alignment
|
||||
ipinfo.ip_addr[1] = 168; // 168:byte alignment
|
||||
ipinfo.ip_addr[2] = 1; // 2:array element
|
||||
ipinfo.ip_addr[3] = 1; // 3:array element
|
||||
ipinfo.netmask[0] = 255; // 255:byte alignment
|
||||
ipinfo.netmask[1] = 255; // 255:byte alignment
|
||||
ipinfo.netmask[2] = 255; // 255:byte alignment, 2:array element
|
||||
ipinfo.netmask[3] = 0; // 3:array element
|
||||
int retval = tls_wifi_softap_create(&apinfo, &ipinfo);
|
||||
if (retval != WM_SUCCESS) {
|
||||
printf("[wifi_service]:EnableHotspot tls_wifi_softap_create fail, err = %d\n", retval);
|
||||
|
||||
@@ -62,15 +62,15 @@ static char *_path_convert(const char *path)
|
||||
int len;
|
||||
char *target_path;
|
||||
|
||||
len = strlen(path) + 8;
|
||||
len = strlen(path) + 8; // 8:byte alignment
|
||||
target_path = (char *)malloc(len);
|
||||
if (target_path == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memset_s(target_path, len, 0, len);
|
||||
int i, j = 0;
|
||||
memcpy_s(target_path, sizeof(target_path), "/data/", 6);
|
||||
j += 6;
|
||||
memcpy_s(target_path, sizeof(target_path), "/data/", 6); // 6:size
|
||||
j += 6; // 6:byte alignment
|
||||
for (i = 0; i < strlen(path); i++) {
|
||||
if (path[i] != '/') {
|
||||
target_path[j++] = path[i];
|
||||
@@ -113,7 +113,7 @@ int HalFileClose(int fd)
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
ret = close(fd-1);
|
||||
ret = close(fd - 1);
|
||||
if (ret) {
|
||||
return -1;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ int HalFileRead(int fd, char* buf, unsigned int len)
|
||||
if (fd < 0 || (buf == NULL) || (len == 0)) {
|
||||
return -1;
|
||||
}
|
||||
ret = read(fd-1, buf, len);
|
||||
ret = read(fd - 1, buf, len);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+225
-225
File diff suppressed because it is too large
Load Diff
@@ -763,7 +763,7 @@ __STATIC_INLINE void csi_vic_disable_sirq(int32_t IRQn)
|
||||
__STATIC_INLINE uint32_t csi_vic_get_enabled_irq(int32_t IRQn)
|
||||
{
|
||||
int32_t IRQn_tmp = IRQn;
|
||||
IRQn &= 0x7FUL;
|
||||
IRQn_tmp &= 0x7FUL;
|
||||
|
||||
return ((uint32_t)(((VIC->ISER[_IR_IDX(IRQn_tmp)] &
|
||||
(1UL << (((uint32_t)(int32_t)IRQn_tmp % 32) & 0x7FUL))) != 0UL) ? 1UL : 0UL)); // 32:byte alignment
|
||||
@@ -1454,12 +1454,12 @@ __STATIC_INLINE void csi_mpu_config_region(uint32_t idx, uint32_t base_addr, reg
|
||||
__set_PRSR(prsr.w);
|
||||
|
||||
if (size != REGION_SIZE_4KB) {
|
||||
pacr.w &= ~(((1u << (size -11)) - 1) << 12); // 12:byte alignment
|
||||
pacr.w &= ~(((1u << (size -11)) - 1) << 12); // 12:byte alignment, 11:byte alignment
|
||||
}
|
||||
|
||||
pacr.b.size = size;
|
||||
|
||||
capr.w &= ~((0x1 << idx) | (0x3 << (idx * 2 + 8)) | (0x1 << (idx + 24))); // 12:byte alignment
|
||||
capr.w &= ~((0x1 << idx) | (0x3 << (idx * 2 + 8)) | (0x1 << (idx + 24))); // 2:byte, 8:byte, 24:byte
|
||||
capr.w = (capr.w | (attr.nx << idx) | (attr.ap << (idx * 2 + 8)) | // 2:byte , 8:byte alignment
|
||||
(attr.s << (idx + 24))); // 24:byte alignment
|
||||
pacr.w &= ~(((1u << (size -11)) - 1) << 12); // 12:byte alignment, 11:byte alignment
|
||||
|
||||
@@ -134,9 +134,12 @@ extern "C" {
|
||||
*
|
||||
* default max num of station.CNcomment:默认支持的station最大个数.CNend
|
||||
*/
|
||||
#define WIFI_DEFAULT_MAX_NUM_STA 6#ifdef __cplusplus
|
||||
#define WIFI_DEFAULT_MAX_NUM_STA 6
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* end of hi_wifi_api.h */
|
||||
@@ -202,9 +202,9 @@ static inline int digitval(int ch)
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
return ch-'0';
|
||||
} else if (ch >= 'A' && ch <= 'Z') {
|
||||
return ch-'A'+10;
|
||||
return ch-'A' + 10; // 10:byte alignment
|
||||
} else if (ch >= 'a' && ch <= 'z') {
|
||||
return ch-'a'+10;
|
||||
return ch-'a' + 10; // 10:byte alignment
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
@@ -217,50 +217,51 @@ uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n)
|
||||
int d;
|
||||
int base_tmp = base;
|
||||
size_t n_tmp = n;
|
||||
const char *nptr_tmp = nptr;
|
||||
|
||||
while (n_tmp && isspace((unsigned char)*nptr)) {
|
||||
nptr++;
|
||||
while (n_tmp && isspace((unsigned char)*nptr_tmp)) {
|
||||
nptr_tmp++;
|
||||
n_tmp--;
|
||||
}
|
||||
|
||||
/* Single optional + or - */
|
||||
if (n_tmp && *nptr == '-') {
|
||||
if (n_tmp && *nptr_tmp == '-') {
|
||||
minus = 1;
|
||||
nptr++;
|
||||
nptr_tmp++;
|
||||
n_tmp--;
|
||||
} else if (n_tmp && *nptr == '+') {
|
||||
nptr++;
|
||||
} else if (n_tmp && *nptr_tmp == '+') {
|
||||
nptr_tmp++;
|
||||
}
|
||||
|
||||
if (base_tmp == 0) {
|
||||
if (n_tmp >= 2 && nptr[0] == '0' && // 2:byte alignment
|
||||
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
||||
if (n_tmp >= 2 && nptr_tmp[0] == '0' && // 2:byte alignment
|
||||
(nptr_tmp[1] == 'x' || nptr_tmp[1] == 'X')) {
|
||||
n_tmp -= 2; // 2:byte alignment
|
||||
nptr += 2; // 2:byte alignment
|
||||
nptr_tmp += 2; // 2:byte alignment
|
||||
base_tmp = 16; // 16:byte alignment
|
||||
} else if (n_tmp >= 1 && nptr[0] == '0') {
|
||||
} else if (n_tmp >= 1 && nptr_tmp[0] == '0') {
|
||||
n_tmp--;
|
||||
nptr++;
|
||||
nptr_tmp++;
|
||||
base_tmp = 8; // 8:byte alignment
|
||||
} else {
|
||||
base_tmp = 10; // 10:byte alignment
|
||||
}
|
||||
} else if (base_tmp == 16) { // 16:byte alignment
|
||||
if (n_tmp >= 2 && nptr[0] == '0' &&
|
||||
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
||||
if (n_tmp >= 2 && nptr_tmp[0] == '0' &&
|
||||
(nptr_tmp[1] == 'x' || nptr_tmp[1] == 'X')) {
|
||||
n_tmp -= 2; // 2:byte alignment
|
||||
nptr += 2; // 2:byte alignment
|
||||
nptr_tmp += 2; // 2:byte alignment
|
||||
}
|
||||
}
|
||||
|
||||
while (n_tmp && (d = digitval(*nptr)) >= 0 && d < base_tmp) {
|
||||
v = v*base_tmp + d;
|
||||
while (n_tmp && (d = digitval(*nptr_tmp)) >= 0 && d < base_tmp) {
|
||||
v = v * base_tmp + d;
|
||||
n_tmp--;
|
||||
nptr++;
|
||||
nptr_tmp++;
|
||||
}
|
||||
|
||||
if (endptr) {
|
||||
*endptr = (char *)nptr;
|
||||
*endptr = (char *)nptr_tmp;
|
||||
}
|
||||
|
||||
return minus ? -v : v;
|
||||
@@ -301,10 +302,11 @@ enum bail {
|
||||
|
||||
static inline const char *skipspace(const char *p)
|
||||
{
|
||||
while (isspace((unsigned char)*p)) {
|
||||
p++;
|
||||
const char *p_tmp = p;
|
||||
while (isspace((unsigned char)*p_tmp)) {
|
||||
p_tmp++;
|
||||
}
|
||||
return p;
|
||||
return p_tmp;
|
||||
}
|
||||
|
||||
#undef set_bit
|
||||
@@ -687,7 +689,8 @@ static inline void _out_null(char character, void* buffer, size_t idx, size_t ma
|
||||
static inline unsigned int _strnlen_s(const char* str, size_t maxsize)
|
||||
{
|
||||
const char* s;
|
||||
for (s = str; *s && maxsize--; ++s) {
|
||||
size_t maxsize_tmp = maxsize;
|
||||
for (s = str; *s && maxsize_tmp--; ++s) {
|
||||
}
|
||||
return (unsigned int)(s - str);
|
||||
}
|
||||
@@ -714,27 +717,29 @@ static size_t _out_rev(out_fct_type out, char* buffer, size_t idx, size_t maxlen
|
||||
const char* buf, size_t len, unsigned int width, unsigned int flags)
|
||||
{
|
||||
const size_t start_idx = idx;
|
||||
size_t idx_tmp = idx;
|
||||
size_t len_tmp = len;
|
||||
|
||||
// pad spaces up to given width
|
||||
if (!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) {
|
||||
for (size_t i = len; i < width; i++) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
for (size_t i = len_tmp; i < width; i++) {
|
||||
out(' ', buffer, idx_tmp++, maxlen);
|
||||
}
|
||||
}
|
||||
|
||||
// reverse string
|
||||
while (len) {
|
||||
out(buf[--len], buffer, idx++, maxlen);
|
||||
while (len_tmp) {
|
||||
out(buf[--len_tmp], buffer, idx_tmp++, maxlen);
|
||||
}
|
||||
|
||||
// append pad spaces up to given width
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (idx - start_idx < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
while (idx_tmp - start_idx < width) {
|
||||
out(' ', buffer, idx_tmp++, maxlen);
|
||||
}
|
||||
}
|
||||
|
||||
return idx;
|
||||
return idx_tmp;
|
||||
}
|
||||
|
||||
// internal itoa format
|
||||
@@ -870,37 +875,39 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
|
||||
char buf[PRINTF_FTOA_BUFFER_SIZE];
|
||||
size_t len = 0U;
|
||||
double diff = 0.0;
|
||||
double value_tmp = value;
|
||||
unsigned int width_tmp = width;
|
||||
|
||||
// powers of 10
|
||||
static const double pow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
|
||||
|
||||
// test for special values
|
||||
if (value != value) {
|
||||
return _out_rev(out, buffer, idx, maxlen, "nan", 3, width, flags);
|
||||
if (value_tmp != value_tmp) {
|
||||
return _out_rev(out, buffer, idx, maxlen, "nan", 3, width_tmp, flags); // 3:len
|
||||
}
|
||||
if (value < -DBL_MAX) {
|
||||
return _out_rev(out, buffer, idx, maxlen, "fni-", 4, width, flags);
|
||||
if (value_tmp < -DBL_MAX) {
|
||||
return _out_rev(out, buffer, idx, maxlen, "fni-", 4, width_tmp, flags); // 4:len
|
||||
}
|
||||
if (value > DBL_MAX) {
|
||||
if (value_tmp > DBL_MAX) {
|
||||
return _out_rev(out, buffer, idx, maxlen, (flags & FLAGS_PLUS) ? "fni+" : "fni",
|
||||
(flags & FLAGS_PLUS) ? 4U : 3U, width, flags);
|
||||
(flags & FLAGS_PLUS) ? 4U : 3U, width_tmp, flags);
|
||||
}
|
||||
|
||||
// test for very large values
|
||||
// standard printf behavior is to print EVERY whole number digit --
|
||||
// which could be 100s of characters overflowing your buffers == bad
|
||||
if ((value > PRINTF_MAX_FLOAT) || (value < -PRINTF_MAX_FLOAT)) {
|
||||
if ((value_tmp > PRINTF_MAX_FLOAT) || (value_tmp < -PRINTF_MAX_FLOAT)) {
|
||||
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
||||
return _etoa(out, buffer, idx, maxlen, value, prec_tmp, width, flags);
|
||||
return _etoa(out, buffer, idx, maxlen, value_tmp, prec_tmp, width_tmp, flags);
|
||||
#else
|
||||
return 0U;
|
||||
#endif
|
||||
}
|
||||
// test for negative
|
||||
bool negative = false;
|
||||
if (value < 0) {
|
||||
if (value_tmp < 0) {
|
||||
negative = true;
|
||||
value = 0 - value;
|
||||
value_tmp = 0 - value_tmp;
|
||||
}
|
||||
|
||||
// set default precision, if not set explicitly
|
||||
@@ -913,8 +920,8 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
|
||||
prec_tmp--;
|
||||
}
|
||||
|
||||
int whole = (int)value;
|
||||
double tmp = (value - whole) * pow10[prec_tmp];
|
||||
int whole = (int)value_tmp;
|
||||
double tmp = (value_tmp - whole) * pow10[prec_tmp];
|
||||
unsigned long frac = (unsigned long)tmp;
|
||||
diff = tmp - frac;
|
||||
|
||||
@@ -932,7 +939,7 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
|
||||
}
|
||||
|
||||
if (prec_tmp == 0U) {
|
||||
diff = value - (double)whole;
|
||||
diff = value_tmp - (double)whole;
|
||||
if ((diff > 0.5) && (whole & 1)) {
|
||||
// exactly 0.5 and ODD, then round up
|
||||
// 1.5 -> 2, but 2.5 -> 2
|
||||
@@ -968,10 +975,10 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
|
||||
|
||||
// pad leading zeros
|
||||
if (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD)) {
|
||||
if (width && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) {
|
||||
width--;
|
||||
if (width_tmp && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) {
|
||||
width_tmp--;
|
||||
}
|
||||
while ((len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) {
|
||||
while ((len < width_tmp) && (len < PRINTF_FTOA_BUFFER_SIZE)) {
|
||||
buf[len++] = '0';
|
||||
}
|
||||
}
|
||||
@@ -986,7 +993,7 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
|
||||
}
|
||||
}
|
||||
|
||||
return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags);
|
||||
return _out_rev(out, buffer, idx, maxlen, buf, len, width_tmp, flags);
|
||||
}
|
||||
|
||||
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
||||
@@ -995,19 +1002,23 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
|
||||
unsigned int prec, unsigned int width, unsigned int flags)
|
||||
{
|
||||
unsigned int prec_tmp = prec;
|
||||
double value_tmp = value;
|
||||
unsigned int flags_tmp = flags;
|
||||
size_t idx_tmp = idx;
|
||||
char* buffer_tmp = buffer;
|
||||
// check for NaN and special values
|
||||
if ((value != value) || (value > DBL_MAX) || (value < -DBL_MAX)) {
|
||||
return _ftoa(out, buffer, idx, maxlen, value, prec_tmp, width, flags);
|
||||
if ((value_tmp != value_tmp) || (value_tmp > DBL_MAX) || (value_tmp < -DBL_MAX)) {
|
||||
return _ftoa(out, buffer_tmp, idx_tmp, maxlen, value_tmp, prec_tmp, width, flags_tmp);
|
||||
}
|
||||
|
||||
// determine the sign
|
||||
const bool negative = value < 0;
|
||||
const bool negative = value_tmp < 0;
|
||||
if (negative) {
|
||||
value = -value;
|
||||
value_tmp = -value_tmp;
|
||||
}
|
||||
|
||||
// default precision
|
||||
if (!(flags & FLAGS_PRECISION)) {
|
||||
if (!(flags_tmp & FLAGS_PRECISION)) {
|
||||
prec_tmp = PRINTF_DEFAULT_FLOAT_PRECISION;
|
||||
}
|
||||
|
||||
@@ -1018,7 +1029,7 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
|
||||
double F;
|
||||
} conv;
|
||||
|
||||
conv.F = value;
|
||||
conv.F = value_tmp;
|
||||
int exp2 = (int)((conv.U >> 52U) & 0x07FFU) - 1023; // effectively log2
|
||||
conv.U = (conv.U & ((1ULL << 52U) - 1U)) | (1023ULL << 52U); // drop the exponent so conv.F is now in [1,2)
|
||||
// now approximate log10 from the log2 integer part and an expansion of ln around 1.5
|
||||
@@ -1034,7 +1045,7 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
|
||||
conv.F *= 1 + 2 * z / (2 - z + (z2 / (6 + // 2:byte alignment, 6:byte alignment
|
||||
(z2 / (10 + z2 / 14))))); // 10:byte alignment, 14:byte alignment
|
||||
// correct for rounding errors
|
||||
if (value < conv.F) {
|
||||
if (value_tmp < conv.F) {
|
||||
expval--;
|
||||
conv.F /= 10; // 10:byte alignment
|
||||
}
|
||||
@@ -1043,21 +1054,21 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
|
||||
unsigned int minwidth = ((expval < 100) && (expval > -100)) ? 4U : 5U;
|
||||
|
||||
// in "%g" mode, "prec" is the number of *significant figures* not decimals
|
||||
if (flags & FLAGS_ADAPT_EXP) {
|
||||
if (flags_tmp & FLAGS_ADAPT_EXP) {
|
||||
// do we want to fall-back to "%f" mode?
|
||||
if ((value >= 1e-4) && (value < 1e6)) {
|
||||
if ((value_tmp >= 1e-4) && (value_tmp < 1e6)) {
|
||||
if ((int)prec_tmp > expval) {
|
||||
prec_tmp = (unsigned)((int)prec_tmp - expval - 1);
|
||||
} else {
|
||||
prec_tmp = 0;
|
||||
}
|
||||
flags |= FLAGS_PRECISION; // make sure _ftoa respects precision
|
||||
flags_tmp |= FLAGS_PRECISION; // make sure _ftoa respects precision
|
||||
// no characters in exponent
|
||||
minwidth = 0U;
|
||||
expval = 0;
|
||||
} else {
|
||||
// we use one sigfig for the whole part
|
||||
if ((prec_tmp > 0) && (flags & FLAGS_PRECISION)) {
|
||||
if ((prec_tmp > 0) && (flags_tmp & FLAGS_PRECISION)) {
|
||||
--prec_tmp;
|
||||
}
|
||||
}
|
||||
@@ -1072,35 +1083,36 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
|
||||
// not enough characters, so go back to default sizing
|
||||
fwidth = 0U;
|
||||
}
|
||||
if ((flags & FLAGS_LEFT) && minwidth) {
|
||||
if ((flags_tmp & FLAGS_LEFT) && minwidth) {
|
||||
// if we're padding on the right, DON'T pad the floating part
|
||||
fwidth = 0U;
|
||||
}
|
||||
|
||||
// rescale the float value
|
||||
if (expval) {
|
||||
value /= conv.F;
|
||||
value_tmp /= conv.F;
|
||||
}
|
||||
|
||||
// output the floating part
|
||||
const size_t start_idx = idx;
|
||||
idx = _ftoa(out, buffer, idx, maxlen, negative ? -value : value, prec_tmp, fwidth, flags & ~FLAGS_ADAPT_EXP);
|
||||
const size_t start_idx = idx_tmp;
|
||||
idx_tmp = _ftoa(out, buffer_tmp, idx_tmp, maxlen,
|
||||
negative ? -value_tmp : value_tmp, prec_tmp, fwidth, flags_tmp & ~FLAGS_ADAPT_EXP);
|
||||
|
||||
// output the exponent part
|
||||
if (!prec_tmp && minwidth) {
|
||||
// output the exponential symbol
|
||||
out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen);
|
||||
out((flags_tmp & FLAGS_UPPERCASE) ? 'E' : 'e', buffer_tmp, idx_tmp++, maxlen);
|
||||
// output the exponent value
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval,
|
||||
expval < 0, 10, 0, minwidth-1, FLAGS_ZEROPAD | FLAGS_PLUS);
|
||||
idx_tmp = _ntoa_long(out, buffer_tmp, idx_tmp, maxlen, (expval < 0) ? -expval : expval,
|
||||
expval < 0, 10, 0, minwidth-1, FLAGS_ZEROPAD | FLAGS_PLUS);
|
||||
// might need to right-pad spaces
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (idx - start_idx < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
if (flags_tmp & FLAGS_LEFT) {
|
||||
while (idx_tmp - start_idx < width) {
|
||||
out(' ', buffer_tmp, idx_tmp++, maxlen);
|
||||
}
|
||||
}
|
||||
}
|
||||
return idx;
|
||||
return idx_tmp;
|
||||
}
|
||||
#endif // PRINTF_SUPPORT_EXPONENTIAL
|
||||
#endif // PRINTF_SUPPORT_FLOAT
|
||||
@@ -1110,42 +1122,44 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||
{
|
||||
unsigned int flags, width, precision, n;
|
||||
size_t idx = 0U;
|
||||
out_fct_type out_tmp = out;
|
||||
const char* format_tmp = format;
|
||||
|
||||
if (!buffer) {
|
||||
// use null output function
|
||||
out = _out_null;
|
||||
out_tmp = _out_null;
|
||||
}
|
||||
|
||||
while (*format) {
|
||||
while (*format_tmp) {
|
||||
// format specifier? %[flags][width][.precision][length]
|
||||
if (*format != '%') {
|
||||
if (*format_tmp != '%') {
|
||||
// no
|
||||
out(*format, buffer, idx++, maxlen);
|
||||
format++;
|
||||
out_tmp(*format_tmp, buffer, idx++, maxlen);
|
||||
format_tmp++;
|
||||
continue;
|
||||
} else {
|
||||
// yes, evaluate it
|
||||
format++;
|
||||
format_tmp++;
|
||||
}
|
||||
|
||||
// evaluate flags
|
||||
flags = 0U;
|
||||
do {
|
||||
switch (*format) {
|
||||
case '0': flags |= FLAGS_ZEROPAD; format++; n = 1U; break;
|
||||
case '-': flags |= FLAGS_LEFT; format++; n = 1U; break;
|
||||
case '+': flags |= FLAGS_PLUS; format++; n = 1U; break;
|
||||
case ' ': flags |= FLAGS_SPACE; format++; n = 1U; break;
|
||||
case '#': flags |= FLAGS_HASH; format++; n = 1U; break;
|
||||
switch (*format_tmp) {
|
||||
case '0': flags |= FLAGS_ZEROPAD; format_tmp++; n = 1U; break;
|
||||
case '-': flags |= FLAGS_LEFT; format_tmp++; n = 1U; break;
|
||||
case '+': flags |= FLAGS_PLUS; format_tmp++; n = 1U; break;
|
||||
case ' ': flags |= FLAGS_SPACE; format_tmp++; n = 1U; break;
|
||||
case '#': flags |= FLAGS_HASH; format_tmp++; n = 1U; break;
|
||||
default : n = 0U; break;
|
||||
}
|
||||
} while (n);
|
||||
|
||||
// evaluate width field
|
||||
width = 0U;
|
||||
if (_is_digit(*format)) {
|
||||
width = _atoi(&format);
|
||||
} else if (*format == '*') {
|
||||
if (_is_digit(*format_tmp)) {
|
||||
width = _atoi(&format_tmp);
|
||||
} else if (*format_tmp == '*') {
|
||||
const int w = va_arg(va, int);
|
||||
if (w < 0) {
|
||||
flags |= FLAGS_LEFT; // reverse padding
|
||||
@@ -1153,61 +1167,61 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||
} else {
|
||||
width = (unsigned int)w;
|
||||
}
|
||||
format++;
|
||||
format_tmp++;
|
||||
}
|
||||
|
||||
// evaluate precision field
|
||||
precision = 0U;
|
||||
if (*format == '.') {
|
||||
if (*format_tmp == '.') {
|
||||
flags |= FLAGS_PRECISION;
|
||||
format++;
|
||||
if (_is_digit(*format)) {
|
||||
precision = _atoi(&format);
|
||||
} else if (*format == '*') {
|
||||
format_tmp++;
|
||||
if (_is_digit(*format_tmp)) {
|
||||
precision = _atoi(&format_tmp);
|
||||
} else if (*format_tmp == '*') {
|
||||
const int prec = (int)va_arg(va, int);
|
||||
precision = prec > 0 ? (unsigned int)prec : 0U;
|
||||
format++;
|
||||
format_tmp++;
|
||||
}
|
||||
}
|
||||
|
||||
// evaluate length field
|
||||
switch (*format) {
|
||||
switch (*format_tmp) {
|
||||
case 'l' :
|
||||
flags |= FLAGS_LONG;
|
||||
format++;
|
||||
if (*format == 'l') {
|
||||
format_tmp++;
|
||||
if (*format_tmp == 'l') {
|
||||
flags |= FLAGS_LONG_LONG;
|
||||
format++;
|
||||
format_tmp++;
|
||||
}
|
||||
break;
|
||||
case 'h' :
|
||||
flags |= FLAGS_SHORT;
|
||||
format++;
|
||||
if (*format == 'h') {
|
||||
format_tmp++;
|
||||
if (*format_tmp == 'h') {
|
||||
flags |= FLAGS_CHAR;
|
||||
format++;
|
||||
format_tmp++;
|
||||
}
|
||||
break;
|
||||
#if defined(PRINTF_SUPPORT_PTRDIFF_T)
|
||||
case 't' :
|
||||
flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
format_tmp++;
|
||||
break;
|
||||
#endif
|
||||
case 'j' :
|
||||
flags |= (sizeof(intmax_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
format_tmp++;
|
||||
break;
|
||||
case 'z' :
|
||||
flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
format_tmp++;
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
// evaluate specifier
|
||||
switch (*format) {
|
||||
switch (*format_tmp) {
|
||||
case 'd' :
|
||||
case 'i' :
|
||||
case 'u' :
|
||||
@@ -1217,23 +1231,23 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||
case 'b' : {
|
||||
// set the base
|
||||
unsigned int base;
|
||||
if (*format == 'x' || *format == 'X') {
|
||||
if (*format_tmp == 'x' || *format_tmp == 'X') {
|
||||
base = 16U;
|
||||
} else if (*format == 'o') {
|
||||
} else if (*format_tmp == 'o') {
|
||||
base = 8U;
|
||||
} else if (*format == 'b') {
|
||||
} else if (*format_tmp == 'b') {
|
||||
base = 2U;
|
||||
} else {
|
||||
base = 10U;
|
||||
flags &= ~FLAGS_HASH; // no hash for dec format
|
||||
}
|
||||
// uppercase
|
||||
if (*format == 'X') {
|
||||
if (*format_tmp == 'X') {
|
||||
flags |= FLAGS_UPPERCASE;
|
||||
}
|
||||
|
||||
// no plus or space flag for u, x, X, o, b
|
||||
if ((*format != 'i') && (*format != 'd')) {
|
||||
if ((*format_tmp != 'i') && (*format_tmp != 'd')) {
|
||||
flags &= ~(FLAGS_PLUS | FLAGS_SPACE);
|
||||
}
|
||||
|
||||
@@ -1243,67 +1257,67 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||
}
|
||||
|
||||
// convert the integer
|
||||
if ((*format == 'i') || (*format == 'd')) {
|
||||
if ((*format_tmp == 'i') || (*format_tmp == 'd')) {
|
||||
// signed
|
||||
if (flags & FLAGS_LONG_LONG) {
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
const long long value = va_arg(va, long long);
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen,
|
||||
idx = _ntoa_long_long(out_tmp, buffer, idx, maxlen,
|
||||
(unsigned long long)(value > 0 ? value : 0 - value),
|
||||
value < 0, base, precision, width, flags);
|
||||
#endif
|
||||
} else if (flags & FLAGS_LONG) {
|
||||
const long value = va_arg(va, long);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value),
|
||||
idx = _ntoa_long(out_tmp, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value),
|
||||
value < 0, base, precision, width, flags);
|
||||
} else {
|
||||
const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) : \
|
||||
(flags & FLAGS_SHORT) ? (short int)va_arg(va, int) : va_arg(va, int);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value),
|
||||
idx = _ntoa_long(out_tmp, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value),
|
||||
value < 0, base, precision, width, flags);
|
||||
}
|
||||
} else {
|
||||
// unsigned
|
||||
if (flags & FLAGS_LONG_LONG) {
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long),
|
||||
idx = _ntoa_long_long(out_tmp, buffer, idx, maxlen, va_arg(va, unsigned long long),
|
||||
false, base, precision, width, flags);
|
||||
#endif
|
||||
} else if (flags & FLAGS_LONG) {
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long),
|
||||
idx = _ntoa_long(out_tmp, buffer, idx, maxlen, va_arg(va, unsigned long),
|
||||
false, base, precision, width, flags);
|
||||
} else {
|
||||
const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) : \
|
||||
(flags & FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int) : \
|
||||
va_arg(va, unsigned int);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags);
|
||||
idx = _ntoa_long(out_tmp, buffer, idx, maxlen, value, false, base, precision, width, flags);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
format_tmp++;
|
||||
break;
|
||||
}
|
||||
#if defined(PRINTF_SUPPORT_FLOAT)
|
||||
case 'f' :
|
||||
case 'F' :
|
||||
if (*format == 'F') {
|
||||
if (*format_tmp == 'F') {
|
||||
flags |= FLAGS_UPPERCASE;
|
||||
}
|
||||
idx = _ftoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
||||
format++;
|
||||
idx = _ftoa(out_tmp, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
||||
format_tmp++;
|
||||
break;
|
||||
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
if ((*format == 'g')||(*format == 'G')) {
|
||||
if ((*format_tmp == 'g')||(*format_tmp == 'G')) {
|
||||
flags |= FLAGS_ADAPT_EXP;
|
||||
}
|
||||
if ((*format == 'E')||(*format == 'G')) {
|
||||
if ((*format_tmp == 'E')||(*format_tmp == 'G')) {
|
||||
flags |= FLAGS_UPPERCASE;
|
||||
}
|
||||
idx = _etoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
||||
format++;
|
||||
idx = _etoa(out_tmp, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
||||
format_tmp++;
|
||||
break;
|
||||
#endif // PRINTF_SUPPORT_EXPONENTIAL
|
||||
#endif // PRINTF_SUPPORT_FLOAT
|
||||
@@ -1312,18 +1326,18 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||
// pre padding
|
||||
if (!(flags & FLAGS_LEFT)) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
out_tmp(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
// char output
|
||||
out((char)va_arg(va, int), buffer, idx++, maxlen);
|
||||
out_tmp((char)va_arg(va, int), buffer, idx++, maxlen);
|
||||
// post padding
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
out_tmp(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
format_tmp++;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1336,20 +1350,20 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||
}
|
||||
if (!(flags & FLAGS_LEFT)) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
out_tmp(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
// string output
|
||||
while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) {
|
||||
out(*(p++), buffer, idx++, maxlen);
|
||||
out_tmp(*(p++), buffer, idx++, maxlen);
|
||||
}
|
||||
// post padding
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
out_tmp(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
format_tmp++;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1362,16 +1376,16 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||
is_ll = true;
|
||||
}
|
||||
if (is_ll) {
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*),
|
||||
idx = _ntoa_long_long(out_tmp, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*),
|
||||
false, 16U, precision, width, flags);
|
||||
} else {
|
||||
#endif
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void*)),
|
||||
idx = _ntoa_long(out_tmp, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void*)),
|
||||
false, 16U, precision, width, flags);
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
}
|
||||
#endif
|
||||
format++;
|
||||
format_tmp++;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1386,20 +1400,20 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||
}
|
||||
if (!(flags & FLAGS_LEFT)) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
out_tmp(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
// string output
|
||||
while ((*pstr != 0) && (!(flags & FLAGS_PRECISION) || precision--)) {
|
||||
out(*(pstr++), buffer, idx++, maxlen);
|
||||
out_tmp(*(pstr++), buffer, idx++, maxlen);
|
||||
}
|
||||
// post padding
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
out_tmp(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
format_tmp++;
|
||||
break;
|
||||
}
|
||||
case 'v' : {
|
||||
@@ -1413,20 +1427,20 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||
}
|
||||
if (!(flags & FLAGS_LEFT)) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
out_tmp(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
// string output
|
||||
while ((*pstr != 0) && (!(flags & FLAGS_PRECISION) || precision--)) {
|
||||
out(*(pstr++), buffer, idx++, maxlen);
|
||||
out_tmp(*(pstr++), buffer, idx++, maxlen);
|
||||
}
|
||||
// post padding
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
out_tmp(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
format_tmp++;
|
||||
break;
|
||||
}
|
||||
case 'V' : {
|
||||
@@ -1440,37 +1454,37 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||
}
|
||||
if (!(flags & FLAGS_LEFT)) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
out_tmp(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
// string output
|
||||
while ((*pstr != 0) && (!(flags & FLAGS_PRECISION) || precision--)) {
|
||||
out(*(pstr++), buffer, idx++, maxlen);
|
||||
out_tmp(*(pstr++), buffer, idx++, maxlen);
|
||||
}
|
||||
// post padding
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
out_tmp(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
format_tmp++;
|
||||
break;
|
||||
}
|
||||
|
||||
case '%' :
|
||||
out('%', buffer, idx++, maxlen);
|
||||
format++;
|
||||
out_tmp('%', buffer, idx++, maxlen);
|
||||
format_tmp++;
|
||||
break;
|
||||
|
||||
default :
|
||||
out(*format, buffer, idx++, maxlen);
|
||||
format++;
|
||||
out_tmp(*format_tmp, buffer, idx++, maxlen);
|
||||
format_tmp++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// termination
|
||||
out((char)0, buffer, idx < maxlen ? idx : maxlen - 1U, maxlen);
|
||||
out_tmp((char)0, buffer, idx < maxlen ? idx : maxlen - 1U, maxlen);
|
||||
|
||||
// return written chars without terminating \0
|
||||
return (int)idx;
|
||||
|
||||
@@ -296,13 +296,14 @@ int strtohex(u32 *hex, char *str)
|
||||
int n;
|
||||
int i;
|
||||
u32 dd;
|
||||
char *str_tmp = str;
|
||||
|
||||
n = -1;
|
||||
i = 0;
|
||||
dd = 0;
|
||||
|
||||
while (*str) {
|
||||
n = atohex(*str++);
|
||||
while (*str_tmp) {
|
||||
n = atohex(*str_tmp++);
|
||||
if (n < 0) {return -1;}
|
||||
dd = (dd<<4) + n;
|
||||
if (++i > 8) {return -1;}
|
||||
@@ -318,15 +319,16 @@ int strtohexarray(u8 array[], int cnt, char *str)
|
||||
u8 tmp;
|
||||
u8 *des;
|
||||
int cnt_tmp = cnt;
|
||||
char *str_tmp = str;
|
||||
des = array;
|
||||
|
||||
while (cnt_tmp-- > 0) {
|
||||
int hex = atohex(*str++);
|
||||
int hex = atohex(*str_tmp++);
|
||||
if (hex < 0) {
|
||||
return -1;
|
||||
} else {tmp = (hex << 4) & 0xf0;}
|
||||
|
||||
hex = atohex(*str++);
|
||||
hex = atohex(*str_tmp++);
|
||||
if (hex < 0) {
|
||||
return -1;
|
||||
} else {
|
||||
@@ -336,7 +338,7 @@ int strtohexarray(u8 array[], int cnt, char *str)
|
||||
*des++ = (u8) tmp;
|
||||
}
|
||||
|
||||
return ((*str==0) ? 0 : -1);
|
||||
return ((*str_tmp==0) ? 0 : -1);
|
||||
}
|
||||
|
||||
int strtoip(u32 *ipadr, char * str)
|
||||
@@ -542,9 +544,11 @@ void dumpUint32(char *name, uint32_t* buffer, int len)
|
||||
|
||||
int strcasecmp(const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1 && *s2) {
|
||||
char a = *s1++;
|
||||
char b = *s2++;
|
||||
const char *s1_tmp = s1;
|
||||
const char *s2_tmp = s2;
|
||||
while (*s1_tmp && *s2_tmp) {
|
||||
char a = *s1_tmp++;
|
||||
char b = *s2_tmp++;
|
||||
|
||||
if (a == b) {
|
||||
continue;
|
||||
|
||||
@@ -348,13 +348,14 @@ static inline void net_buf_simple_restore(struct os_mbuf *buf,
|
||||
static inline void sys_memcpy_swap(void *dst, const void *src, size_t length)
|
||||
{
|
||||
size_t Length = length;
|
||||
const void *src_tmp = src;
|
||||
__ASSERT(((src < dst && (src + Length) <= dst) ||
|
||||
(src > dst && (dst + Length) <= src)),
|
||||
"Source and destination buffers must not overlap");
|
||||
src += Length - 1;
|
||||
src_tmp += Length - 1;
|
||||
|
||||
for (; Length > 0; Length--) {
|
||||
*((u8_t *)dst++) = *((u8_t *)src--);
|
||||
*((u8_t *)dst++) = *((u8_t *)src_tmp--);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,13 +31,14 @@ int bt_mesh_aes_cmac(const u8_t key[16], struct bt_mesh_sg *sg,
|
||||
struct tc_aes_
|
||||
key_sched_struct sched;
|
||||
struct tc_cmac_struct state;
|
||||
struct bt_mesh_sg *sg_tmp = sg;
|
||||
|
||||
if (tc_cmac_setup(&state, key, &sched) == TC_CRYPTO_FAIL) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
for (; sg_len_tmp; sg_len_tmp--, sg++) {
|
||||
if (tc_cmac_update(&state, sg->data, sg->len) == TC_CRYPTO_FAIL) {
|
||||
for (; sg_len_tmp; sg_len_tmp--, sg_tmp++) {
|
||||
if (tc_cmac_update(&state, sg_tmp->data, sg_tmp->len) == TC_CRYPTO_FAIL) {
|
||||
return -EIO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -972,22 +972,22 @@ static int proxy_segment_and_send(uint16_t conn_handle, u8_t type,
|
||||
/* ATT_MTU - OpCode (1 byte) - Handle (2 bytes) */
|
||||
mtu = ble_att_mtu(conn_handle) - 3; // 3:byte alignment
|
||||
if (mtu > msg->om_len) {
|
||||
net_buf_simple_push_u8(msg, PDU_HDR(SAR_COMPLETE, type));
|
||||
net_buf_simple_push_u8(msg, PDU_HDR((SAR_COMPLETE), (type)));
|
||||
return proxy_send(conn_handle, msg->om_data, msg->om_len);
|
||||
}
|
||||
|
||||
net_buf_simple_push_u8(msg, PDU_HDR(SAR_FIRST, type));
|
||||
net_buf_simple_push_u8(msg, PDU_HDR((SAR_FIRST), (type)));
|
||||
proxy_send(conn_handle, msg->om_data, mtu);
|
||||
net_buf_simple_pull(msg, mtu);
|
||||
|
||||
while (msg->om_len) {
|
||||
if (msg->om_len + 1 < mtu) {
|
||||
net_buf_simple_push_u8(msg, PDU_HDR(SAR_LAST, type));
|
||||
net_buf_simple_push_u8(msg, PDU_HDR((SAR_LAST), (type)));
|
||||
proxy_send(conn_handle, msg->om_data, msg->om_len);
|
||||
break;
|
||||
}
|
||||
|
||||
net_buf_simple_push_u8(msg, PDU_HDR(SAR_CONT, type));
|
||||
net_buf_simple_push_u8(msg, PDU_HDR((SAR_CONT), (type)));
|
||||
proxy_send(conn_handle, msg->om_data, mtu);
|
||||
net_buf_simple_pull(msg, mtu);
|
||||
}
|
||||
|
||||
@@ -1590,8 +1590,7 @@ static int cmd_mod_pub(int argc, char *argv[])
|
||||
}
|
||||
|
||||
struct shell_cmd_help cmd_mod_pub_help = {
|
||||
NULL, "<addr> <mod id> [cid] [<PubAddr> " \
|
||||
"<AppKeyIndex> <cred> <ttl> <period> <count> <interval>]", NULL
|
||||
NULL, "<addr> <mod id> [cid] [<PubAddr> <AppKeyIndex> <cred> <ttl> <period> <count> <interval>]", NULL
|
||||
};
|
||||
|
||||
static void hb_sub_print(struct bt_mesh_cfg_hb_sub *sub)
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "mesh/testing.h"
|
||||
#include "mesh/slist.h"
|
||||
#include "mesh/glue.h"
|
||||
#include "mesh/access.h"
|
||||
#include "mesh/testing.h"
|
||||
|
||||
#include "net.h"
|
||||
#include "access.h"
|
||||
|
||||
@@ -334,7 +334,7 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct os_mbuf *sdu,
|
||||
tx->dst = net_tx->ctx->addr;
|
||||
tx->seg_n = (sdu->om_len - 1) / 12; // 12:byte alignment
|
||||
tx->nack_count = tx->seg_n + 1;
|
||||
tx->seq_auth = SEQ_AUTH(BT_MESH_NET_IVI_TX, bt_mesh.seq);
|
||||
tx->seq_auth = (SEQ_AUTH(BT_MESH_NET_IVI_TX, bt_mesh.seq));
|
||||
tx->sub = net_tx->sub;
|
||||
tx->new_key = net_tx->sub->kr_flag;
|
||||
tx->cb = cb;
|
||||
@@ -736,19 +736,19 @@ static int trans_ack(struct bt_mesh_net_rx *rx, u8_t hdr,
|
||||
u16_t seq_zero;
|
||||
u8_t obo;
|
||||
|
||||
if (buf->om_len < 6) {
|
||||
if (buf->om_len < 6) { // 6:Analyzing conditions
|
||||
BT_ERR("Too short ack message");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
seq_zero = net_buf_simple_pull_be16(buf);
|
||||
obo = seq_zero >> 15;
|
||||
seq_zero = (seq_zero >> 2) & TRANS_SEQ_ZERO_MASK;
|
||||
obo = seq_zero >> 15; // 15:byte alignment
|
||||
seq_zero = (seq_zero >> 2) & TRANS_SEQ_ZERO_MASK; // 2:byte alignment
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && rx->friend_match) {
|
||||
BT_DBG("Ack for LPN 0x%04x of this Friend", rx->ctx.recv_dst);
|
||||
/* Best effort - we don't have enough info for true SeqAuth */
|
||||
*seq_auth = SEQ_AUTH(BT_MESH_NET_IVI_RX(rx), seq_zero);
|
||||
*seq_auth = (SEQ_AUTH(BT_MESH_NET_IVI_RX(rx), seq_zero));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -939,9 +939,9 @@ static inline s32_t ack_timeout(struct seg_rx *rx)
|
||||
/* The acknowledgment timer shall be set to a minimum of
|
||||
* 150 + 50 * TTL milliseconds.
|
||||
*/
|
||||
to = K_MSEC(150 + (50 * ttl));
|
||||
to = K_MSEC(150 + (50 * ttl)); // 150:byte, 50:byte alignment
|
||||
/* 100 ms for every not yet received segment */
|
||||
to += K_MSEC(((rx->seg_n + 1) - popcount(rx->block)) * 100);
|
||||
to += K_MSEC(((rx->seg_n + 1) - popcount(rx->block)) * 100); // 100:100ms
|
||||
/* Make sure we don't send more frequently than the duration for
|
||||
* each packet (default is 300ms).
|
||||
*/
|
||||
@@ -1179,7 +1179,7 @@ static int trans_seg(struct os_mbuf *buf, struct bt_mesh_net_rx *net_rx,
|
||||
u8_t seg_o;
|
||||
int err;
|
||||
|
||||
if (buf->om_len < 5) {
|
||||
if (buf->om_len < 5) { // 5:loop condition
|
||||
BT_ERR("Too short segmented message (len %u)", buf->om_len);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -1193,10 +1193,10 @@ static int trans_seg(struct os_mbuf *buf, struct bt_mesh_net_rx *net_rx,
|
||||
BT_DBG("ASZMIC %u AKF %u AID 0x%02x", ASZMIC(hdr), AKF(hdr), AID(hdr));
|
||||
net_buf_simple_pull(buf, 1);
|
||||
seq_zero = net_buf_simple_pull_be16(buf);
|
||||
seg_o = (seq_zero & 0x03) << 3;
|
||||
seq_zero = (seq_zero >> 2) & TRANS_SEQ_ZERO_MASK;
|
||||
seg_o = (seq_zero & 0x03) << 3; // 3:byte alignment
|
||||
seq_zero = (seq_zero >> 2) & TRANS_SEQ_ZERO_MASK; // 2:byte alignment
|
||||
seg_n = net_buf_simple_pull_u8(buf);
|
||||
seg_o |= seg_n >> 5;
|
||||
seg_o |= seg_n >> 5; // 5:byte alignment
|
||||
seg_n &= 0x1f;
|
||||
BT_DBG("SeqZero 0x%04x SegO %u SegN %u", seq_zero, seg_o, seg_n);
|
||||
|
||||
@@ -1218,10 +1218,10 @@ static int trans_seg(struct os_mbuf *buf, struct bt_mesh_net_rx *net_rx,
|
||||
* Mentioned delta shall be >= 0, if it is not then seq_auth will
|
||||
* be broken and it will be verified by the code below.
|
||||
*/
|
||||
*seq_auth = SEQ_AUTH(BT_MESH_NET_IVI_RX(net_rx),
|
||||
*seq_auth = (SEQ_AUTH(BT_MESH_NET_IVI_RX(net_rx),
|
||||
(net_rx->seq -
|
||||
((((net_rx->seq & BIT_MASK(14)) - seq_zero)) &
|
||||
BIT_MASK(13))));
|
||||
BIT_MASK(13)))));
|
||||
*seg_count = seg_n + 1;
|
||||
/* Look for old RX sessions */
|
||||
rx = seg_rx_find(net_rx, seq_auth);
|
||||
|
||||
@@ -567,6 +567,7 @@ static int ble_att_svr_tx_rsp(uint16_t conn_handle, int hs_status, struct os_mbu
|
||||
struct ble_l2cap_chan *chan;
|
||||
struct ble_hs_conn *conn;
|
||||
int do_tx;
|
||||
struct os_mbuf *om_tmp = om;
|
||||
|
||||
int hs_status_tmp = hs_status;
|
||||
if (hs_status_tmp != 0 && err_status == 0) {
|
||||
@@ -584,11 +585,11 @@ static int ble_att_svr_tx_rsp(uint16_t conn_handle, int hs_status, struct os_mbu
|
||||
hs_status_tmp = rc;
|
||||
} else {
|
||||
if (hs_status_tmp == 0) {
|
||||
BLE_HS_DBG_ASSERT(om != NULL);
|
||||
ble_att_inc_tx_stat(om->om_data[0]);
|
||||
ble_att_truncate_to_mtu(chan, om);
|
||||
hs_status_tmp = ble_l2cap_tx(conn, chan, om);
|
||||
om = NULL;
|
||||
BLE_HS_DBG_ASSERT(om_tmp != NULL);
|
||||
ble_att_inc_tx_stat(om_tmp->om_data[0]);
|
||||
ble_att_truncate_to_mtu(chan, om_tmp);
|
||||
hs_status_tmp = ble_l2cap_tx(conn, chan, om_tmp);
|
||||
om_tmp = NULL;
|
||||
|
||||
if (hs_status_tmp != 0) {
|
||||
err_status = BLE_ATT_ERR_UNLIKELY;
|
||||
@@ -602,22 +603,22 @@ static int ble_att_svr_tx_rsp(uint16_t conn_handle, int hs_status, struct os_mbu
|
||||
STATS_INC(ble_att_stats, error_rsp_tx);
|
||||
|
||||
/* Reuse om for error response. */
|
||||
if (om == NULL) {
|
||||
om = ble_hs_mbuf_l2cap_pkt();
|
||||
if (om_tmp == NULL) {
|
||||
om_tmp = ble_hs_mbuf_l2cap_pkt();
|
||||
} else {
|
||||
os_mbuf_adj(om, OS_MBUF_PKTLEN(om));
|
||||
os_mbuf_adj(om_tmp, OS_MBUF_PKTLEN(om_tmp));
|
||||
}
|
||||
|
||||
if (om != NULL) {
|
||||
ble_att_svr_tx_error_rsp(conn_handle, om, att_op,
|
||||
if (om_tmp != NULL) {
|
||||
ble_att_svr_tx_error_rsp(conn_handle, om_tmp, att_op,
|
||||
err_handle, err_status);
|
||||
om = NULL;
|
||||
om_tmp = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Free mbuf if it was not consumed (i.e., if the send failed). */
|
||||
os_mbuf_free_chain(om);
|
||||
os_mbuf_free_chain(om_tmp);
|
||||
return hs_status_tmp;
|
||||
}
|
||||
|
||||
@@ -2146,7 +2147,6 @@ int ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
|
||||
* 5. Invalid handle.
|
||||
* 6. Write not permitted.
|
||||
*/
|
||||
|
||||
/* <5> */
|
||||
if (attr_entry == NULL) {
|
||||
rc = BLE_HS_ENOENT;
|
||||
|
||||
Reference in New Issue
Block a user