Add get_clients

This commit is contained in:
PolynomialDivision 2017-07-15 15:55:52 +02:00
parent ecb6c6b80f
commit 2228c2a74a
2 changed files with 139 additions and 0 deletions

View file

@ -27,6 +27,43 @@ typedef struct {
int counter;
} probe_entry;
/*
static const struct {
const char *name;
uint32_t flag;
} sta_flags[] = {
{ "auth", WLAN_STA_AUTH },
{ "assoc", WLAN_STA_ASSOC },
{ "authorized", WLAN_STA_AUTHORIZED },
{ "preauth", WLAN_STA_PREAUTH },
{ "wds", WLAN_STA_WDS },
{ "wmm", WLAN_STA_WMM },
{ "ht", WLAN_STA_HT },
{ "vht", WLAN_STA_VHT },
{ "wps", WLAN_STA_WPS },
{ "mfp", WLAN_STA_MFP },
};
*/
typedef struct {
uint32_t freq;
} client_request;
typedef struct {
uint8_t mac[ETH_ALEN];
uint32_t freq;
uint32_t auth;
uint32_t assoc;
uint32_t authorized;
uint32_t preauth;
uint32_t wds;
uint32_t wmm;
uint32_t ht;
uint32_t vht;
uint32_t wps;
uint32_t mfp;
} client;
// List
typedef struct node {
probe_entry data;

View file

@ -33,6 +33,50 @@ static const struct blobmsg_policy prob_policy[__PROB_MAX] = {
[PROB_FREQ] = {.name = "freq", .type = BLOBMSG_TYPE_INT32},
};
enum {
CLIENT_TABLE,
CLIENT_TABLE_FREQ,
__CLIENT_TABLE_MAX,
};
static const struct blobmsg_policy client_table_policy[__CLIENT_TABLE_MAX] = {
[CLIENT_TABLE] = {.name = "clients", .type = BLOBMSG_TYPE_TABLE},
[CLIENT_TABLE_FREQ] = {.name = "freq", .type = BLOBMSG_TYPE_INT32},
};
enum {
//CLIENT_TABLE,
//CLIENT_TABLE_FREQ,
CLIENT_AUTH,
CLIENT_ASSOC,
CLIENT_AUTHORIZED,
CLIENT_PREAUTH,
CLIENT_WDS,
CLIENT_WMM,
CLIENT_HT,
CLIENT_VHT,
CLIENT_WPS,
CLIENT_MFP,
CLIENT_AID,
__CLIENT_MAX,
};
static const struct blobmsg_policy client_policy[__CLIENT_MAX] = {
//[CLIENT_TABLE] = {.name = "clients", .type = BLOBMSG_TYPE_TABLE},
//[CLIENT_TABLE_FREQ] = {.name = "freq", .type = BLOBMSG_TYPE_INT32},
[CLIENT_AUTH] = {.name = "auth", .type = BLOBMSG_TYPE_INT8},
[CLIENT_ASSOC] = {.name = "assoc", .type = BLOBMSG_TYPE_INT8},
[CLIENT_AUTHORIZED] = {.name = "authorized", .type = BLOBMSG_TYPE_INT8},
[CLIENT_PREAUTH] = {.name = "preauth", .type = BLOBMSG_TYPE_INT8},
[CLIENT_WDS] = {.name = "wds", .type = BLOBMSG_TYPE_INT8},
[CLIENT_WMM] = {.name = "wmm", .type = BLOBMSG_TYPE_INT8},
[CLIENT_HT] = {.name = "ht", .type = BLOBMSG_TYPE_INT8},
[CLIENT_VHT] = {.name = "vht", .type = BLOBMSG_TYPE_INT8},
[CLIENT_WPS] = {.name = "wps", .type = BLOBMSG_TYPE_INT8},
[CLIENT_MFP] = {.name = "mfp", .type = BLOBMSG_TYPE_INT8},
[CLIENT_AID] = {.name = "aid", .type = BLOBMSG_TYPE_INT32},
};
/* Function Definitions */
static void hostapd_handle_remove(struct ubus_context *ctx,
struct ubus_subscriber *s, uint32_t id);
@ -183,12 +227,70 @@ int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) {
return 0;
}
static void
dump_client(struct blob_attr **tb)
{
printf("DUMPING CLIENT:\n");
if (tb[CLIENT_AUTH]) {
printf("AUTH: %d\n", blobmsg_get_u8(tb[CLIENT_AUTH]));
}
if (tb[CLIENT_ASSOC]) {
printf("ASSOC: %d\n", blobmsg_get_u8(tb[CLIENT_ASSOC]));
}
if(tb[CLIENT_PREAUTH]){
printf("Preauth: %d\n", blobmsg_get_u8(tb[CLIENT_PREAUTH]));
}
if(tb[CLIENT_HT]){
printf("HT: %d\n", blobmsg_get_u8(tb[CLIENT_HT]));
}
if(tb[CLIENT_HT]){
printf("AID: %d\n", blobmsg_get_u32(tb[CLIENT_AID]));
}
printf("Dumped Client!\n");
}
static void
dump_client_table(struct blob_attr *head, int len)
{
struct blob_attr *attr;
struct blobmsg_hdr *hdr;
__blob_for_each_attr(attr, head, len) {
hdr = blob_data(attr);
printf("%s\n", hdr->name); // mac client
struct blob_attr *tb[__CLIENT_MAX];
blobmsg_parse(client_policy, __CLIENT_MAX, tb, blobmsg_data(attr), blobmsg_len(attr));
char* str = blobmsg_format_json_indent(attr, true, -1);
printf("%s\n", str);
dump_client(tb);
}
}
static int parse_to_clients(struct blob_attr *msg) {
struct blob_attr *tb[__CLIENT_TABLE_MAX];
blobmsg_parse(client_table_policy, __CLIENT_TABLE_MAX, tb, blob_data(msg), blob_len(msg));
if (tb[CLIENT_TABLE]) {
dump_client_table(blobmsg_data(tb[CLIENT_TABLE]), blobmsg_data_len(tb[CLIENT_TABLE]));
}
printf("Parsing client request success!!!\n");
return 0;
}
static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_attr *msg)
{
char *str;
if (!msg)
return;
parse_to_clients(msg);
str = blobmsg_format_json_indent(msg, true, -1);
printf("%s\n", str);
free(str);