mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-03-31 06:56:52 +02:00
nl80211util: Add skeleton of nl80211_parse_attrs
This commit is contained in:
parent
1fc480c007
commit
2dbcad3185
@ -24,6 +24,7 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <linux/if_ether.h>
|
#include <linux/if_ether.h>
|
||||||
#include <ell/ell.h>
|
#include <ell/ell.h>
|
||||||
|
|
||||||
@ -31,6 +32,100 @@
|
|||||||
|
|
||||||
#include "src/nl80211util.h"
|
#include "src/nl80211util.h"
|
||||||
|
|
||||||
|
typedef bool (*attr_handler)(const void *data, uint16_t len, void *o);
|
||||||
|
|
||||||
|
static bool extract_ifindex(const void *data, uint16_t len, void *o)
|
||||||
|
{
|
||||||
|
uint32_t *out = o;
|
||||||
|
|
||||||
|
if (len != 4)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* ifindex cannot be 0 */
|
||||||
|
if (l_get_u32(data) == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*out = l_get_u32(data);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static attr_handler handler_for_type(enum nl80211_attrs type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case NL80211_ATTR_IFINDEX:
|
||||||
|
return extract_ifindex;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct attr_entry {
|
||||||
|
uint16_t type;
|
||||||
|
void *data;
|
||||||
|
attr_handler handler;
|
||||||
|
};
|
||||||
|
|
||||||
|
int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...)
|
||||||
|
{
|
||||||
|
struct l_genl_attr attr;
|
||||||
|
va_list args;
|
||||||
|
struct l_queue *entries;
|
||||||
|
const struct l_queue_entry *e;
|
||||||
|
struct attr_entry *entry;
|
||||||
|
uint16_t type;
|
||||||
|
uint16_t len;
|
||||||
|
const void *data;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (!l_genl_attr_init(&attr, msg))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
va_start(args, tag);
|
||||||
|
entries = l_queue_new();
|
||||||
|
ret = -ENOSYS;
|
||||||
|
|
||||||
|
while (tag != NL80211_ATTR_UNSPEC) {
|
||||||
|
entry = l_new(struct attr_entry, 1);
|
||||||
|
|
||||||
|
entry->type = tag;
|
||||||
|
entry->data = va_arg(args, void *);
|
||||||
|
entry->handler = handler_for_type(tag);
|
||||||
|
l_queue_push_tail(entries, entry);
|
||||||
|
|
||||||
|
if (!entry->handler)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
tag = va_arg(args, enum nl80211_attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
||||||
|
for (e = l_queue_get_entries(entries); e; e = e->next) {
|
||||||
|
entry = e->data;
|
||||||
|
|
||||||
|
if (entry->type == type)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!e)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!entry->handler(data, len, entry->data)) {
|
||||||
|
ret = -EINVAL;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
done:
|
||||||
|
l_queue_destroy(entries, l_free);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
struct l_genl_msg *nl80211_build_new_key_group(uint32_t ifindex, uint32_t cipher,
|
struct l_genl_msg *nl80211_build_new_key_group(uint32_t ifindex, uint32_t cipher,
|
||||||
uint8_t key_id, const uint8_t *key,
|
uint8_t key_id, const uint8_t *key,
|
||||||
size_t key_len, const uint8_t *ctr,
|
size_t key_len, const uint8_t *ctr,
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include <ell/ell.h>
|
#include <ell/ell.h>
|
||||||
|
|
||||||
|
int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...);
|
||||||
|
|
||||||
struct l_genl_msg *nl80211_build_new_key_group(uint32_t ifindex,
|
struct l_genl_msg *nl80211_build_new_key_group(uint32_t ifindex,
|
||||||
uint32_t cipher, uint8_t key_id,
|
uint32_t cipher, uint8_t key_id,
|
||||||
const uint8_t *key, size_t key_len,
|
const uint8_t *key, size_t key_len,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user