fpc_hcp.c File Reference

Host Communication Protocol implementation. More...

`#include <stdlib.h>`
`#include <string.h>`
`#include "fpc_hcp.h"`
Include dependency graph for fpc_hcp.c:

Go to the source code of this file.

## Macros

HCP Packet Member Sizes
Macros for packet member sizes.
#define | PACKET_ID_SIZE sizeof(((fpc_hcp_packet_t*)0)->id)
#define | PACKET_NUM_ARGS_SIZE sizeof(((fpc_hcp_packet_t*)0)->num_args)
#define | PACKET_HEADER_SIZE (PACKET_ID_SIZE + PACKET_NUM_ARGS_SIZE)
HCP Argument Member Sizes
Macros for argument member sizes.
#define | ARGUMENT_ARG_SIZE sizeof(((fpc_hcp_arg_data_t*)0)->arg)
#define | ARGUMENT_SIZE_SIZE sizeof(((fpc_hcp_arg_data_t*)0)->size)
#define | ARGUMENT_HEADER_SIZE (ARGUMENT_ARG_SIZE + ARGUMENT_SIZE_SIZE)

## Functions

static fpc_com_result_t | recieve_chunks (fpc_com_chain_t *chain)
| Handle receive chunks. More...
static fpc_com_result_t | transmit_chunks (fpc_com_chain_t *chain)
| Handle transmit chunks. More...
uint16_t | fpc_hcp_get_size (fpc_hcp_packet_t *packet, uint16_t *num_args)
| Calculate serialized packet size. More...
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. More...
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. More...
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. More...
bool | fpc_hcp_arg_check (fpc_hcp_packet_t *packet, fpc_hcp_arg_t arg)
| Check if command contains selected argument key. More...
fpc_hcp_arg_data_t * | fpc_hcp_arg_get (fpc_hcp_packet_t *packet, fpc_hcp_arg_t arg)
| Get Argument with specified key. More...
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. More...
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. More...

## Detailed Description

Host Communication Protocol implementation.

Definition in file fpc_hcp.c.

## Macro Definition Documentation

#define ARGUMENT_ARG_SIZE sizeof(((fpc_hcp_arg_data_t*)0)->arg)

Definition at line 44 of file fpc_hcp.c.

#define ARGUMENT_HEADER_SIZE (ARGUMENT_ARG_SIZE + ARGUMENT_SIZE_SIZE)

Definition at line 46 of file fpc_hcp.c.

#define ARGUMENT_SIZE_SIZE sizeof(((fpc_hcp_arg_data_t*)0)->size)

Definition at line 45 of file fpc_hcp.c.

#define PACKET_HEADER_SIZE (PACKET_ID_SIZE + PACKET_NUM_ARGS_SIZE)

Definition at line 35 of file fpc_hcp.c.

#define PACKET_ID_SIZE sizeof(((fpc_hcp_packet_t*)0)->id)

Definition at line 33 of file fpc_hcp.c.

#define PACKET_NUM_ARGS_SIZE sizeof(((fpc_hcp_packet_t*)0)->num_args)

Definition at line 34 of file fpc_hcp.c.

## Function Documentation

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.

Note
  This function does not allocate any memory, it will only set the argument variables.

Parameters

  [in] | packet | Packet to add to.
  [in] | arg | Argument id.
  [in] | size | Size of argument data.
  [in] | free_data | Set to true if data should be owned by the argument, false if user still owns data.
  [in] | data | Pointer to argument data.

Returns
  true = success, false = failure.

Definition at line 145 of file fpc_hcp.c.

References fpc_hcp_arg_data::arg, ARG_NONE, fpc_hcp_packet::arguments, fpc_hcp_arg_data::data, fpc_hcp_arg_data::free_data, fpc_hcp_packet::num_args, and fpc_hcp_arg_data::size.

bool fpc_hcp_arg_check | ( | fpc_hcp_packet_t * | packet,
|  | fpc_hcp_arg_t | arg
| ) |  |

Check if command contains selected argument key.

Parameters

  [in] | packet | The packet to scan.
  [in] | arg | Argument to look for.

Returns
  true if found, false if not found.

Definition at line 169 of file fpc_hcp.c.

References fpc_hcp_arg_get().

Here is the call graph for this function:

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.

Argument data will be copied to specified data buffer. Remaining bytes in data will be cleared if the argument data size is less than data size when the argument contains data.

Parameters

  [in] | packet | The packet to operate on.
  [in] | arg | The arg to retrieve data from.
  [in] | data_size | Number of bytes to copy.
  [in,out] | data | Pointer to data buffer.

Returns
  True if argument found, false if not found.

Definition at line 183 of file fpc_hcp.c.

References fpc_hcp_arg_data::data, fpc_hcp_arg_get(), and fpc_hcp_arg_data::size.

Here is the call graph for this function:

fpc_hcp_arg_data_t* fpc_hcp_arg_get | ( | fpc_hcp_packet_t * | packet,
|  | fpc_hcp_arg_t | arg
| ) |  |

Get Argument with specified key.

Parameters

  [in] | packet | The packet to operate on.
  [in] | arg | The arg to retrieve.

Returns
  Pointer to fpc_hcp_arg_data_t is successful, otherwise NULL.

Definition at line 173 of file fpc_hcp.c.

References fpc_hcp_arg_data::arg, fpc_hcp_packet::arguments, and fpc_hcp_packet::num_args.

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.

Parameters

  [in] | chain | Pointer to the communication chain used to retrieve the packet.
  [in] | packet | Pointer to packet.

Definition at line 198 of file fpc_hcp.c.

References fpc_hcp_arg_data::arg, ARG_NONE, fpc_com_chain::argument_free, fpc_hcp_packet::arguments, CMD_NONE, fpc_com_chain::context, fpc_hcp_packet::id, and fpc_hcp_packet::num_args.

uint16_t fpc_hcp_get_size | ( | fpc_hcp_packet_t * | packet,
|  | uint16_t * | num_args
| ) |  |

Calculate serialized packet size.

Parameters

  [in] | packet | Packet to calculate.
  [in,out] | num_args | Will return number of arguments held by the command can be set to NULL.

Returns
  Serialized size.

Definition at line 64 of file fpc_hcp.c.

References fpc_hcp_arg_data::arg, ARG_NONE, ARGUMENT_HEADER_SIZE, fpc_hcp_packet::arguments, fpc_hcp_packet::num_args, PACKET_HEADER_SIZE, and fpc_hcp_arg_data::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.

Parameters

  [in,out] | packet | Pointer to pre-allocated packet struct.
  [in] | chain | The chain to use.

Returns
  fpc_com_result_t

Definition at line 117 of file fpc_hcp.c.

References fpc_com_chain::app_mtu_buffer, fpc_com_chain::app_mtu_size, FPC_COM_CHAIN_RX, FPC_COM_RESULT_INVALID_ARGUMENT, fpc_com_chain_private::hcp_packet, fpc_com_chain::initialized, fpc_com_chain::link_overhead_get, fpc_com_chain::phy_mtu_buffer, fpc_com_chain::phy_mtu_size, fpc_com_chain::private_vars, recieve_chunks(), and fpc_com_chain::tsp_overhead_get.

Here is the call graph for this function:

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.

Parameters

  [in] | packet | Application packet to send.
  [in] | chain | The chain to use.

Returns
  fpc_com_result_t

Definition at line 89 of file fpc_hcp.c.

References fpc_com_chain::app_mtu_buffer, fpc_com_chain::app_mtu_size, FPC_COM_CHAIN_TX, FPC_COM_RESULT_INVALID_ARGUMENT, fpc_com_chain_private::hcp_packet, fpc_com_chain::initialized, fpc_com_chain::link_overhead_get, fpc_com_chain::phy_mtu_buffer, fpc_com_chain::phy_mtu_size, fpc_com_chain::private_vars, transmit_chunks(), and fpc_com_chain::tsp_overhead_get.

Here is the call graph for this function:

static fpc_com_result_t recieve_chunks | ( | fpc_com_chain_t * | chain | ) |

static

Handle receive chunks.

Parameters

  chain | Comminucation chain. return fpc_com_result_t

Definition at line 211 of file fpc_hcp.c.

References fpc_com_chain::app_mtu_buffer, fpc_com_chain::app_mtu_size, fpc_com_chain::app_overhead_get, fpc_com_chain::app_packet_size, fpc_com_chain::app_rx, fpc_hcp_arg_data::arg, fpc_com_chain::argument_allocator, ARGUMENT_ARG_SIZE, fpc_com_chain::argument_free, ARGUMENT_SIZE_SIZE, fpc_com_chain::context, fpc_hcp_arg_data::data, FPC_COM_CHAIN_RX, FPC_COM_RESULT_INVALID_ARGUMENT, FPC_COM_RESULT_NO_MEMORY, FPC_COM_RESULT_OK, fpc_hcp_arg_add(), fpc_hcp_arg_data::free_data, HCP_MIN, fpc_com_chain_private::hcp_packet, fpc_hcp_packet::id, PACKET_HEADER_SIZE, PACKET_ID_SIZE, PACKET_NUM_ARGS_SIZE, fpc_com_chain::private_vars, and fpc_hcp_arg_data::size.

Here is the call graph for this function:

static fpc_com_result_t transmit_chunks | ( | fpc_com_chain_t * | chain | ) |

static

Handle transmit chunks.

Parameters

  chain | Comminucation chain. return fpc_com_result_t

Definition at line 355 of file fpc_hcp.c.

References fpc_com_chain::app_mtu_buffer, fpc_com_chain::app_mtu_size, fpc_com_chain::app_overhead_get, fpc_com_chain::app_packet_size, fpc_com_chain::app_tx, fpc_hcp_arg_data::arg, ARGUMENT_ARG_SIZE, ARGUMENT_HEADER_SIZE, ARGUMENT_SIZE_SIZE, fpc_hcp_packet::arguments, fpc_hcp_arg_data::data, FPC_COM_CHAIN_TX, FPC_COM_RESULT_INVALID_ARGUMENT, FPC_COM_RESULT_OK, fpc_hcp_get_size(), HCP_MIN, fpc_com_chain_private::hcp_packet, fpc_com_chain_private::hcp_seq_len, fpc_com_chain_private::hcp_seq_nr, fpc_hcp_packet::id, PACKET_HEADER_SIZE, PACKET_ID_SIZE, PACKET_NUM_ARGS_SIZE, fpc_com_chain::phy_mtu_size, fpc_com_chain::private_vars, and fpc_hcp_arg_data::size.

Here is the call graph for this function: