diff options
author | Marc <foxtrot@malloc.me> | 2022-01-09 16:07:03 +0000 |
---|---|---|
committer | Marc <foxtrot@malloc.me> | 2022-01-09 16:07:03 +0000 |
commit | 96b638f0d0cacf58c1b0bab5f38f9d82b9e93f3f (patch) | |
tree | a241be5b1b868cc4cce75bcade73d65a419a2671 | |
parent | 1d9f81ab8641c5fb1f46d16081c8b320998c70ec (diff) | |
download | libwifi-96b638f0d0cacf58c1b0bab5f38f9d82b9e93f3f.tar.gz libwifi-96b638f0d0cacf58c1b0bab5f38f9d82b9e93f3f.tar.bz2 libwifi-96b638f0d0cacf58c1b0bab5f38f9d82b9e93f3f.zip |
core: Add a function to check if a tag is present by tag number
-rw-r--r-- | src/libwifi/core/frame/tag.c | 16 | ||||
-rw-r--r-- | src/libwifi/core/frame/tag.h | 9 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/libwifi/core/frame/tag.c b/src/libwifi/core/frame/tag.c index 9dec547..1d43c55 100644 --- a/src/libwifi/core/frame/tag.c +++ b/src/libwifi/core/frame/tag.c | |||
@@ -129,3 +129,19 @@ int libwifi_quick_add_tag(struct libwifi_tagged_parameters *tags, int tag_number | |||
129 | 129 | ||
130 | return 0; | 130 | return 0; |
131 | } | 131 | } |
132 | |||
133 | int libwifi_check_tag(struct libwifi_tagged_parameters *tags, int tag_number) { | ||
134 | int tag_count = 0; | ||
135 | struct libwifi_tag_iterator it = {0}; | ||
136 | if (libwifi_tag_iterator_init(&it, tags->parameters, tags->length) != 0) { | ||
137 | return -EINVAL; | ||
138 | } | ||
139 | |||
140 | do { | ||
141 | if (it.tag_header->tag_num == tag_number) { | ||
142 | tag_count++; | ||
143 | } | ||
144 | } while (libwifi_tag_iterator_next(&it) != -1); | ||
145 | |||
146 | return tag_count; | ||
147 | } | ||
diff --git a/src/libwifi/core/frame/tag.h b/src/libwifi/core/frame/tag.h index 02928fe..030c0b9 100644 --- a/src/libwifi/core/frame/tag.h +++ b/src/libwifi/core/frame/tag.h | |||
@@ -303,4 +303,13 @@ size_t libwifi_dump_tag(struct libwifi_tagged_parameter *tag, unsigned char *buf | |||
303 | int libwifi_quick_add_tag(struct libwifi_tagged_parameters *tagged_parameters, int tag_number, | 303 | int libwifi_quick_add_tag(struct libwifi_tagged_parameters *tagged_parameters, int tag_number, |
304 | const unsigned char *tag_data, size_t tag_length); | 304 | const unsigned char *tag_data, size_t tag_length); |
305 | 305 | ||
306 | /** | ||
307 | * Check if a tagged parameter is present via tag number. | ||
308 | * | ||
309 | * @param tags A tagged parameters list | ||
310 | * @param tag_number The number of the tagged parameter to find | ||
311 | * @returns The number of times the supplied tag_number was found in tags | ||
312 | */ | ||
313 | int libwifi_check_tag(struct libwifi_tagged_parameters *tags, int tag_number); | ||
314 | |||
306 | #endif /* LIBWIFI_CORE_TAG_H */ | 315 | #endif /* LIBWIFI_CORE_TAG_H */ |