diff --git a/src/include/ubus.h b/src/include/ubus.h index 0de634b..d436912 100644 --- a/src/include/ubus.h +++ b/src/include/ubus.h @@ -81,7 +81,7 @@ int handle_auth_req(struct blob_attr* msg); * @param probe_entry * @return */ -int ubus_send_probe_via_network(struct probe_entry_s *probe_entry); +int ubus_send_probe_via_network(struct probe_entry_s *probe_entry, bool is_beacon); /** * Add mac to a list that contains addresses of clients that can not be controlled. diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 4192b08..41a51b3 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -794,16 +794,42 @@ probe_entry* probe_array_update_rssi(struct dawn_mac client_addr, struct dawn_ma dawnlog_debug_func("Entering..."); dawn_mutex_require(&probe_array_mutex); - probe_entry* entry = probe_array_get_entry(client_addr, bssid_addr); + probe_entry* probe_req_new = dawn_malloc(sizeof(probe_entry)); - if (entry) { - entry->signal = rssi; + if (probe_req_new) { + // Fields we will update + probe_req_new->client_addr = client_addr; + probe_req_new->bssid_addr = bssid_addr; + probe_req_new->signal = rssi; + + // Other fields in case entry is new + probe_req_new->ht_capabilities = false; + probe_req_new->vht_capabilities = false; + probe_req_new->rcpi = -1; + probe_req_new->rsni = -1; + + //FIXME: Should we put the linked list defaults in the insert function? + probe_req_new->next_probe = NULL; + probe_req_new->next_probe_skip = NULL; + + probe_entry* probe_req_updated = insert_to_probe_array(probe_req_new, false, false, false, time(0)); + if (probe_req_new != probe_req_updated) + { + dawnlog_info("RSSI PROBE used to update client / BSSID = " MACSTR " / " MACSTR " \n", MAC2STR(probe_req_updated->client_addr.u8), MAC2STR(probe_req_updated->bssid_addr.u8)); + + dawn_free(probe_req_new); + probe_req_new = NULL; + } + else + { + dawnlog_info("RSSI PROBE is new for client / BSSID = " MACSTR " / " MACSTR " \n", MAC2STR(probe_req_updated->client_addr.u8), MAC2STR(probe_req_updated->bssid_addr.u8)); + } if (send_network) - ubus_send_probe_via_network(entry); + ubus_send_probe_via_network(probe_req_updated, false); } - return entry; + return probe_req_new; } probe_entry* probe_array_update_rcpi_rsni(struct dawn_mac client_addr, struct dawn_mac bssid_addr, uint32_t rcpi, uint32_t rsni, int send_network) @@ -822,7 +848,7 @@ probe_entry* probe_array_update_rcpi_rsni(struct dawn_mac client_addr, struct da entry->rsni = rsni; if (send_network) - ubus_send_probe_via_network(entry); + ubus_send_probe_via_network(entry, true); } return entry; @@ -897,8 +923,13 @@ probe_entry* insert_to_probe_array(probe_entry* entry, int is_local, int save_80 // Beacon reports don't have these fields, so only update them from probes (*node_ref)->signal = entry->signal; - (*node_ref)->ht_capabilities = entry->ht_capabilities; - (*node_ref)->vht_capabilities = entry->vht_capabilities; + + // Some "synthetic" PROBE entries have FALSE for these which would overwrite genuine values + if (entry->ht_capabilities) + (*node_ref)->ht_capabilities = entry->ht_capabilities; + + if (entry->vht_capabilities) + (*node_ref)->vht_capabilities = entry->vht_capabilities; } else { @@ -917,6 +948,7 @@ probe_entry* insert_to_probe_array(probe_entry* entry, int is_local, int save_80 else { dawnlog_debug("Adding...\n"); + if (is_local && !is_beacon) entry->counter = 1; else @@ -938,10 +970,10 @@ probe_entry* insert_to_probe_array(probe_entry* entry, int is_local, int save_80 { entry->next_probe_skip = NULL; } - - entry->time = expiry; } + entry->time = expiry; + return entry; // return pointer to what we used, which may not be what was passed in } diff --git a/src/test/test_storage.c b/src/test/test_storage.c index 5c8ce04..41377c0 100644 --- a/src/test/test_storage.c +++ b/src/test/test_storage.c @@ -71,7 +71,7 @@ void del_client_interface(uint32_t id, const struct dawn_mac client_addr, uint32 printf("del_client_interface() was called...\n"); } -int ubus_send_probe_via_network(struct probe_entry_s *probe_entry) +int ubus_send_probe_via_network(struct probe_entry_s *probe_entry, bool is_beacon) { printf("send_probe_via_network() was called...\n"); return 0; diff --git a/src/utils/msghandler.c b/src/utils/msghandler.c index 305dfbe..fe0280b 100644 --- a/src/utils/msghandler.c +++ b/src/utils/msghandler.c @@ -301,7 +301,7 @@ int handle_network_msg(char* msg) { dawn_mutex_lock(&probe_array_mutex); dawn_mutex_require(&probe_array_mutex); - if (entry != insert_to_probe_array(entry, false, true, false, time(0))) // use 802.11k values + if (entry != insert_to_probe_array(entry, false, false, false, time(0))) // use 802.11k values { // insert found an existing entry, rather than linking in our new one dawnlog_info("Remote PROBE updated client / BSSID = " MACSTR " / " MACSTR " \n", @@ -341,13 +341,28 @@ int handle_network_msg(char* msg) { handle_uci_config(data_buf.head); } else if (strncmp(method, "beacon-report", 12) == 0) { - // TODO: Check beacon report stuff + probe_entry* entry = parse_to_probe_req(data_buf.head); + if (entry != NULL) { + dawn_mutex_lock(&probe_array_mutex); - dawnlog_debug("HANDLING BEACON REPORT NETWORK!\n"); - dawnlog_debug("The Method for beacon-report is: %s\n", method); - // ignore beacon reports send via network!, use probe functions for it - //probe_entry entry; // for now just stay at probe entry stuff... - //parse_to_beacon_rep(data_buf.head, &entry, true); + dawn_mutex_require(&probe_array_mutex); + if (entry != insert_to_probe_array(entry, false, true, true, time(0))) // use 802.11k values + { + // insert found an existing entry, rather than linking in our new one + dawnlog_info("Remote BEACON updated client / BSSID = " MACSTR " / " MACSTR " \n", + MAC2STR(entry->client_addr.u8), MAC2STR(entry->bssid_addr.u8)); + + dawn_free(entry); + entry = NULL; + } + else + { + dawnlog_info("Remote BEACON is for new client / BSSID = " MACSTR " / " MACSTR " \n", + MAC2STR(entry->client_addr.u8), MAC2STR(entry->bssid_addr.u8)); + } + + dawn_mutex_unlock(&probe_array_mutex); + } } else { diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 4c67b0e..77e5911 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -504,7 +504,7 @@ static int handle_probe_req(struct blob_attr* msg) { dawn_mutex_lock(&probe_array_mutex); dawn_mutex_require(&probe_array_mutex); - probe_entry* probe_req_updated = insert_to_probe_array(probe_req_new, true, true, false, time(0)); + probe_entry* probe_req_updated = insert_to_probe_array(probe_req_new, true, false, false, time(0)); // If insert finds an existing entry, rather than linking in our new one, // send new probe req because we want to stay synced. // If not, probe_req and probe_req_updated should be equivalent @@ -520,7 +520,7 @@ static int handle_probe_req(struct blob_attr* msg) { dawnlog_info("Local PROBE is new for client / BSSID = " MACSTR " / " MACSTR " \n", MAC2STR(probe_req_updated->client_addr.u8), MAC2STR(probe_req_updated->bssid_addr.u8)); } - ubus_send_probe_via_network(probe_req_updated); + ubus_send_probe_via_network(probe_req_updated, false); if (dawn_metric.eval_probe_req <= 0) { dawnlog_trace(MACSTR " Allow probe due to not evaluating requests", MAC2STR(probe_req_updated->client_addr.u8)); @@ -600,8 +600,8 @@ static int handle_beacon_rep(struct blob_attr *msg) { // BEACON will never set RSSI, but may have RCPI and RSNI dawn_mutex_require(&probe_array_mutex); - entry = insert_to_probe_array(entry, false, false, true, time(0)); - ubus_send_probe_via_network(entry); + entry = insert_to_probe_array(entry, true, true, true, time(0)); + ubus_send_probe_via_network(entry, true); ret = 0; } @@ -1249,7 +1249,7 @@ int ubus_call_umdns() { } //TODO: ADD STUFF HERE!!!! -int ubus_send_probe_via_network(struct probe_entry_s *probe_entry) { // TODO: probe_entry is also a typedef - fix? +int ubus_send_probe_via_network(struct probe_entry_s *probe_entry, bool is_beacon) { // TODO: probe_entry is also a typedef - fix? struct blob_buf b = {0}; dawnlog_debug_func("Entering..."); @@ -1259,27 +1259,33 @@ int ubus_send_probe_via_network(struct probe_entry_s *probe_entry) { // TODO: p blobmsg_add_macaddr(&b, "bssid", probe_entry->bssid_addr); blobmsg_add_macaddr(&b, "address", probe_entry->client_addr); blobmsg_add_macaddr(&b, "target", probe_entry->target_addr); - blobmsg_add_u32(&b, "signal", probe_entry->signal); - blobmsg_add_u32(&b, "freq", probe_entry->freq); - blobmsg_add_u32(&b, "rcpi", probe_entry->rcpi); - blobmsg_add_u32(&b, "rsni", probe_entry->rsni); - - blobmsg_add_u32(&b, "ht_capabilities", probe_entry->ht_capabilities); - blobmsg_add_u32(&b, "vht_capabilities", probe_entry->vht_capabilities); - - /*if (probe_entry->ht_capabilities) + if (!is_beacon) { - void *ht_cap = blobmsg_open_table(&b, "ht_capabilities"); - blobmsg_close_table(&b, ht_cap); + blobmsg_add_u32(&b, "signal", probe_entry->signal); + blobmsg_add_u32(&b, "freq", probe_entry->freq); + + blobmsg_add_u32(&b, "ht_capabilities", probe_entry->ht_capabilities); + blobmsg_add_u32(&b, "vht_capabilities", probe_entry->vht_capabilities); + + /*if (probe_entry->ht_capabilities) + { + void *ht_cap = blobmsg_open_table(&b, "ht_capabilities"); + blobmsg_close_table(&b, ht_cap); + } + + if (probe_entry->vht_capabilities) { + void *vht_cap = blobmsg_open_table(&b, "vht_capabilities"); + blobmsg_close_table(&b, vht_cap); + }*/ + } + else + { + blobmsg_add_u32(&b, "rcpi", probe_entry->rcpi); + blobmsg_add_u32(&b, "rsni", probe_entry->rsni); } - if (probe_entry->vht_capabilities) { - void *vht_cap = blobmsg_open_table(&b, "vht_capabilities"); - blobmsg_close_table(&b, vht_cap); - }*/ - - send_blob_attr_via_network(b.head, "probe"); + send_blob_attr_via_network(b.head, is_beacon ? "beacon-report" : "probe"); blob_buf_free(&b); dawn_unregmem(&b);