Morse Micro IoT SDK  2.6.4-esp32
mmutils.h
1/*
2 * Copyright 2024 Morse Micro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
15#pragma once
16
17#include <stdarg.h>
18#include <stdint.h>
19#include <stdlib.h>
20#include <stdbool.h>
21#include <string.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
41#define MM_MIN(_x, _y) (((_x)<(_y))?(_x):(_y))
42
57#define MM_MAX(_x, _y) (((_x)>(_y))?(_x):(_y))
58
64#ifndef MM_FAST_ROUND_UP
65#define MM_FAST_ROUND_UP(x, m) ((((x)-1) | ((m)-1)) + 1)
66#endif
67
69#define MM_UNUSED(_x) (void)(_x)
70
72#ifndef MM_PACKED
73#define MM_PACKED __attribute__((packed))
74#endif
75
77#ifndef MM_WEAK
78#define MM_WEAK __attribute__((weak))
79#endif
80
81#ifndef MM_STATIC_ASSERT
93#define MM_STATIC_ASSERT(_expression, _message) _Static_assert((_expression), _message)
94#endif
95
105#define MM_ARRAY_COUNT(_a) (sizeof(_a)/sizeof((_a)[0]))
106
118static inline char mm_nibble_to_hex_char(uint8_t nibble)
119{
120 nibble &= 0x0f;
121 if (nibble < 0x0a)
122 {
123 return '0' + nibble;
124 }
125 else
126 {
127 return 'A' + nibble - 0x0a;
128 }
129}
130
141{
145 MM_AKM_SUITE_PSK = 0x506f9a02,
147 MM_AKM_SUITE_SAE = 0x000fac08,
149 MM_AKM_SUITE_OWE = 0x000fac12,
152};
153
156{
161};
162
164#ifndef MM_RSN_INFORMATION_MAX_PAIRWISE_CIPHER_SUITES
165#define MM_RSN_INFORMATION_MAX_PAIRWISE_CIPHER_SUITES (2)
166#endif
167
169#ifndef MM_RSN_INFORMATION_MAX_AKM_SUITES
170#define MM_RSN_INFORMATION_MAX_AKM_SUITES (2)
171#endif
172
174#define MM_RSN_INFORMATION_IE_TYPE (48)
176#define MM_VENDOR_SPECIFIC_IE_TYPE (221)
177
181{
182 MM_ENOMEM = 12,
183 MM_EFAULT = 14,
184 MM_ENODEV = 19,
185 MM_EINVAL = 22,
186 MM_ETIMEDOUT = 110,
187};
188
195{
207 uint16_t version;
210};
211
212
220const char *mm_akm_suite_to_string(uint32_t akm_suite_oui);
221
237int mm_find_ie_from_offset(const uint8_t *ies, uint32_t ies_len,
238 uint32_t search_offset, uint8_t ie_type);
239
251static inline int mm_find_ie(const uint8_t *ies, uint32_t ies_len, uint8_t ie_type)
252{
253 return mm_find_ie_from_offset(ies, ies_len, 0, ie_type);
254}
255
272int mm_find_vendor_specific_ie_from_offset(const uint8_t *ies, uint32_t ies_len,
273 uint32_t search_offset,
274 const uint8_t *id, size_t id_len);
275
288static inline int mm_find_vendor_specific_ie(const uint8_t *ies, uint32_t ies_len,
289 const uint8_t *id, size_t id_len)
290{
291 return mm_find_vendor_specific_ie_from_offset(ies, ies_len, 0, id, id_len);
292}
293
304int mm_parse_rsn_information(const uint8_t *ies, uint32_t ies_len,
305 struct mm_rsn_information *output);
306
309#ifdef __cplusplus
310}
311#endif
312
#define MM_RSN_INFORMATION_MAX_AKM_SUITES
Maximum number of AKM suites our parser will process.
Definition: mmutils.h:170
static int mm_find_vendor_specific_ie(const uint8_t *ies, uint32_t ies_len, const uint8_t *id, size_t id_len)
Search through the given list of Information Elements (IEs) to find the first Vendor Specific IE that...
Definition: mmutils.h:288
mm_akm_suite_oui
Enumeration of Authentication Key Management (AKM) Suite OUIs as BE32 integers.
Definition: mmutils.h:141
static int mm_find_ie(const uint8_t *ies, uint32_t ies_len, uint8_t ie_type)
Search a list of Information Elements (IEs) and find the first instance of matching the given type.
Definition: mmutils.h:251
const char * mm_akm_suite_to_string(uint32_t akm_suite_oui)
Get the name of the given AKM Suite as a string.
int mm_find_vendor_specific_ie_from_offset(const uint8_t *ies, uint32_t ies_len, uint32_t search_offset, const uint8_t *id, size_t id_len)
Search through the given list of Information Elements (IEs) from the given starting offset to find th...
mm_errno
Explicitly defined errno values to obviate the need to include errno.h.
Definition: mmutils.h:181
int mm_parse_rsn_information(const uint8_t *ies, uint32_t ies_len, struct mm_rsn_information *output)
Search through the given list of information elements to find the RSN IE then parse it to extract rel...
#define MM_RSN_INFORMATION_MAX_PAIRWISE_CIPHER_SUITES
Maximum number of pairwise cipher suites our parser will process.
Definition: mmutils.h:165
mm_cipher_suite_oui
Enumeration of Cipher Suite OUIs as BE32 integers.
Definition: mmutils.h:156
int mm_find_ie_from_offset(const uint8_t *ies, uint32_t ies_len, uint32_t search_offset, uint8_t ie_type)
Search a list of Information Elements (IEs) from the given starting offset and find the first instanc...
@ MM_AKM_SUITE_SAE
Simultaneous Authentication of Equals (SAE)
Definition: mmutils.h:147
@ MM_AKM_SUITE_NONE
Open (no security)
Definition: mmutils.h:143
@ MM_AKM_SUITE_OWE
OWE.
Definition: mmutils.h:149
@ MM_AKM_SUITE_OTHER
Another suite not in this enum.
Definition: mmutils.h:151
@ MM_AKM_SUITE_PSK
Pre-shared key (WFA OUI)
Definition: mmutils.h:145
@ MM_CIPHER_SUITE_OTHER
Another cipher suite not in this enum.
Definition: mmutils.h:160
@ MM_CIPHER_SUITE_AES_CCM
Open (no security)
Definition: mmutils.h:158
static char mm_nibble_to_hex_char(uint8_t nibble)
Convert the least significant 4 bits of the given argument to a character representing their hexadeci...
Definition: mmutils.h:118
Data structure to represent information extracted from an RSN information element.
Definition: mmutils.h:195
uint16_t num_akm_suites
Number of AKM suites in akm_suites.
Definition: mmutils.h:205
uint32_t group_cipher_suite
The group cipher suite OUI.
Definition: mmutils.h:197
uint16_t version
Version number of the RSN IE.
Definition: mmutils.h:207
uint32_t pairwise_cipher_suites[MM_RSN_INFORMATION_MAX_PAIRWISE_CIPHER_SUITES]
Pairwise cipher suite OUIs.
Definition: mmutils.h:199
uint16_t rsn_capabilities
RSN Capabilities field of the RSN IE (in host order).
Definition: mmutils.h:209
uint16_t num_pairwise_cipher_suites
Number of pairwise cipher suites in pairwise_cipher_suites.
Definition: mmutils.h:203
uint32_t akm_suites[MM_RSN_INFORMATION_MAX_AKM_SUITES]
AKM suite OUIs.
Definition: mmutils.h:201