diff --git a/src/core/agent.c b/src/core/agent.c index 1f14adccf967e13874b5c66db15f697a8d23ab64..79c40798bfb43a7fc9a9856b2269006ad64f8f00 100644 --- a/src/core/agent.c +++ b/src/core/agent.c @@ -1961,6 +1961,7 @@ static void wifi_radio_event_handler(void *c, struct blob_attr *msg) scan_finished = !strcmp(action, "scan_finished"); if (scan_finished) { struct wifi_radio_element *current_radio = wifi_ifname_to_radio_element(agent, radio); + current_radio->scanned = 1; handle_wifi_radio_scan_finished(agent); } diff --git a/src/core/agent_map.c b/src/core/agent_map.c index 50810432082923e28e3c6f02864159eeae83ac83..21868c15b955c24caf1f08a8f6446ac9aca9ffcc 100644 --- a/src/core/agent_map.c +++ b/src/core/agent_map.c @@ -3051,7 +3051,7 @@ int handle_channel_scan_request(void *agent, struct cmdu_cstruct *cmdu) int channel_index; struct cmdu_cstruct *cmdu_copy = NULL; - uint8_t *ss = NULL; // binary cmdu->tlvs + uint8_t *ss = NULL; // binary cmdu->tlvs /* do c-style comments (like this) */ char *tlv_str = NULL; // string cmdu->tlvs uint8_t *tlvs = NULL; // binary resulting tlvs char *endtlvstr = NULL; // end_of_mes tlv string @@ -3064,7 +3064,7 @@ int handle_channel_scan_request(void *agent, struct cmdu_cstruct *cmdu) len = 0; ss = map_put_tlv_cstruct(cmdu->tlvs[it], &len); if (ss) { - tlv_str = (char *)calloc((2 * len) + 1, + tlv_str = (char *)calloc((2 * len) + 1, /* dangerous to do allocations inside a loop, can extract_tlv_by_type be used instead of the loop? */ sizeof(char)); if (!tlv_str) { dbg("|%s:%d| out of memory!\n", __func__, __LINE__); @@ -3077,7 +3077,7 @@ int handle_channel_scan_request(void *agent, struct cmdu_cstruct *cmdu) } // End of message tlv - endtlvstr = calloc(7, 1); + endtlvstr = calloc(7, 1); // use static buffer if (!endtlvstr) { dbg("|%s:%d| out of memory!\n", __func__, __LINE__); free(tlv_str); @@ -3086,9 +3086,9 @@ int handle_channel_scan_request(void *agent, struct cmdu_cstruct *cmdu) } endtlvstr = "000000"; - // Append the cmdu->tlvs string with end of message tlv + // Append the cmdu->tlvs string with end of message tlv /* c-style comments */ // Get resulting tlvs string - const size_t len1 = strlen(tlv_str); + const size_t len1 = strlen(tlv_str); /* don't define variables in the middle of the code, always top of scope */ const size_t len2 = strlen(endtlvstr); restlvstr = malloc(len1 + len2 + 1); if (!restlvstr) { @@ -3099,7 +3099,7 @@ int handle_channel_scan_request(void *agent, struct cmdu_cstruct *cmdu) return 0; } memcpy(restlvstr, tlv_str, len1); - memcpy(restlvstr + len1, endtlvstr, len2 + 1); + memcpy(restlvstr + len1, endtlvstr, len2 + 1); // possibly easier to just do memcpy right away for this rather than string handling? // Resulting tlvs string to binary value leng = len1 + len2; @@ -3122,7 +3122,7 @@ int handle_channel_scan_request(void *agent, struct cmdu_cstruct *cmdu) fprintf(stderr, "agent: %s: map_build_cmdu() successful!\n", __func__); } else { fprintf(stderr, "agent: %s: map_build_cmdu() failed!\n", __func__); - free(tlv_str); + free(tlv_str); // use a goto out_copy; (and for all the above as well) will make this be cleaner and more readable free(ss); free(endtlvstr); free(restlvstr); @@ -3132,8 +3132,8 @@ int handle_channel_scan_request(void *agent, struct cmdu_cstruct *cmdu) // Saving the cmdu with the agent a->req_channel_scan_cmdu = cmdu_copy; - cmdu_copy = NULL; - fprintf(stderr, "DONE ADDING CMDU TO AGENT\n"); + cmdu_copy = NULL; // don't need to set it to NULL + fprintf(stderr, "DONE ADDING CMDU TO AGENT\n"); // dont use fprint dbg("\n%s L-%d | cmdu mid: %d\n", __func__, __LINE__, a->req_channel_scan_cmdu->message_id); dbg("%s L-%d | cmdu typs: %s\n", __func__, @@ -3145,7 +3145,7 @@ int handle_channel_scan_request(void *agent, struct cmdu_cstruct *cmdu) uint8_t *tmp = NULL; tmp = cmdu->tlvs[0]; - if (*tmp != MAP_TLV_CHANNEL_SCAN_REQ) { + if (*tmp != MAP_TLV_CHANNEL_SCAN_REQ) { /* probably should be done earlier? */ dbg("Wrong received TLV type!\n"); return -1; } @@ -3161,11 +3161,14 @@ int handle_channel_scan_request(void *agent, struct cmdu_cstruct *cmdu) radio_name = wifi_get_radio_by_mac(a, query->radio_data[i].radio_id); if (!radio_name) continue; + snprintf(r_objname, 31, r_fmt, radio_name); //a->radios[ri].name r_wobj = ubus_get_object(a->ubus_ctx, r_objname); if (r_wobj == WIFI_OBJECT_INVALID) continue; + ri = wifi_get_radio_index_by_mac(a, query->radio_data[i].radio_id); + // ubus call wifi.radio.wl0 scan free_scanresults_neighbors(&a->radios[ri]); ubus_call_object(a, r_wobj, "scan", NULL, &a->radios[ri]); @@ -3209,11 +3212,11 @@ int handle_wifi_radio_scan_finished(void *agent) struct tlv_ch_scan_req *query = (struct tlv_ch_scan_req *)tmp; // Response only when all channels are scanned - if (all_channel_scanned(a, query)) { + if (all_channel_scanned(a, query)) { // better to do !all_channel_scanned; return; to reduce indentation dbg("All radios have been scanned!\n"); // Parse channel scanresults - char r_objname[32] = {0}; + char r_objname[32] = {0}; // define variables at top of scope const char *r_fmt = "wifi.radio.%s"; char *radio_name; wifi_object_t r_wobj = WIFI_OBJECT_INVALID; @@ -3227,6 +3230,7 @@ int handle_wifi_radio_scan_finished(void *agent) trace("...done scanning radio %s neighbors.\n", wifi_get_radio_by_mac(a, query->radio_data[i].radio_id)); // ubus call wifi.radio.wl0 scanresults ubus_call_object(a, r_wobj, "scanresults", parse_scanresults, &a->radios[ri]); + a->radios[ri].scanned = false; // need to reset scanned state } // Allocate the cmdu @@ -3328,6 +3332,7 @@ found: ret = agent_send_cmdu(a, cmdu_data); map_free_cmdu(cmdu_data); map_free_cmdu(a->req_channel_scan_cmdu); + // possibly a good idea to set set a->req_channel_scan_cmdu = NULL? return ret; } dbg("Not all radios have been scanned.\n");