uint32_t nrf_ecb_hal_data_t_in_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, void * const p_data) { nrf_ecb_hal_data_t * p_ecb_data = (nrf_ecb_hal_data_t *)p_data; uint32_t err_code; uint8_t * p_tmp = p_ecb_data->key; err_code = buf_dec(p_buf, buf_len, p_index, &p_tmp,SOC_ECB_KEY_LENGTH,SOC_ECB_KEY_LENGTH); SER_ASSERT(err_code == NRF_SUCCESS, err_code); p_tmp = p_ecb_data->cleartext; err_code = buf_dec(p_buf, buf_len, p_index, &p_tmp,SOC_ECB_CLEARTEXT_LENGTH, SOC_ECB_CLEARTEXT_LENGTH); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return NRF_SUCCESS; }
uint32_t len16data_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, uint8_t * * const pp_data, uint16_t * const p_dlen) { uint32_t err_code = NRF_SUCCESS; uint16_t out_buf_len = *p_dlen; err_code = uint16_t_dec(p_buf, buf_len, p_index, p_dlen); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = buf_dec(p_buf, buf_len, p_index, pp_data, out_buf_len, *p_dlen); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_code; }
uint32_t ble_gatts_value_t_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, void * const p_void_struct) { ble_gatts_value_t * p_value = (ble_gatts_value_t *)p_void_struct; uint32_t err_code = NRF_SUCCESS; uint16_t total_len = p_value->len; err_code = uint16_t_dec(p_buf, buf_len, p_index, (void *) &(p_value->len)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_dec(p_buf, buf_len, p_index, (void *) &(p_value->offset)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = buf_dec(p_buf, buf_len, p_index, &(p_value->p_value), total_len, p_value->len); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_code; }
uint32_t ble_gatts_value_get_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, uint8_t * * const pp_value, uint16_t * * const pp_value_len, uint32_t * const p_result_code) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_result_code); SER_ASSERT_NOT_NULL(pp_value); SER_ASSERT_NOT_NULL(pp_value_len); uint32_t err_code; uint32_t index = 0; uint32_t decode_result = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, SD_BLE_GATTS_VALUE_GET, p_result_code); if (decode_result != NRF_SUCCESS) { return decode_result; } if (*p_result_code != NRF_SUCCESS) { SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; } uint16_t value_buffer_size = *(*pp_value_len); err_code = cond_field_dec(p_buf, packet_len, &index, (void * *)pp_value_len, uint16_t_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); uint16_t value_len = (*pp_value_len) ? *(*pp_value_len) : 0; err_code = buf_dec(p_buf, packet_len, &index, pp_value, value_buffer_size, value_len); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; }
/* Puts the given char into the given terminal's buffer, moving the * cursor accordingly for control chars Returns 1 if char can be * echoed (non-control char), 0 otherwise */ static int vt_handle_char(virtterm_t *vt, char c) { KASSERT(NULL != vt); /* Start where the cursor currently is located */ int new_cursor = vt->vt_cursor; int ret = 0; switch (c) { case '\b': /* Move cursor back one space */ /* the user can't backspace past the beginning */ if (new_cursor != vt->vt_head) buf_dec(new_cursor); break; case '\r': new_cursor = (new_cursor / DISPLAY_WIDTH) * DISPLAY_WIDTH; break; /* In the next two cases, the cursor advances, and we * need to compare it with the end of the buffer to * determine whether or not to advance the buffer * tail */ case '\n': /* To beginning of next line */ new_cursor = next_row(new_cursor); goto handle_tail; default: /* Actually put a char into the buffer */ vt->vt_buf[new_cursor] = c; /* And increment */ buf_inc(new_cursor); ret = 1; handle_tail: /* Yuck */ if (circ_dist(new_cursor, vt->vt_cursor) >= circ_dist(vt->vt_tail, vt->vt_cursor)) { /* Current cursor pos past tail of the current * buffer, so advance tail */ int new_tail = next_row(new_cursor); /* Check for head adjusting (if we write * enough that the scroll buffer fills up, we * sacrifice chars near the head) */ if (circ_dist(vt->vt_tail, vt->vt_head) >= circ_dist(vt->vt_tail, new_tail)) { vt->vt_head = next_row(new_tail); } /* Remember to clear space we may have acquired */ if (vt->vt_tail <= new_tail) { memset(vt->vt_buf + vt->vt_tail, 0, new_tail - vt->vt_tail); } else { memset(vt->vt_buf + vt->vt_tail, 0, SCROLL_BUFSIZE - vt->vt_tail); memset(vt->vt_buf, 0, new_tail); } /* Finally, set the new tail */ vt->vt_tail = new_tail; } break; } vt->vt_cursor = new_cursor; return ret; }