33 #define PACKET_ID_SIZE sizeof(((fpc_hcp_packet_t*)0)->id) 34 #define PACKET_NUM_ARGS_SIZE sizeof(((fpc_hcp_packet_t*)0)->num_args) 35 #define PACKET_HEADER_SIZE (PACKET_ID_SIZE + PACKET_NUM_ARGS_SIZE) 44 #define ARGUMENT_ARG_SIZE sizeof(((fpc_hcp_arg_data_t*)0)->arg) 45 #define ARGUMENT_SIZE_SIZE sizeof(((fpc_hcp_arg_data_t*)0)->size) 46 #define ARGUMENT_HEADER_SIZE (ARGUMENT_ARG_SIZE + ARGUMENT_SIZE_SIZE) 74 for (uint8_t i = 0; i < packet->
num_args; i++) {
93 if (chain == NULL || packet == NULL || chain->
initialized ==
false ||
103 uint16_t link_offset;
108 + tsp_offset + link_offset;
121 if (chain == NULL || packet == NULL || chain->
initialized ==
false ||
131 uint16_t link_offset;
136 + tsp_offset + link_offset;
150 if (packet == NULL || (size > 0 && data == NULL)) {
154 for (uint8_t i = 0; i < packet->
num_args; i++) {
175 for (uint8_t i = 0; i < packet->
num_args; i++) {
188 if (arg_data == NULL || data == NULL || data_size == 0 || arg_data->
size == 0
189 || data_size > arg_data->
size) {
193 memcpy(data, arg_data->
data, data_size);
200 if (chain && packet) {
201 for (uint8_t i = 0; i < packet->
num_args; i++) {
215 uint16_t id_rem_size;
216 uint16_t size_rem_size;
217 uint16_t arg_rem_size = 0;
219 uint8_t *arg_data = NULL;
222 uint16_t num_args = 0;
224 bool first_packet =
true;
238 result = chain->
app_rx(chain);
253 num_args = *((uint16_t *) data);
256 first_packet =
false;
262 while (rem_size && (arg_nr < num_args)) {
265 if (rem_size && id_rem_size) {
267 copy_size =
HCP_MIN(id_rem_size, rem_size);
274 id_rem_size -= copy_size;
275 rem_size -= copy_size;
278 if (rem_size && size_rem_size) {
282 copy_size =
HCP_MIN(size_rem_size, rem_size);
290 size_rem_size -= copy_size;
291 rem_size -= copy_size;
293 if (size_rem_size == 0) {
294 bool free_data =
true;
298 arg, arg_size, &free_data, chain->
context);
299 if (arg_data == NULL) {
306 free_data, arg_data);
307 if (status ==
false) {
310 arg_struct.
arg = arg;
312 arg_struct.
size = arg_size;
313 arg_struct.
data = arg_data;
317 if (arg_nr < num_args) {
325 arg_rem_size = arg_size;
329 if (rem_size && arg_rem_size) {
331 copy_size =
HCP_MIN(arg_rem_size, rem_size);
334 memcpy(arg_data + (arg_size - arg_rem_size), data, copy_size);
338 rem_size -= copy_size;
339 arg_rem_size -= copy_size;
343 if (id_rem_size == 0 && size_rem_size == 0 && arg_rem_size == 0) {
357 uint16_t serialized_size;
358 uint16_t packet_data_left;
359 uint16_t data_rem_size = 0;
363 uint16_t num_args = 0;
398 *((uint16_t *) data) = num_args;
405 while (packet_data_left && arg_nr < num_args) {
421 data_rem_size = arg_data->
size;
433 if (packet_data_left && data_rem_size) {
437 copy_size =
HCP_MIN(data_rem_size, packet_data_left);
440 memcpy(data, arg_data->
data + (arg_data->
size - data_rem_size), copy_size);
444 data_rem_size -= copy_size;
445 packet_data_left -= copy_size;
447 if (!data_rem_size) {
453 result = chain->
app_tx(chain);
461 packet_data_left =
HCP_MIN(serialized_size, app_mtu);
uint16_t(* tsp_overhead_get)(uint16_t *offset)
fpc_com_result_t(* app_tx)(fpc_com_chain_t *chain)
uint8_t * phy_mtu_buffer[2]
static fpc_com_result_t recieve_chunks(fpc_com_chain_t *chain)
Handle receive chunks.
uint16_t(* app_overhead_get)(uint16_t *offset)
#define ARGUMENT_HEADER_SIZE
bool fpc_hcp_arg_check(fpc_hcp_packet_t *packet, fpc_hcp_arg_t arg)
Check if command contains selected argument key.
Application Command Packet.
bool fpc_hcp_arg_copy_data(fpc_hcp_packet_t *packet, fpc_hcp_arg_t arg, uint16_t data_size, uint8_t *data)
Copy data from an argument with specified key.
void *(* argument_allocator)(fpc_hcp_cmd_t cmd, fpc_hcp_arg_t arg, uint16_t size, bool *free_data, void *context)
static fpc_com_result_t transmit_chunks(fpc_com_chain_t *chain)
Handle transmit chunks.
#define PACKET_HEADER_SIZE
fpc_hcp_arg_data_t * fpc_hcp_arg_get(fpc_hcp_packet_t *packet, fpc_hcp_arg_t arg)
Get Argument with specified key.
void * context
User context pointer. User private stuff, to be able to pass nessecary context to argument_allocator ...
void(* argument_free)(fpc_hcp_cmd_t cmd, fpc_hcp_arg_data_t *arg_data, void *context)
#define PACKET_NUM_ARGS_SIZE
#define ARGUMENT_ARG_SIZE
bool fpc_hcp_arg_add(fpc_hcp_packet_t *packet, fpc_hcp_arg_t arg, uint16_t size, bool free_data, void *data)
Add argument to packet.
fpc_com_result_t fpc_hcp_transmit(fpc_hcp_packet_t *packet, fpc_com_chain_t *chain)
Transmits an application packet through the supplied transmit chain.
uint16_t app_packet_size[2]
uint8_t * app_mtu_buffer[2]
uint16_t(* link_overhead_get)(uint16_t *offset)
fpc_hcp_arg_data_t * arguments
fpc_hcp_packet_t * hcp_packet
fpc_com_chain_private_t private_vars
uint16_t fpc_hcp_get_size(fpc_hcp_packet_t *packet, uint16_t *num_args)
Calculate serialized packet size.
fpc_com_result_t fpc_hcp_receive(fpc_hcp_packet_t *packet, fpc_com_chain_t *chain)
Receives an application packet through the supplied transmit chain.
Host Communication Protocol interface.
#define ARGUMENT_SIZE_SIZE
void fpc_hcp_free(fpc_com_chain_t *chain, fpc_hcp_packet_t *packet)
Frees the resources held by the packet i.e. the dynamic data held in the arguments.
fpc_com_result_t(* app_rx)(fpc_com_chain_t *chain)