diff --git a/src/core/agent.c b/src/core/agent.c index ada6ba07bd35ac074e62e1ba2e0e4c137b63b98f..3867264fd62bfd72e50d666bed150375ed006e53 100644 --- a/src/core/agent.c +++ b/src/core/agent.c @@ -1939,8 +1939,6 @@ static void wifi_bsta_event_handler(void *c, struct blob_attr *msg) } if (add) { - struct cmdu_cstruct *autoconfig_cmdu; - bk->connected = true; if (!a->configured) { time(&a->autocfg); @@ -3194,6 +3192,10 @@ static void agent_steering_opp_timeout(struct uloop_timeout *t) //src and interface to which the message needs to be sent strcpy(ifname, "lo"); +#if 0 // TODO: needs to be enabled for proper DUT behavior + strncpy(ifname, "br-lan"); + mempcy(origin, a->cntlr_almac, 6); +#endif send_sta_steer_complete((void *)a, origin, ifname); } @@ -3314,7 +3316,6 @@ void clear_fhlist(struct agent *a) int start_agent(void) { - struct cmdu_cstruct *autoconfig_cmdu; struct agent *w; struct ubus_context *ctx; pthread_t tid[1]; @@ -3419,9 +3420,6 @@ int start_agent(void) w->sta_steerlist_count = 0; w->sta_steer_req_timer.cb = agent_steering_opp_timeout; - autoconfig_cmdu = agent_gen_ap_autoconfig_search(w, - MULTICAST_ADDR_HEX, NULL, 0x02); - agent_add_cmdu(w, autoconfig_cmdu); time(&w->autocfg); uloop_timeout_set(&w->autocfg_dispatcher, 2 * 1000); // 2 seconds diff --git a/src/core/agent.h b/src/core/agent.h index fc81cdd4552868066e20422c16c0aeeaf7897d5b..52777a40da848ec3a245ff505ee8b911072d6cee 100644 --- a/src/core/agent.h +++ b/src/core/agent.h @@ -16,7 +16,7 @@ // TODO: TODO: fixme: remove this include //#include <ieee1905/1905_tlvs.h> -#define MAX_STA 20 +#define MAX_STA 32 typedef char timestamp_t[32]; /* defined in agent/main.c */ @@ -384,8 +384,6 @@ struct wifi_sta_steer_list { uint8_t complete; }; -#define CMDU_QUEUE_MAX 8 - /** struct agent - wifi agent */ struct agent { int debug; @@ -395,7 +393,6 @@ struct agent { bool configured; time_t autocfg; struct uloop_timeout autocfg_dispatcher; - struct cmdu_cstruct *cmdu_queue[CMDU_QUEUE_MAX]; struct list_head fhlist; struct list_head bklist; struct list_head framelist; diff --git a/src/core/agent_map.c b/src/core/agent_map.c index 691e3273ee4de3fe70c10516165fcf41ba4e3af9..9ce0176f457a13be512d18d8ff0bf3b7974e1d1b 100644 --- a/src/core/agent_map.c +++ b/src/core/agent_map.c @@ -58,7 +58,7 @@ #define UBUS_TIMEOUT 1000 #define MAX_RADIO 20 -#define MAX_STA 30 + struct channel_response { uint8_t radio_id[6]; uint8_t response; @@ -85,6 +85,8 @@ typedef int (*map_cmdu_handler_t)(void *agent, struct cmdu_cstruct *cmdu); typedef int (*map_cmdu_sendfunc_t)(void *agent, struct cmdu_cstruct *cmdu); int agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu); +int agent_transition_sta(struct agent *a, struct tlv_steer_Req *p, struct netif_fh *fh, + int l, int m); uint8_t *extract_tlv_by_type(struct cmdu_cstruct *cmdu, uint8_t tlv_type) { @@ -279,6 +281,44 @@ int send_oper_channel_report(void *agent, struct cmdu_cstruct *rec_cmdu) return ret; } +int send_sta_steer_complete(void *agent, uint8_t *origin, const char *intf_name) +{ + trace("agent: %s: --->\n", __func__); + struct agent *a = (struct agent *) agent; + struct cmdu_cstruct *cmdu_data; + int ret = 0; + + cmdu_data = (struct cmdu_cstruct *)calloc(1, + sizeof(struct cmdu_cstruct)); + if (!cmdu_data) { + fprintf(stderr, "Out of memory!\n"); + return -1; + } + + cmdu_data->message_type = CMDU_STEERING_COMPLETED; + memcpy(cmdu_data->origin, origin, 6); + //cmdu_data->message_id = 19; + strcpy(cmdu_data->intf_name, intf_name); + + cmdu_data->num_tlvs = 0; /* (No TLVs) */ + if (a->is_sta_steer_start) { + /** + * Here we are sending the steering completed message + * so we need to reset all the values of the + * steering opportunity + */ + a->is_sta_steer_start = 0; + a->sta_steerlist_count = 0; + memset(a->sta_steer_list, 0, sizeof(a->sta_steer_list)); + /* stop the timer if it is running */ + uloop_timeout_cancel(&a->sta_steer_req_timer); + } + + agent_send_cmdu(a, cmdu_data); + map_free_cmdu(cmdu_data); + return ret; +} + int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name, uint8_t *target_bssid, uint8_t *src_bssid, uint8_t *sta, uint8_t status_code) @@ -287,7 +327,6 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name, trace("agent: %s: --->\n", __func__); struct agent *a = (struct agent *) agent; uint16_t tlv_index = 0; - uint32_t j; struct cmdu_cstruct *cmdu_data; int ret = 0, all_complete = 1; @@ -393,46 +432,6 @@ int send_beacon_metrics_response(void *agent, struct cmdu_cstruct *cmdu) return 0; } -int send_sta_steer_complete(void *agent, uint8_t *origin, const char *intf_name) -{ - trace("agent: %s: --->\n", __func__); - struct agent *a = (struct agent *) agent; - uint16_t tlv_index = 0; - uint32_t j; - struct cmdu_cstruct *cmdu_data; - int ret = 0, res = 0, i = 0; - - cmdu_data = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - if (!cmdu_data) { - fprintf(stderr, "Out of memory!\n"); - return -1; - } - - cmdu_data->message_type = CMDU_STEERING_COMPLETED; - memcpy(cmdu_data->origin, origin, 6); - //cmdu_data->message_id = 19; - strcpy(cmdu_data->intf_name, intf_name); - - cmdu_data->num_tlvs = 0; /* (No TLVs) */ - if (a->is_sta_steer_start) { - /** - * Here we are sending the steering completed message - * so we need to reset all the values of the - * steering opportunity - */ - a->is_sta_steer_start = 0; - a->sta_steerlist_count = 0; - memset(a->sta_steer_list, 0, sizeof(a->sta_steer_list)); - /* stop the timer if it is running */ - uloop_timeout_cancel(&a->sta_steer_req_timer); - } - - agent_send_cmdu(a, cmdu_data); - map_free_cmdu(cmdu_data); - return ret; -} - int send_backhaul_sta_steer_response(void *agent, struct cmdu_cstruct *cmdu) { return 0; @@ -1537,46 +1536,16 @@ int handle_combined_infra_metrics(void *agent, struct cmdu_cstruct *cmdu) return 0; } -int handle_sta_steer_request(void *agent, struct cmdu_cstruct *cmdu) +/* Add the rcpi based check according to section + * 11.3 + */ +bool agent_rcpi_steer(void) { - trace("%s: --->\n", __func__); - struct agent *a = (struct agent *) agent; - int ret = 0; - struct channel_response channel_resp[MAX_RADIO]; - uint32_t channel_resp_nr = 0, match = 0, found = 0; - int i, j, k, l, m; - uint8_t *tlv = NULL; - struct wifi_radio_element *radio; - uint32_t pref_tlv_present = 0; - - /* Here we first parse the steer request */ - if (cmdu->num_tlvs != 0) { - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *) cmdu->tlvs[i]; - switch (*tlv) { - case MAP_TLV_STEERING_REQUEST: - { - struct tlv_steer_Req *p = - (struct tlv_steer_Req *)tlv; - - ret = agent_process_steer_request_tlv(agent, - p, cmdu); - } -//#ifdef profile2 - case MAP_TLV_PROFILE2_STEERING_REQ: - { - //TODO here we need to call the request transmission for the - //STAs are Agile Multiband capable - struct tlv_profile2_steer_req *p = - (struct tlv_profile2_steer_req *)tlv; - } -//#endif - default: - break; - } - } - } - return ret; + /** + * TODO: Implement proper logic to trigger steer + */ + trace("agent: %s: --->\n", __func__); + return false; } int validate_sta_bssid_assoc(struct netif_fh *fh, struct tlv_steer_Req *p, @@ -1618,54 +1587,120 @@ int validate_sta_bssid_assoc(struct netif_fh *fh, struct tlv_steer_Req *p, return 0; } -int agent_transition_sta(struct agent *a, struct tlv_steer_Req *p, struct netif_fh *fh, - int l, int m) +int agent_send_request_transition(void *agent, uint8_t *client_sta, + struct netif_fh *fh, uint8_t *bssid, uint32_t timeout) { - uint8_t wildcard[6]; - uint8_t wildcard_bssid[6]; - int result = 0; - char wildcard_str[18] = { 0x0 }; + struct agent *a = (struct agent *) agent; + char client_macstr[18] = { 0 }; + char bssid_str[18] = { 0 }; + struct blob_buf bb = { 0 }; int ret = 0; + void *tbl; trace("agent: %s: --->\n", __func__); - snprintf(wildcard_str, 18, "FF:FF:FF:FF:FF:FF"); - hwaddr_aton(wildcard_str, wildcard); + if (!client_sta || !bssid) + return -1; - result = memcmp(p->steering_req_target_bssids[l].bssid, wildcard, 6); - if (result == 0) { - /** - * code to search bssid as the bssid is a - * wildcard - */ - trace("[%s:%d] bssid id wildcard\n", - __func__, __LINE__); - ret = agent_search_bssid_for_sta(a, - p->steering_req_macs[l].addr, - wildcard_bssid, p->bssid); - if (ret == 0) - ret = agent_send_request_transition(a, - p->steering_req_macs[l].addr, - fh, wildcard_bssid, 0); - } else { - ret = agent_send_request_transition(a, - p->steering_req_macs[l].addr, - fh, p->steering_req_target_bssids[m].bssid, 0); + blob_buf_init(&bb, 0); + + hwaddr_ntoa(client_sta, client_macstr); + blobmsg_add_string(&bb, "client", client_macstr); + + hwaddr_ntoa(bssid, bssid_str); + tbl = blobmsg_open_array(&bb, "bssid"); + blobmsg_add_string(&bb, NULL, bssid_str); + blobmsg_close_table(&bb, tbl); + + if (timeout) { + //fill the timeout } - return 0; + + ret = ubus_invoke(a->ubus_ctx, fh->wifi, "request_transition", bb.head, + NULL, NULL, UBUS_TIMEOUT); + if (ret) { + trace("[%s:%d] ubus call failed for |wifi.ap. send|", + __func__, __LINE__); + goto out; + } + +out: + blob_buf_free(&bb); + return ret; } -/* Add the rcpi based check according to section - * 11.3 - */ -bool agent_rcpi_steer(void) +//TODO search BSSID incase of wildcard or in case need to get the +//implementation specific policy section 11.4 +int agent_search_bssid_for_sta(struct agent *a, uint8_t *sta, uint8_t *bssid, + uint8_t *src_bssid) { - /** - * TODO: Implement proper logic to trigger steer - */ + + struct netif_fh *p; + int ret = 0; + trace("agent: %s: --->\n", __func__); - return false; + list_for_each_entry(p, &a->fhlist, list) { + trace("bssid = " MACFMT " pbssid = " MACFMT "\n", + MAC2STR(bssid), MAC2STR(p->bssid)); + ret = memcmp(src_bssid, p->bssid, 6); + if (ret != 0) { + memcpy(bssid, p->bssid, 6); + return 0; + } + } + memcpy(bssid, src_bssid, 6); + return 0; } +int send_1905_acknowledge(void *agent, + struct cmdu_cstruct *rec_cmdu, + struct sta_error_response *sta_resp, uint32_t sta_count) +{ + struct agent *a = (struct agent *) agent; + uint16_t tlv_index = 0; + uint32_t j; + struct cmdu_cstruct *cmdu_data; + int ret = 0; + + trace("agent: %s: --->\n", __func__); + cmdu_data = (struct cmdu_cstruct *)calloc(1, + sizeof(struct cmdu_cstruct)); + + if (!cmdu_data) { + fprintf(stderr, "Out of memory!\n"); + return -1; + } + + cmdu_data->message_type = CMDU_1905_ACK; + memcpy(cmdu_data->origin, rec_cmdu->origin, 6); + //cmdu_data->message_id = 11; + strcpy(cmdu_data->intf_name, rec_cmdu->intf_name); + + cmdu_data->num_tlvs = sta_count; /* (TLV for error) */ + cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, + sizeof(uint8_t *)); + + if (!cmdu_data->tlvs) { + map_free_cmdu(cmdu_data); + return -1; + } + + /* Error Code TLV 17.2.36 */ + for (j = 0; j < sta_count; j++) { + struct tlv_error_code *p = NULL; + /** + * Here we need to check that the sta error + * response + */ + p = agent_gen_tlv_error_code(a, rec_cmdu, + sta_resp[j].sta_mac, sta_resp[j].response); + if (!p) + continue; + cmdu_data->tlvs[tlv_index++] = (uint8_t *)p; + } + ret = agent_send_cmdu(a, cmdu_data); + map_free_cmdu(cmdu_data); + return ret; +} int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, struct cmdu_cstruct *cmdu) @@ -1673,8 +1708,7 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, trace("agent: %s: --->\n", __func__); struct agent *a = (struct agent *) agent; int ret = 0, result = 0; - uint32_t match = 0, found = 0; - int i, j, k, l, m; + int l, m; struct netif_fh *fh; struct sta *s; struct sta_error_response sta_resp[MAX_STA]; @@ -1902,127 +1936,87 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, } send_ack: - send_1905_acknowledge(agent, p, cmdu, sta_resp, count); + send_1905_acknowledge(agent, cmdu, sta_resp, count); return ret; } -//TODO search BSSID incase of wildcard or in case need to get the -//implementation specific policy section 11.4 -int agent_search_bssid_for_sta(struct agent *a, uint8_t *sta, uint8_t *bssid, - uint8_t *src_bssid) +int handle_sta_steer_request(void *agent, struct cmdu_cstruct *cmdu) { - - struct netif_fh *p; + trace("%s: --->\n", __func__); + struct agent *a = (struct agent *) agent; int ret = 0; + int i; + uint8_t *tlv = NULL; - trace("agent: %s: --->\n", __func__); - list_for_each_entry(p, &a->fhlist, list) { - trace("bssid = " MACFMT " pbssid = " MACFMT "\n", - MAC2STR(bssid), MAC2STR(p->bssid)); - ret = memcmp(src_bssid, p->bssid, 6); - if (ret != 0) { - memcpy(bssid, p->bssid, 6); - return 0; + /* Here we first parse the steer request */ + if (cmdu->num_tlvs != 0) { + for (i = 0; i < cmdu->num_tlvs; i++) { + tlv = (uint8_t *) cmdu->tlvs[i]; + switch (*tlv) { + case MAP_TLV_STEERING_REQUEST: + { + struct tlv_steer_Req *p = + (struct tlv_steer_Req *)tlv; + + ret = agent_process_steer_request_tlv(agent, + p, cmdu); + break; + } +//#ifdef profile2 + case MAP_TLV_PROFILE2_STEERING_REQ: + { + //TODO here we need to call the request transmission for the + //STAs are Agile Multiband capable + struct tlv_profile2_steer_req *p = + (struct tlv_profile2_steer_req *)tlv; + + break; + } +//#endif + default: + break; + } } } - memcpy(bssid, src_bssid, 6); - return 0; + return ret; } -int send_1905_acknowledge(void *agent, struct tlv_error_code *p, - struct cmdu_cstruct *rec_cmdu, - struct sta_error_response *sta_resp, uint32_t sta_count) +int agent_transition_sta(struct agent *a, struct tlv_steer_Req *p, struct netif_fh *fh, + int l, int m) { - struct agent *a = (struct agent *) agent; - uint16_t tlv_index = 0; - uint32_t j; - struct cmdu_cstruct *cmdu_data; + uint8_t wildcard[6]; + uint8_t wildcard_bssid[6]; + int result = 0; + char wildcard_str[18] = { 0x0 }; int ret = 0; trace("agent: %s: --->\n", __func__); - cmdu_data = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - - if (!cmdu_data) { - fprintf(stderr, "Out of memory!\n"); - return -1; - } - - cmdu_data->message_type = CMDU_1905_ACK; - memcpy(cmdu_data->origin, rec_cmdu->origin, 6); - //cmdu_data->message_id = 11; - strcpy(cmdu_data->intf_name, rec_cmdu->intf_name); - - cmdu_data->num_tlvs = sta_count; /* (TLV for error) */ - cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, - sizeof(uint8_t *)); - - if (!cmdu_data->tlvs) { - map_free_cmdu(cmdu_data); - return -1; - } + snprintf(wildcard_str, 18, "FF:FF:FF:FF:FF:FF"); + hwaddr_aton(wildcard_str, wildcard); - /* Error Code TLV 17.2.36 */ - for (j = 0; j < sta_count; j++) { - struct tlv_error_code *p = NULL; + result = memcmp(p->steering_req_target_bssids[l].bssid, wildcard, 6); + if (result == 0) { /** - * Here we need to check that the sta error - * response + * code to search bssid as the bssid is a + * wildcard */ - p = agent_gen_tlv_error_code(a, rec_cmdu, - sta_resp[j].sta_mac, sta_resp[j].response); - if (!p) - continue; - cmdu_data->tlvs[tlv_index++] = (uint8_t *)p; + trace("[%s:%d] bssid id wildcard\n", + __func__, __LINE__); + ret = agent_search_bssid_for_sta(a, + p->steering_req_macs[l].addr, + wildcard_bssid, p->bssid); + if (ret == 0) + ret = agent_send_request_transition(a, + p->steering_req_macs[l].addr, + fh, wildcard_bssid, 0); + } else { + ret = agent_send_request_transition(a, + p->steering_req_macs[l].addr, + fh, p->steering_req_target_bssids[m].bssid, 0); } - ret = agent_send_cmdu(a, cmdu_data); - map_free_cmdu(cmdu_data); return 0; } -int agent_send_request_transition(void *agent, uint8_t *client_sta, - struct netif_fh *fh, uint8_t *bssid, uint32_t timeout) -{ - struct agent *a = (struct agent *) agent; - char client_macstr[18] = { 0 }; - char bssid_str[18] = { 0 }; - struct blob_buf bb = { 0 }; - int ret = 0; - uint32_t id; - char ap_ifname[30] = { 0 }; - void *tbl; - - trace("agent: %s: --->\n", __func__); - if (!client_sta || !bssid) - return -1; - - blob_buf_init(&bb, 0); - - hwaddr_ntoa(client_sta, client_macstr); - blobmsg_add_string(&bb, "client", client_macstr); - - hwaddr_ntoa(bssid, bssid_str); - tbl = blobmsg_open_array(&bb, "bssid"); - blobmsg_add_string(&bb, NULL, bssid_str); - blobmsg_close_table(&bb, tbl); - - if (timeout) { - //fill the timeout - } - - ret = ubus_invoke(a->ubus_ctx, fh->wifi, "request_transition", bb.head, - NULL, NULL, UBUS_TIMEOUT); - if (ret) { - trace("[%s:%d] ubus call failed for |wifi.ap. send|", - __func__, __LINE__); - goto out; - } - -out: - blob_buf_free(&bb); - return ret; -} - int handle_sta_assoc_control_request(void *agent, struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); diff --git a/src/core/agent_map.h b/src/core/agent_map.h index da3d23a6eead46ecc95f4a7dcffc3618287d9d4d..25507baa75bb336bc89e5d80aae0011fce098063 100644 --- a/src/core/agent_map.h +++ b/src/core/agent_map.h @@ -23,6 +23,9 @@ int agent_fill_radio_max_preference(void *agent, int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p, struct channel_response *channel_resp, uint32_t *channel_response_nr); - +int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name, + uint8_t *target_bssid, uint8_t *src_bssid, + uint8_t *sta, uint8_t status_code); +int send_sta_steer_complete(void *agent, uint8_t *origin, const char *intf_name); #endif /* AGENT_MAP_H */ diff --git a/src/core/agent_ubus.c b/src/core/agent_ubus.c index fe16d6eb53d68d072c7f74060affffb5f082e5d2..b73727061d5e078c7697b49de5993faa724bc49b 100644 --- a/src/core/agent_ubus.c +++ b/src/core/agent_ubus.c @@ -31,6 +31,7 @@ #include "agent.h" #include "agent_map.h" #include "agent_ubus.h" +#include "agent_cmdu_generator.h" #define OBJECT_INVALID ((uint32_t)-1) @@ -416,7 +417,7 @@ static int agent_ap_search(struct ubus_context *ctx, struct ubus_object *obj, { struct agent *a = container_of(obj, struct agent, obj); struct blob_attr *tb[__SEARCH_POLICY_MAX]; - int i, tlv_index = 0, band, ieee1905band; + int i, band = 0; blobmsg_parse(search_policy_params, __SEARCH_POLICY_MAX, tb, blob_data(msg), blob_len(msg));