# CO_UTILS
[COMMON]

Common utilities. More...

Collaboration diagram for CO_UTILS:

## Defines
#define | CO_STAIDX_TO_AID(sta_idx) ((sta_idx) + 1)
| Converts a STA index in an Association Index.
#define | CO_GET_INDEX(__element_ptr, __array_ptr) ((__element_ptr) - (__array_ptr))
| Get the index of an element in an array.
#define | CO_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
| Get the number of element in an array.
#define | CHAR_LEN (CHAR_BIT/8)
| Length of a char in bytes.
#define | CPU2HW(ptr) (((uint32_t)(ptr)) * CHAR_LEN)
| Converts a CPU pointer into a HW address This macro is used to convert a SW pointer into the corresponding HW address.
#define | HW2CPU(ptr) ((void *)(((uint32_t)(ptr)) / CHAR_LEN))
| Converts a HW address into a CPU pointer This macro is doing the reverse operation as CPU2HW.
#define | sizeof_b(a) (sizeof(a) * CHAR_LEN)
| Return the size of a variable or type in bytes.
#define | offsetof_b(a, b) (offsetof(a, b) * CHAR_LEN)
| Return the offset (in bytes) of a structure element.
## Functions
__INLINE uint16_t | co_read16 (void const *ptr16)
| Read an aligned 16 bits word.
__INLINE void | co_write16 (void const *ptr16, uint32_t value)
| Write an aligned 16 bits word.
__INLINE uint32_t | co_read32 (void const *ptr32)
| Read an aligned 32 bit word.
__INLINE void | co_write32 (void const *ptr32, uint32_t value)
| Write an aligned 32 bits word.
__INLINE void | co_copy32 (uint32_t *dst, uint32_t *src, uint32_t len)
| Copy a 32-bit aligned buffer into another one The length in bytes is converted to the corresponding number of 32-bit words.
__INLINE uint8_t | co_read8p (uint32_t addr)
| Read a 8 bits word.
__INLINE void | co_write8p (uint32_t addr, uint8_t value)
| Write a 8 bits word.
__INLINE uint16_t | co_read16p (uint32_t addr)
| Read a packed 16 bits word.
__INLINE void | co_write16p (uint32_t addr, uint32_t value)
| Write a packed 16 bits word.
__INLINE uint32_t | co_read24p (uint32_t addr)
| Read a packed 24 bits word.
__INLINE void | co_write24p (uint32_t addr, uint32_t value)
| Write a packed 24 bits word.
__INLINE uint32_t | co_read32p (uint32_t addr)
| Read a packed 32 bits word.
__INLINE void | co_write32p (uint32_t addr, uint32_t value)
| Write a packed 32 bits word.
__INLINE uint64_t | co_read64p (uint32_t addr)
| Read a packed 64 bits word.
__INLINE bool | co_cmp8p (uint32_t pkd, uint8_t const *ptr, uint32_t len)
| Compare a packed byte buffer with a CPU byte array.
__INLINE void | co_pack8p (uint32_t dst, uint8_t const *src, uint32_t len)
| Copy and pack a byte array to another one.
__INLINE void | co_unpack8p (uint8_t *dst, uint32_t src, uint32_t len)
| Copy and unpack a byte array to another one.
__INLINE void | co_copy8p (uint32_t dst, uint32_t src, uint32_t len)
| Copy a packed byte array to another packed byte array.
__INLINE uint8_t | co_val_get (uint8_t const array[], int lsb, int width)
| This function returns the value of bit field inside an array of bits, represented as an array of bytes.
__INLINE void | co_val_set (uint8_t array[], int lsb, int width, uint8_t val)
| This function sets a value of a bit field inside an array of bits, represented as an array of bytes.
__INLINE bool | co_bit_is_set (uint8_t const array[], int pos)
| This function returns the status of a specific bit position inside an array of bits, represented as an array of bytes.
__INLINE void | co_bit_set (uint8_t array[], uint8_t pos)
| This function sets a specific bit position inside an array of bits, represented as an array of bytes.
__INLINE void | co_bit_clr (uint8_t array[], uint8_t pos)
| This function clears a specific bit position inside an array of bits, represented as an array of bytes.

## Detailed Description

Common utilities.

This module contains the common utilities functions and macros

## Define Documentation

#define CO_ARRAY_SIZE | ( | a |  | ) | (sizeof(a) / sizeof((a)[0]))

Get the number of element in an array.

Parameters:

  `[in]` | a | Pointer to the array

Returns:
  The number of the element

Definition at line 65 of file co_utils.h.

#define CO_GET_INDEX | ( | __element_ptr,
|  | __array_ptr |  | ) | ((__element_ptr) - (__array_ptr))

Get the index of an element in an array.

Parameters:

  `[in]` | __element_ptr | Pointer to the element
  `[in]` | __array_ptr | Pointer to the array

Returns:
  The index of the element

Definition at line 56 of file co_utils.h.

#define CO_STAIDX_TO_AID | ( | sta_idx |  | ) | ((sta_idx) + 1)

Converts a STA index in an Association Index.

Parameters:

  `[in]` | sta_idx | The station index.

Returns:
  The association index

Definition at line 46 of file co_utils.h.

#define CPU2HW | ( | ptr |  | ) | (((uint32_t)(ptr)) * CHAR_LEN)

Converts a CPU pointer into a HW address This macro is used to convert a SW pointer into the corresponding HW address.

With CPUs having native byte support, the value returned will be the same as the pointer passed. With TL4, the value returned is the pointer multiplied by 2.

Parameters:

  `[in]` | ptr | Pointer to be converted

Returns:
  The corresponding HW address

Definition at line 80 of file co_utils.h.

Referenced by aes_cmac(), bfr_is_vht_bfr(), bfr_prep_bfr_poll(), bfr_prep_ndpa(), bfr_upload_report(), dma_push(), hsu_hmac_sha_x(), hsu_sha_x(), macif_init(), macif_rx_desc_upload(), macif_tx_cfm_push(), me_build_associate_req(), me_build_authenticate(), mm_bcn_build(), mm_bcn_desc_prep(), mm_bcn_init_mesh_add_ies_desc(), mm_bcn_init_p2p_noa(), mm_bcn_init_tim(), mm_bcn_update(), mm_compute_beacon_crc(), mm_tim_update_proceed(), rxl_go_to_last_rbd(), rxl_hd_append(), rxl_mpdu_transfer(), rxl_payload_transfer(), rxl_pd_append(), rxl_rxcntrl_frame(), rxu_cntrl_desc_init(), rxu_cntrl_machdr_read(), rxu_cntrl_mic_check(), rxu_cntrl_protected_handle(), rxu_mgt_ind_handler(), rxu_mgt_route(), rxu_mgt_route_action(), scan_search_ds(), scanu_build_ie(), scanu_join_frame_handler(), scanu_scan_frame_handler(), sm_connect_req_handler(), tdls_check_frame_action(), tdls_check_tdls_channel_switch_request(), tdls_check_tdls_channel_switch_response(), tdls_check_tdls_peer_traffic_response(), txl_agg_hwdesc_init(), txl_buffer_bfr_dma_desc_conf(), txl_buffer_mic_compute(), txl_buffer_transfer(), txl_buffer_update_tbd(), txl_buffer_update_thd(), txl_cntrl_start_pm_mon(), txl_frame_init(), txl_frame_init_desc(), txl_frame_prepare(), txl_frame_send_tdls_channel_switch_req_frame(), txl_frame_send_tdls_channel_switch_rsp_frame(), txl_frame_send_tdls_peer_traffic_ind_frame(), txl_hwdesc_config_post(), txl_int_fake_transfer(), txl_mumimo_convert(), and txu_cntrl_mac_hdr_append().

#define HW2CPU | ( | ptr |  | ) | ((void *)(((uint32_t)(ptr)) / CHAR_LEN))

Converts a HW address into a CPU pointer This macro is doing the reverse operation as CPU2HW.

Parameters:

  `[in]` | ptr | Address to be converted

Returns:
  The corresponding CPU pointer

Definition at line 90 of file co_utils.h.

Referenced by bfr_init_index_table(), bfr_prep_bfr_poll(), bfr_prep_ndp(), bfr_prep_ndpa(), hsu_michael(), me_build_associate_req(), michael_calc(), mm_bcn_build(), rxl_current_desc_get(), rxl_frame_handle(), rxl_go_to_last_rbd(), rxl_hd_append(), rxl_immediate_frame_get(), rxl_mpdu_copy(), rxl_mpdu_free(), rxl_mpdu_partial_transfer(), rxl_mpdu_transfer(), rxl_payload_transfer(), rxl_pd_append(), rxl_rxcntrl_frame(), rxl_rxdesc_get(), rxu_cntrl_mac2eth_update(), rxu_cntrl_mic_check(), rxu_cntrl_protected_handle(), rxu_cntrl_remove_sec_hdr_mgmt_frame(), rxu_mgt_frame_check(), rxu_mgt_frame_ind(), tpc_update_frame_tx_power(), txl_buffer_machdr_get(), txl_decode_compressed_ba(), txl_frame_exchange_done(), txl_frame_exchange_manage(), txl_frame_push(), txl_hwdesc_config_post(), txl_is_ba_valid(), txl_payload_handle(), txu_cntrl_amsdu_hdr_append(), txu_cntrl_llc_hdr_append(), txu_cntrl_mac_hdr_append(), and txu_cntrl_sec_hdr_append().

#define offsetof_b | ( | a,
|  | b |  | ) | (offsetof(a, b) * CHAR_LEN)

Return the offset (in bytes) of a structure element.

Parameters:

  `[in]` | a | Structure type
  `[in]` | b | Field name

Returns:
  The of the field in bytes

Definition at line 109 of file co_utils.h.

Referenced by txl_buffer_transfer().

#define sizeof_b | ( | a |  | ) | (sizeof(a) * CHAR_LEN)

Return the size of a variable or type in bytes.

Parameters:

  `[in]` | a | Variable for which the size is computed

Returns:
  The size of the variable in bytes

Definition at line 99 of file co_utils.h.

Referenced by ipc_emb_txdesc_copy(), macif_init(), rxu_cntrl_mac2eth_update(), txl_buffer_control_copy(), txl_buffer_get_params(), txl_buffer_get_space(), txl_buffer_mic_compute(), txl_buffer_transfer(), txl_buffer_update_tbd(), txl_buffer_update_thd(), txl_int_fake_transfer(), txu_cntrl_amsdu_hdr_append(), txu_cntrl_llc_hdr_append(), and txu_cntrl_umacdesc_prep().

## Function Documentation

__INLINE void co_bit_clr | ( | uint8_t | array[],
|  | uint8_t | pos |
| ) |  |  |

This function clears a specific bit position inside an array of bits, represented as an array of bytes.

Parameters:

  `[in]` | array | Array of bits
  `[in]` | pos | Bit position to be cleared

Definition at line 527 of file co_utils.h.

References CO_BIT.

__INLINE bool co_bit_is_set | ( | uint8_t const | array[],
|  | int | pos |
| ) |  |  |

This function returns the status of a specific bit position inside an array of bits, represented as an array of bytes.

Parameters:

  `[in]` | array | Array of bits to be checked
  `[in]` | pos | Bit position to be checked

Returns:
  true if the specified bit is set, false otherwise

Definition at line 501 of file co_utils.h.

References CO_BIT.

__INLINE void co_bit_set | ( | uint8_t | array[],
|  | uint8_t | pos |
| ) |  |  |

This function sets a specific bit position inside an array of bits, represented as an array of bytes.

Parameters:

  `[in]` | array | Array of bits
  `[in]` | pos | Bit position to be set

Definition at line 514 of file co_utils.h.

References CO_BIT.

__INLINE bool co_cmp8p | ( | uint32_t | pkd,
|  | uint8_t const * | ptr,
|  | uint32_t | len |
| ) |  |  |

Compare a packed byte buffer with a CPU byte array.

Parameters:

  `[in]` | pkd | The address of the packed buffer.
  `[in]` | ptr | Pointer to the CPU byte array
  `[in]` | len | Length to be compared

Returns:
  true if the buffers are equal, false otherwise

Definition at line 360 of file co_utils.h.

References co_read8p().

Referenced by mac_vsie_find().

__INLINE void co_copy32 | ( | uint32_t * | dst,
|  | uint32_t * | src,
|  | uint32_t | len |
| ) |  |  |

Copy a 32-bit aligned buffer into another one The length in bytes is converted to the corresponding number of 32-bit words.

If the byte length is not a multiple of 4, then additional bytes will be copied at the end of the buffer. It is the responsibility of the caller to ensure that these extra-byte copy won't corrupt the memory at the end of the destination buffer.

Parameters:

  `[in]` | dst | Pointer to the destination buffer
  `[in]` | src | Pointer to the source buffer
  `[in]` | len | Length to be copied (in bytes)

Definition at line 176 of file co_utils.h.

References CO_ALIGN4_HI.

Referenced by rxl_mpdu_copy().

__INLINE void co_copy8p | ( | uint32_t | dst,
|  | uint32_t | src,
|  | uint32_t | len |
| ) |  |  |

Copy a packed byte array to another packed byte array.

Parameters:

  `[in]` | dst | The address of the first byte of the packed buffer in which the data has to be copied.
  `[in]` | src | Address of the source buffer
  `[in]` | len | Length to be copied

Definition at line 413 of file co_utils.h.

References co_read8p(), and co_write8p().

Referenced by me_build_associate_req(), me_build_authenticate(), rxu_cntrl_mic_check(), rxu_cntrl_mic_rd_concat(), scanu_build_ie(), and txl_buffer_mic_compute().

__INLINE void co_pack8p | ( | uint32_t | dst,
|  | uint8_t const * | src,
|  | uint32_t | len |
| ) |  |  |

Copy and pack a byte array to another one.

Parameters:

  `[in]` | dst | The address of the first byte of the packed buffer in which the data has to be copied.
  `[in]` | src | Pointer to the source buffer
  `[in]` | len | Length to be copied

Definition at line 379 of file co_utils.h.

References co_write8p().

Referenced by me_add_ie_ext_supp_rates(), me_add_ie_ht_capa(), me_add_ie_ssid(), me_add_ie_supp_rates(), me_build_associate_req(), and scanu_build_ie().

__INLINE uint16_t co_read16 | ( | void const * | ptr16 | ) |

Read an aligned 16 bits word.

Parameters:

  `[in]` | ptr16 | The address of the first byte of the 16 bits word.

Returns:
  The 16 bits value.

Definition at line 122 of file co_utils.h.

Referenced by rxl_frame_handle(), rxl_pm_check(), rxl_rxcntrl_frame(), and tdls_check_frame_action().

__INLINE uint16_t co_read16p | ( | uint32_t | addr | ) |

Read a packed 16 bits word.

Parameters:

  `[in]` | addr | The address of the first byte of the 16 bits word.

Returns:
  The 16 bits value.

Definition at line 229 of file co_utils.h.

References __PACKED16, and co_read8p().

Referenced by co_read24p(), co_read32p(), me_extract_ht_capa(), me_extract_mobility_domain(), me_extract_vht_capa(), mfp_check_mmic_ie(), p2p_att_find(), p2p_cli_noa_handle_att(), rxu_mgt_ind_handler(), scanu_get_multi_bssid_info(), scanu_get_security_info(), tdls_check_tdls_channel_switch_request(), tdls_check_tdls_channel_switch_response(), tdls_check_tdls_peer_traffic_response(), txl_check_bcmc_status(), and txl_cntrl_start_pm_mon().

__INLINE uint32_t co_read24p | ( | uint32_t | addr | ) |

Read a packed 24 bits word.

Parameters:

  `[in]` | addr | The address of the first byte of the 24 bits word.

Returns:
  The 24 bits value, on a 32-bit variable.

Definition at line 271 of file co_utils.h.

References co_read16p(), and co_read8p().

__INLINE uint32_t co_read32 | ( | void const * | ptr32 | ) |

Read an aligned 32 bit word.

Parameters:

  `[in]` | ptr32 | The address of the first byte of the 32 bit word.

Returns:
  The 32 bit value.

Definition at line 146 of file co_utils.h.

__INLINE uint32_t co_read32p | ( | uint32_t | addr | ) |

Read a packed 32 bits word.

Parameters:

  `[in]` | addr | The address of the first byte of the 32 bits word.

Returns:
  The 32 bits value.

Definition at line 296 of file co_utils.h.

References __PACKED, and co_read16p().

Referenced by aes_cmac(), bfr_upload_report(), co_read64p(), me_extract_edca_params(), me_extract_vht_capa(), p2p_cli_noa_handle_att(), and tdls_check_frame_action().

__INLINE uint64_t co_read64p | ( | uint32_t | addr | ) |

Read a packed 64 bits word.

Parameters:

  `[in]` | addr | The address of the first byte of the 64 bits word.

Returns:
  The 64 bits value.

Definition at line 337 of file co_utils.h.

References __PACKED, and co_read32p().

Referenced by mfp_check_mmic_ie().

__INLINE uint8_t co_read8p | ( | uint32_t | addr | ) |

Read a 8 bits word.

Parameters:

  `[in]` | addr | The address of the first byte of the 8 bits word.

Returns:
  The read value

Definition at line 192 of file co_utils.h.

Referenced by aes_cmac(), bfr_is_vht_bfr(), co_cmp8p(), co_copy8p(), co_read16p(), co_read24p(), co_unpack8p(), mac_ext_ie_find(), mac_ie_find(), mac_ie_len(), me_beacon_check(), me_bw_check(), me_erp_prot_check(), me_extract_country_reg(), me_extract_csa(), me_extract_edca_params(), me_extract_ht_capa(), me_extract_mobility_domain(), me_extract_power_constraint(), me_extract_rate_set(), mm_bcn_build(), mm_bcn_csa_init(), mm_bcn_desc_prep(), mm_compute_beacon_crc(), mm_tim_update_proceed(), p2p_att_find(), p2p_cli_noa_handle_att(), rxu_mgt_ind_handler(), rxu_mgt_route_action(), scanu_build_ie(), scanu_get_multi_bssid_info(), scanu_scan_frame_handler(), tdls_check_frame_action(), tdls_check_tdls_channel_switch_request(), tdls_check_tdls_channel_switch_response(), tdls_check_tdls_peer_traffic_response(), and txl_machdr_format().

__INLINE void co_unpack8p | ( | uint8_t * | dst,
|  | uint32_t | src,
|  | uint32_t | len |
| ) |  |  |

Copy and unpack a byte array to another one.

Parameters:

  `[in]` | dst | Pointer to the first byte of the unpacked buffer in which the data has to be copied.
  `[in]` | src | Address of the packed source buffer
  `[in]` | len | Length to be copied

Definition at line 396 of file co_utils.h.

References co_read8p().

Referenced by me_extract_ht_capa(), scanu_check_ssid(), scanu_new_bssid_set(), and scanu_scan_frame_handler().

__INLINE uint8_t co_val_get | ( | uint8_t const | array[],
|  | int | lsb,
|  | int | width |
| ) |  |  |

This function returns the value of bit field inside an array of bits, represented as an array of bytes.

Parameters:

  `[in]` | array | Array of bits
  `[in]` | lsb | Position of the LSB of the field inside the array of bits
  `[in]` | width | Width of the field

Returns:
  true if the specified bit is set, false otherwise

Definition at line 431 of file co_utils.h.

References CO_BIT.

__INLINE void co_val_set | ( | uint8_t | array[],
|  | int | lsb,
|  | int | width,
|  | uint8_t | val |
| ) |  |  |

This function sets a value of a bit field inside an array of bits, represented as an array of bytes.

Parameters:

  `[in]` | array | Array of bits
  `[in]` | lsb | Position of the LSB of the field inside the array of bits
  `[in]` | width | Width of the field
  `[in]` | val | Value to be set

Definition at line 466 of file co_utils.h.

References CO_BIT.

__INLINE void co_write16 | ( | void const * | ptr16,
|  | uint32_t | value |
| ) |  |  |

Write an aligned 16 bits word.

Parameters:

  `[in]` | ptr16 | The address of the first byte of the 16 bits word.
  `[in]` | value | The value to write.

Definition at line 134 of file co_utils.h.

Referenced by mm_bcn_build().

__INLINE void co_write16p | ( | uint32_t | addr,
|  | uint32_t | value |
| ) |  |  |

Write a packed 16 bits word.

Parameters:

  `[in]` | addr | The address of the first byte of the 16 bits word.
  `[in]` | value | The value to write.

Definition at line 249 of file co_utils.h.

References __PACKED16, and co_write8p().

Referenced by bfr_prep_ndpa(), bfr_upload_report(), co_write24p(), co_write32p(), me_add_ba_ssc_frame(), me_add_baparamset_frame(), me_add_ie_ht_capa(), me_add_ie_ht_oper(), me_build_add_ba_req(), me_build_add_ba_rsp(), me_build_associate_req(), me_build_authenticate(), me_build_deauthenticate(), me_build_del_ba(), me_del_baparamset_frame(), txl_check_bcmc_status(), txl_frame_send_tdls_channel_switch_req_frame(), txl_frame_send_tdls_channel_switch_rsp_frame(), txl_frame_send_tdls_peer_traffic_ind_frame(), and txl_machdr_format().

__INLINE void co_write24p | ( | uint32_t | addr,
|  | uint32_t | value |
| ) |  |  |

Write a packed 24 bits word.

Parameters:

  `[in]` | addr | The address of the first byte of the 24 bits word.
  `[in]` | value | The value to write.

Definition at line 283 of file co_utils.h.

References co_write16p(), and co_write8p().

__INLINE void co_write32 | ( | void const * | ptr32,
|  | uint32_t | value |
| ) |  |  |

Write an aligned 32 bits word.

Parameters:

  `[in]` | ptr32 | The address of the first byte of the 32 bits word.
  `[in]` | value | The value to write.

Definition at line 158 of file co_utils.h.

__INLINE void co_write32p | ( | uint32_t | addr,
|  | uint32_t | value |
| ) |  |  |

Write a packed 32 bits word.

Parameters:

  `[in]` | addr | The address of the first byte of the 32 bits word.
  `[in]` | value | The value to write.

Definition at line 316 of file co_utils.h.

References __PACKED, and co_write16p().

Referenced by txl_frame_send_tdls_channel_switch_req_frame(), txl_frame_send_tdls_channel_switch_rsp_frame(), txl_frame_send_tdls_peer_traffic_ind_frame(), and txu_cntrl_mac_hdr_append().

__INLINE void co_write8p | ( | uint32_t | addr,
|  | uint8_t | value |
| ) |  |  |

Write a 8 bits word.

Parameters:

  `[in]` | addr | The address of the first byte of the 8 bits word.
  `[in]` | value | The value to write.

Definition at line 210 of file co_utils.h.

Referenced by aes_cmac(), bfr_prep_bfr_poll(), bfr_prep_ndpa(), co_copy8p(), co_pack8p(), co_write16p(), co_write24p(), me_add_ie_dsss_param(), me_add_ie_ext_supp_rates(), me_add_ie_ht_capa(), me_add_ie_ht_oper(), me_add_ie_ssid(), me_add_ie_supp_rates(), me_add_ie_tim(), me_build_add_ba_req(), me_build_add_ba_rsp(), me_build_associate_req(), me_build_authenticate(), me_build_del_ba(), mfp_check_mmic_ie(), mm_bcn_build(), mm_bcn_desc_prep(), mm_bcn_init_tim(), mm_tim_update_proceed(), scanu_build_ie(), txl_frame_send_tdls_channel_switch_req_frame(), txl_frame_send_tdls_channel_switch_rsp_frame(), and txl_frame_send_tdls_peer_traffic_ind_frame().