Skip to content
Snippets Groups Projects
Commit 6de0862d authored by Ozan Tanfener's avatar Ozan Tanfener Committed by Jakob Olsson
Browse files

map-agent: module test PoC

parent fc8f41b3
Branches mem-mgmt
No related tags found
No related merge requests found
EXECS = mapagent EXECS = mapagent
CFLAGS+=-I. -Iinclude -Iutils -Icore -Iipc -D_GNU_SOURCE CFLAGS+=-I. -Iinclude -Iutils -Icore -Iipc -D_GNU_SOURCE
CFLAGS+="-I/usr/include/libnl3"
CFLAGS+= -g -Wall CFLAGS+= -g -Wall
OBJS = \ OBJS = \
... ...
......
...@@ -2972,11 +2972,14 @@ static void parse_radio(struct ubus_request *req, int type, ...@@ -2972,11 +2972,14 @@ static void parse_radio(struct ubus_request *req, int type,
re->current_txpower_percent = (uint8_t) blobmsg_get_u32(tb[9]); re->current_txpower_percent = (uint8_t) blobmsg_get_u32(tb[9]);
if (tb[10]) { if (tb[10]) {
// TODO: uncomment when radio mac is fixed in wifimngr test suite
char macaddr[18] = {0}; char macaddr[18] = {0};
strncpy(macaddr, blobmsg_data(tb[10]), 17); re->macaddr[5] = atoi(re->name+4);
if (!hwaddr_aton(macaddr, re->macaddr))
return; //strncpy(macaddr, blobmsg_data(tb[10]), 17);
//if (!hwaddr_aton(macaddr, re->macaddr))
// return;
} }
} }
... ...
......
...@@ -64,12 +64,14 @@ ...@@ -64,12 +64,14 @@
#define MAX_RADIO 20 #define MAX_RADIO 20
struct channel_response { struct channel_response
{
uint8_t radio_id[6]; uint8_t radio_id[6];
uint8_t response; uint8_t response;
}; };
struct sta_error_response { struct sta_error_response
{
uint8_t sta_mac[6]; uint8_t sta_mac[6];
uint8_t response; uint8_t response;
}; };
...@@ -79,13 +81,13 @@ for ((e) = (struct tlv *)(_buf); \ ...@@ -79,13 +81,13 @@ for ((e) = (struct tlv *)(_buf); \
(e)->len && (_buf) + (_len) - (uint8_t *)(e)-3 - (e)->len >= 0; \ (e)->len && (_buf) + (_len) - (uint8_t *)(e)-3 - (e)->len >= 0; \
(e) = (struct tlv *)(_buf + 3 + (e)->len)) (e) = (struct tlv *)(_buf + 3 + (e)->len))
struct tlv { struct tlv
{
uint8_t type; uint8_t type;
uint16_t len; uint16_t len;
uint8_t value[]; uint8_t value[];
} __attribute__((packed)); } __attribute__((packed));
typedef int (*map_cmdu_handler_t)(void *agent, struct cmdu_cstruct *cmdu); typedef int (*map_cmdu_handler_t)(void *agent, struct cmdu_cstruct *cmdu);
typedef int (*map_cmdu_sendfunc_t)(void *agent, struct cmdu_cstruct *cmdu); typedef int (*map_cmdu_sendfunc_t)(void *agent, struct cmdu_cstruct *cmdu);
...@@ -98,14 +100,14 @@ uint8_t *extract_tlv_by_type(struct cmdu_cstruct *cmdu, uint8_t tlv_type) ...@@ -98,14 +100,14 @@ uint8_t *extract_tlv_by_type(struct cmdu_cstruct *cmdu, uint8_t tlv_type)
uint8_t *tlv; uint8_t *tlv;
int i; int i;
for (i = 0; i < cmdu->num_tlvs; i++) { for (i = 0; i < cmdu->num_tlvs; i++)
{
tlv = cmdu->tlvs[i]; tlv = cmdu->tlvs[i];
if (*tlv == tlv_type) if (*tlv == tlv_type)
return tlv; return tlv;
} }
return NULL; return NULL;
} }
/* lookup netif struct by bssid */ /* lookup netif struct by bssid */
...@@ -113,7 +115,8 @@ static struct netif_fh *get_netif_by_bssid(struct agent *a, uint8_t *bssid) ...@@ -113,7 +115,8 @@ static struct netif_fh *get_netif_by_bssid(struct agent *a, uint8_t *bssid)
{ {
struct netif_fh *p; struct netif_fh *p;
list_for_each_entry(p, &a->fhlist, list) { list_for_each_entry(p, &a->fhlist, list)
{
trace("bssid = " MACFMT " pbssid = " MACFMT "\n", trace("bssid = " MACFMT " pbssid = " MACFMT "\n",
MAC2STR(bssid), MAC2STR(p->bssid)); MAC2STR(bssid), MAC2STR(p->bssid));
if (!memcmp(bssid, p->bssid, 6)) if (!memcmp(bssid, p->bssid, 6))
...@@ -139,7 +142,8 @@ int build_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *rec_cmdu, ...@@ -139,7 +142,8 @@ int build_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *rec_cmdu,
// return -1; // return -1;
cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct));
if (!cmdu) { if (!cmdu)
{
fprintf(stderr, "failed to malloc cmdu\n"); fprintf(stderr, "failed to malloc cmdu\n");
return -1; return -1;
} }
...@@ -252,7 +256,8 @@ int send_oper_channel_report(void *agent, struct cmdu_cstruct *rec_cmdu) ...@@ -252,7 +256,8 @@ int send_oper_channel_report(void *agent, struct cmdu_cstruct *rec_cmdu)
cmdu_data = (struct cmdu_cstruct *)calloc(1, cmdu_data = (struct cmdu_cstruct *)calloc(1,
sizeof(struct cmdu_cstruct)); sizeof(struct cmdu_cstruct));
if (!cmdu_data) { if (!cmdu_data)
{
fprintf(stderr, "Out of memory!\n"); fprintf(stderr, "Out of memory!\n");
return -1; return -1;
} }
...@@ -265,13 +270,15 @@ int send_oper_channel_report(void *agent, struct cmdu_cstruct *rec_cmdu) ...@@ -265,13 +270,15 @@ int send_oper_channel_report(void *agent, struct cmdu_cstruct *rec_cmdu)
cmdu_data->num_tlvs = 1 * a->num_radios; /* (Operating Channel report) */ cmdu_data->num_tlvs = 1 * a->num_radios; /* (Operating Channel report) */
cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs,
sizeof(uint8_t *)); sizeof(uint8_t *));
if (!cmdu_data->tlvs) { if (!cmdu_data->tlvs)
{
map_free_cmdu(cmdu_data); map_free_cmdu(cmdu_data);
return -1; return -1;
} }
/* Operating Channel Report TLV 17.2.17 */ /* Operating Channel Report TLV 17.2.17 */
for (j = 0; j < a->num_radios; j++) { for (j = 0; j < a->num_radios; j++)
{
struct tlv_oper_ch_report *p = struct tlv_oper_ch_report *p =
p = agent_gen_operate_channel_report(a, rec_cmdu, j); p = agent_gen_operate_channel_report(a, rec_cmdu, j);
if (!p) if (!p)
...@@ -294,7 +301,8 @@ int send_sta_steer_complete(void *agent, uint8_t *origin, const char *intf_name) ...@@ -294,7 +301,8 @@ int send_sta_steer_complete(void *agent, uint8_t *origin, const char *intf_name)
cmdu_data = (struct cmdu_cstruct *)calloc(1, cmdu_data = (struct cmdu_cstruct *)calloc(1,
sizeof(struct cmdu_cstruct)); sizeof(struct cmdu_cstruct));
if (!cmdu_data) { if (!cmdu_data)
{
fprintf(stderr, "Out of memory!\n"); fprintf(stderr, "Out of memory!\n");
return -1; return -1;
} }
...@@ -305,7 +313,8 @@ int send_sta_steer_complete(void *agent, uint8_t *origin, const char *intf_name) ...@@ -305,7 +313,8 @@ int send_sta_steer_complete(void *agent, uint8_t *origin, const char *intf_name)
strcpy(cmdu_data->intf_name, intf_name); strcpy(cmdu_data->intf_name, intf_name);
cmdu_data->num_tlvs = 0; /* (No TLVs) */ cmdu_data->num_tlvs = 0; /* (No TLVs) */
if (a->is_sta_steer_start) { if (a->is_sta_steer_start)
{
/** /**
* Here we are sending the steering completed message * Here we are sending the steering completed message
* so we need to reset all the values of the * so we need to reset all the values of the
...@@ -337,7 +346,8 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name, ...@@ -337,7 +346,8 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name,
cmdu_data = (struct cmdu_cstruct *)calloc(1, cmdu_data = (struct cmdu_cstruct *)calloc(1,
sizeof(struct cmdu_cstruct)); sizeof(struct cmdu_cstruct));
if (!cmdu_data) { if (!cmdu_data)
{
fprintf(stderr, "Out of memory!\n"); fprintf(stderr, "Out of memory!\n");
return -1; return -1;
} }
...@@ -351,7 +361,8 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name, ...@@ -351,7 +361,8 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name,
cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs,
sizeof(uint8_t *)); sizeof(uint8_t *));
if (!cmdu_data->tlvs) { if (!cmdu_data->tlvs)
{
map_free_cmdu(cmdu_data); map_free_cmdu(cmdu_data);
return -1; return -1;
} }
...@@ -360,7 +371,8 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name, ...@@ -360,7 +371,8 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name,
struct tlv_steer_btm_report *p = struct tlv_steer_btm_report *p =
p = agent_gen_steer_btm_report(a, target_bssid, p = agent_gen_steer_btm_report(a, target_bssid,
src_bssid, sta, status_code); src_bssid, sta, status_code);
if (!p) { if (!p)
{
map_free_cmdu(cmdu_data); map_free_cmdu(cmdu_data);
return -1; return -1;
} }
...@@ -378,11 +390,13 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name, ...@@ -378,11 +390,13 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name,
* Here we store the status in the sta list and check * Here we store the status in the sta list and check
* if the steering completed message can be sent * if the steering completed message can be sent
*/ */
if (a->is_sta_steer_start) { if (a->is_sta_steer_start)
{
int i; int i;
/* iterate list of clients attempted to be steered */ /* iterate list of clients attempted to be steered */
for (i = 0; i < a->sta_steerlist_count; i++) { for (i = 0; i < a->sta_steerlist_count; i++)
{
/* mark all steered clients as completed */ /* mark all steered clients as completed */
ret = memcmp(sta, a->sta_steer_list[i].sta_mac, 6); ret = memcmp(sta, a->sta_steer_list[i].sta_mac, 6);
...@@ -394,14 +408,17 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name, ...@@ -394,14 +408,17 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name,
* Now we need to check if the steering completed * Now we need to check if the steering completed
* message can be sent * message can be sent
*/ */
for (i = 0; i < a->sta_steerlist_count; i++) { for (i = 0; i < a->sta_steerlist_count; i++)
if (a->sta_steer_list[i].complete != 1) { {
if (a->sta_steer_list[i].complete != 1)
{
all_complete = 0; all_complete = 0;
break; break;
} }
} }
if (all_complete) { if (all_complete)
{
/* Here we need to send the steering completed CMDU */ /* Here we need to send the steering completed CMDU */
send_sta_steer_complete(agent, origin, intf_name); send_sta_steer_complete(agent, origin, intf_name);
} }
...@@ -641,14 +658,17 @@ int handle_ap_autoconfig_response(void *agent, struct cmdu_cstruct *cmdu) ...@@ -641,14 +658,17 @@ int handle_ap_autoconfig_response(void *agent, struct cmdu_cstruct *cmdu)
if (!supp_serv) if (!supp_serv)
return -1; return -1;
for (i = 0; i < supp_serv->supported_services_list; i++) { for (i = 0; i < supp_serv->supported_services_list; i++)
if (supp_serv->supported_services[i].service == SUPPORTED_SERVICE_MULTIAP_CONTROLLER) { {
if (supp_serv->supported_services[i].service == SUPPORTED_SERVICE_MULTIAP_CONTROLLER)
{
cntlr = true; cntlr = true;
break; break;
} }
} }
if (!cntlr) { if (!cntlr)
{
trace("agent: Autoconfig response was not from controller\n"); trace("agent: Autoconfig response was not from controller\n");
return -1; return -1;
} }
...@@ -703,7 +723,8 @@ static struct wifi_radio_element *wifi_get_radio_by_mac(struct agent *a, ...@@ -703,7 +723,8 @@ static struct wifi_radio_element *wifi_get_radio_by_mac(struct agent *a,
struct wifi_radio_element *radio; struct wifi_radio_element *radio;
int i; int i;
for (i = 0; i < a->num_radios; i++) { for (i = 0; i < a->num_radios; i++)
{
radio = a->radios + i; radio = a->radios + i;
if (memcmp(radio->macaddr, hwaddr, 6)) if (memcmp(radio->macaddr, hwaddr, 6))
...@@ -720,7 +741,8 @@ struct netif_fh *wifi_get_netif_by_bssid(struct agent *a, uint8_t *bssid) ...@@ -720,7 +741,8 @@ struct netif_fh *wifi_get_netif_by_bssid(struct agent *a, uint8_t *bssid)
{ {
struct netif_fh *fh; struct netif_fh *fh;
list_for_each_entry(fh, &a->fhlist, list) { list_for_each_entry(fh, &a->fhlist, list)
{
if (hwaddr_equal(fh->bssid, bssid)) if (hwaddr_equal(fh->bssid, bssid))
return fh; return fh;
} }
...@@ -761,7 +783,8 @@ int wifi_teardown_map_ifaces_by_radio(struct agent *a, char *device) ...@@ -761,7 +783,8 @@ int wifi_teardown_map_ifaces_by_radio(struct agent *a, char *device)
struct netif_fhcfg *fh, *fh_tmp; struct netif_fhcfg *fh, *fh_tmp;
struct netif_bkcfg *bk, *bk_tmp; struct netif_bkcfg *bk, *bk_tmp;
list_for_each_entry_safe(fh, fh_tmp, &a->cfg.fhlist, list) { list_for_each_entry_safe(fh, fh_tmp, &a->cfg.fhlist, list)
{
if (strncmp(fh->device, device, sizeof(fh->device) - 1)) if (strncmp(fh->device, device, sizeof(fh->device) - 1))
continue; continue;
...@@ -778,7 +801,8 @@ int wifi_teardown_map_ifaces_by_band(struct agent *a, enum wifi_band band) ...@@ -778,7 +801,8 @@ int wifi_teardown_map_ifaces_by_band(struct agent *a, enum wifi_band band)
struct netif_fhcfg *fh, *fh_tmp; struct netif_fhcfg *fh, *fh_tmp;
struct netif_bkcfg *bk, *bk_tmp; struct netif_bkcfg *bk, *bk_tmp;
list_for_each_entry_safe(fh, fh_tmp, &a->cfg.fhlist, list) { list_for_each_entry_safe(fh, fh_tmp, &a->cfg.fhlist, list)
{
if (fh->band != band) if (fh->band != band)
continue; continue;
...@@ -795,15 +819,15 @@ int wifi_teardown_map_ifaces_by_band(struct agent *a, enum wifi_band band) ...@@ -795,15 +819,15 @@ int wifi_teardown_map_ifaces_by_band(struct agent *a, enum wifi_band band)
int check_wireless_ifname(struct agent *a, const char *device, int check_wireless_ifname(struct agent *a, const char *device,
const char *ifname) const char *ifname)
{ {
enum { enum
{
W_IFNAME, W_IFNAME,
W_DEV, W_DEV,
NUM_POLICIES NUM_POLICIES
}; };
const struct uci_parse_option opts[] = { const struct uci_parse_option opts[] = {
{.name = "ifname", .type = UCI_TYPE_STRING}, {.name = "ifname", .type = UCI_TYPE_STRING},
{ .name = "device", .type = UCI_TYPE_STRING } {.name = "device", .type = UCI_TYPE_STRING}};
};
struct uci_option *tb[NUM_POLICIES]; struct uci_option *tb[NUM_POLICIES];
struct uci_context *ctx; struct uci_context *ctx;
struct uci_package *pkg; struct uci_package *pkg;
...@@ -815,12 +839,14 @@ int check_wireless_ifname(struct agent *a, const char *device, ...@@ -815,12 +839,14 @@ int check_wireless_ifname(struct agent *a, const char *device,
if (!ctx) if (!ctx)
return -1; return -1;
if (uci_load(ctx, "wireless", &pkg)) { if (uci_load(ctx, "wireless", &pkg))
{
uci_free_context(ctx); uci_free_context(ctx);
return -1; return -1;
} }
uci_foreach_element(&pkg->sections, e) { uci_foreach_element(&pkg->sections, e)
{
struct uci_section *s = uci_to_section(e); struct uci_section *s = uci_to_section(e);
if (strncmp(s->type, "wifi-iface", strlen("wifi-iface"))) if (strncmp(s->type, "wifi-iface", strlen("wifi-iface")))
...@@ -828,7 +854,8 @@ int check_wireless_ifname(struct agent *a, const char *device, ...@@ -828,7 +854,8 @@ int check_wireless_ifname(struct agent *a, const char *device,
uci_parse_section(s, opts, NUM_POLICIES, tb); uci_parse_section(s, opts, NUM_POLICIES, tb);
if (tb[W_DEV]) { if (tb[W_DEV])
{
const char *cfg_dev; const char *cfg_dev;
cfg_dev = tb[W_DEV]->v.string; cfg_dev = tb[W_DEV]->v.string;
...@@ -837,16 +864,19 @@ int check_wireless_ifname(struct agent *a, const char *device, ...@@ -837,16 +864,19 @@ int check_wireless_ifname(struct agent *a, const char *device,
} }
/* TODO: should work with 16 instead of 4 */ /* TODO: should work with 16 instead of 4 */
if (num_ifs >= TMP_WIFI_IFACE_MAX_NUM) { if (num_ifs >= TMP_WIFI_IFACE_MAX_NUM)
{
rv = true; rv = true;
break; break;
} }
if (tb[W_IFNAME]) { if (tb[W_IFNAME])
{
char *cfg_ifname; char *cfg_ifname;
cfg_ifname = tb[W_IFNAME]->v.string; cfg_ifname = tb[W_IFNAME]->v.string;
if (!strncmp(cfg_ifname, ifname, IFNAMSIZ)) { if (!strncmp(cfg_ifname, ifname, IFNAMSIZ))
{
rv = true; rv = true;
break; break;
} }
...@@ -873,7 +903,8 @@ char *wifi_gen_first_ifname(struct agent *a, char *device, char *ifname) ...@@ -873,7 +903,8 @@ char *wifi_gen_first_ifname(struct agent *a, char *device, char *ifname)
* PLATFORM_COMPUTE_DH_SHARED_SECRET() (verified with i <= 8) * PLATFORM_COMPUTE_DH_SHARED_SECRET() (verified with i <= 8)
*/ */
/* TODO: should work with 16 instead of 4 */ /* TODO: should work with 16 instead of 4 */
for (i = 1; i <= TMP_WIFI_IFACE_MAX_NUM; i++) { for (i = 1; i <= TMP_WIFI_IFACE_MAX_NUM; i++)
{
if (!check_wireless_ifname(a, device, ifname)) if (!check_wireless_ifname(a, device, ifname))
return ifname; return ifname;
...@@ -922,10 +953,13 @@ int handle_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *cmdu) ...@@ -922,10 +953,13 @@ int handle_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *cmdu)
goto teardown; goto teardown;
} }
/* iterate every TLV_TYPE_WSC, may be multiple */ /* iterate every TLV_TYPE_WSC, may be multiple */
for (i = 0; i < cmdu->num_tlvs; i++) { for (i = 0; i < cmdu->num_tlvs; i++)
{
tlv = cmdu->tlvs[i]; tlv = cmdu->tlvs[i];
switch (*tlv) { switch (*tlv)
case TLV_TYPE_WSC: { {
case TLV_TYPE_WSC:
{
struct mdata out; struct mdata out;
struct tlv_wsc *m2; struct tlv_wsc *m2;
char ifname[IFNAMSIZ] = {0}; char ifname[IFNAMSIZ] = {0};
...@@ -933,9 +967,10 @@ int handle_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *cmdu) ...@@ -933,9 +967,10 @@ int handle_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *cmdu)
m2 = (struct tlv_wsc *)tlv; m2 = (struct tlv_wsc *)tlv;
if (!wifi_gen_first_ifname(a, radio->name, ifname)) { if (!wifi_gen_first_ifname(a, radio->name, ifname))
err("Failed to find valid interface name, "\ {
"probably maximum number of "\ err("Failed to find valid interface name, "
"probably maximum number of "
"interfaces have been reached\n", "interfaces have been reached\n",
MACFMT "!\n", MAC2STR(bssid)); MACFMT "!\n", MAC2STR(bssid));
return -1; return -1;
...@@ -946,9 +981,9 @@ int handle_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *cmdu) ...@@ -946,9 +981,9 @@ int handle_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *cmdu)
radio->autconfig.m1_size, radio->autconfig.m1_size,
m2->wsc_frame, m2->wsc_frame,
m2->wsc_frame_size, &out, ifname); m2->wsc_frame_size, &out, ifname);
if (!rv) { if (!rv)
err("Failed to process M2 target for interface "\ {
MACFMT "!\n", MAC2STR(bssid)); err("Failed to process M2 target for interface " MACFMT "!\n", MAC2STR(bssid));
wifi_teardown_map_ifaces_by_radio(a, wifi_teardown_map_ifaces_by_radio(a,
radio->name); radio->name);
...@@ -958,9 +993,10 @@ int handle_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *cmdu) ...@@ -958,9 +993,10 @@ int handle_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *cmdu)
return -1; return -1;
} }
if (BIT(3, out.output.mapie)) { if (BIT(3, out.output.mapie))
err("MAP Extension had teardown bit set, "\ {
"tearing down all MAP interfaces"\ err("MAP Extension had teardown bit set, "
"tearing down all MAP interfaces"
" for bssid" MACFMT "\n", " for bssid" MACFMT "\n",
MAC2STR(bssid)); MAC2STR(bssid));
wifi_teardown_map_ifaces_by_radio(a, wifi_teardown_map_ifaces_by_radio(a,
...@@ -1024,7 +1060,8 @@ int handle_ap_autoconfig_renew(void *agent, struct cmdu_cstruct *cmdu) ...@@ -1024,7 +1060,8 @@ int handle_ap_autoconfig_renew(void *agent, struct cmdu_cstruct *cmdu)
struct wifi_radio_element *radio; struct wifi_radio_element *radio;
int i; int i;
for (i = 0; i < a->num_radios; i++) { for (i = 0; i < a->num_radios; i++)
{
radio = a->radios + i; radio = a->radios + i;
build_ap_autoconfig_wsc(a, cmdu, radio, i); build_ap_autoconfig_wsc(a, cmdu, radio, i);
} }
...@@ -1035,7 +1072,8 @@ int get_radio_index(struct agent *a, uint8_t *mac) ...@@ -1035,7 +1072,8 @@ int get_radio_index(struct agent *a, uint8_t *mac)
{ {
int i; int i;
for (i = 0; i < a->num_radios; i++) { for (i = 0; i < a->num_radios; i++)
{
if (hwaddr_equal(a->radios[i].macaddr, mac)) if (hwaddr_equal(a->radios[i].macaddr, mac))
return i; return i;
} }
...@@ -1047,7 +1085,8 @@ int get_bss_index(struct wifi_radio_element *radio, uint8_t *bssid) ...@@ -1047,7 +1085,8 @@ int get_bss_index(struct wifi_radio_element *radio, uint8_t *bssid)
{ {
int i; int i;
for (i = 0; i < radio->num_bss; i++) { for (i = 0; i < radio->num_bss; i++)
{
if (hwaddr_equal(radio->bsslist[i].bssid, bssid)) if (hwaddr_equal(radio->bsslist[i].bssid, bssid))
return i; return i;
} }
...@@ -1061,9 +1100,11 @@ int get_radio_and_bss_index(struct agent *a, uint8_t *bssid, ...@@ -1061,9 +1100,11 @@ int get_radio_and_bss_index(struct agent *a, uint8_t *bssid,
int i; int i;
int bss_index; int bss_index;
for (i = 0; i < a->num_radios; i++) { for (i = 0; i < a->num_radios; i++)
{
bss_index = get_bss_index(&a->radios[i], bssid); bss_index = get_bss_index(&a->radios[i], bssid);
if (bss_index != -1) { if (bss_index != -1)
{
*radio_index = i; *radio_index = i;
return bss_index; return bss_index;
} }
...@@ -1096,7 +1137,8 @@ static struct cmdu_cstruct *prepare_ap_metrics_query( ...@@ -1096,7 +1137,8 @@ static struct cmdu_cstruct *prepare_ap_metrics_query(
memcpy(cmdu->origin, a->cntlr_almac, 6); memcpy(cmdu->origin, a->cntlr_almac, 6);
strncpy(cmdu->intf_name, "br-lan", IFNAMESIZE - 1); strncpy(cmdu->intf_name, "br-lan", IFNAMESIZE - 1);
if (ifname == NULL) { if (ifname == NULL)
{
/* AP Metrics Query TLV */ /* AP Metrics Query TLV */
cmdu->num_tlvs++; cmdu->num_tlvs++;
// #ifdef PROFILE2 // #ifdef PROFILE2
...@@ -1106,8 +1148,9 @@ static struct cmdu_cstruct *prepare_ap_metrics_query( ...@@ -1106,8 +1148,9 @@ static struct cmdu_cstruct *prepare_ap_metrics_query(
for (i = 0; i < a->num_radios; i++) for (i = 0; i < a->num_radios; i++)
total_bss += a->radios[i].num_bss; total_bss += a->radios[i].num_bss;
}
} else if (ifname && (ifname[0] != '\0')) { else if (ifname && (ifname[0] != '\0'))
{
/* AP Metrics Query TLV */ /* AP Metrics Query TLV */
cmdu->num_tlvs++; cmdu->num_tlvs++;
// #ifdef PROFILE2 // #ifdef PROFILE2
...@@ -1116,7 +1159,8 @@ static struct cmdu_cstruct *prepare_ap_metrics_query( ...@@ -1116,7 +1159,8 @@ static struct cmdu_cstruct *prepare_ap_metrics_query(
// #endif // #endif
radio = wifi_ifname_to_radio_element(a, ifname); radio = wifi_ifname_to_radio_element(a, ifname);
if (!radio) { if (!radio)
{
cmdu->num_tlvs = 0; cmdu->num_tlvs = 0;
goto error; goto error;
} }
...@@ -1125,12 +1169,12 @@ static struct cmdu_cstruct *prepare_ap_metrics_query( ...@@ -1125,12 +1169,12 @@ static struct cmdu_cstruct *prepare_ap_metrics_query(
} }
cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *)); cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *));
if (!cmdu->tlvs) { if (!cmdu->tlvs)
{
cmdu->num_tlvs = 0; cmdu->num_tlvs = 0;
goto error; goto error;
} }
p1 = calloc(1, sizeof(*p1)); p1 = calloc(1, sizeof(*p1));
if (!p1) if (!p1)
goto error; goto error;
...@@ -1139,16 +1183,19 @@ static struct cmdu_cstruct *prepare_ap_metrics_query( ...@@ -1139,16 +1183,19 @@ static struct cmdu_cstruct *prepare_ap_metrics_query(
p1->bssid_nr = total_bss; p1->bssid_nr = total_bss;
p1->ap_metric_query_bssid = calloc(p1->bssid_nr, p1->ap_metric_query_bssid = calloc(p1->bssid_nr,
sizeof(*p1->ap_metric_query_bssid)); sizeof(*p1->ap_metric_query_bssid));
if (!p1->ap_metric_query_bssid) { if (!p1->ap_metric_query_bssid)
{
free(p1); free(p1);
goto error; goto error;
} }
if (ifname == NULL) { if (ifname == NULL)
{
struct tlv_ap_radio_identifier *p2; struct tlv_ap_radio_identifier *p2;
k = 0; k = 0;
for (i = 0; i < a->num_radios; i++) { for (i = 0; i < a->num_radios; i++)
{
radio = a->radios + i; radio = a->radios + i;
// #ifdef PROFILE2 // #ifdef PROFILE2
p2 = agent_gen_ap_radio_identifier(a, radio->macaddr); p2 = agent_gen_ap_radio_identifier(a, radio->macaddr);
...@@ -1156,20 +1203,23 @@ static struct cmdu_cstruct *prepare_ap_metrics_query( ...@@ -1156,20 +1203,23 @@ static struct cmdu_cstruct *prepare_ap_metrics_query(
cmdu->tlvs[tlv_index++] = (uint8_t *)p2; cmdu->tlvs[tlv_index++] = (uint8_t *)p2;
// #endif // #endif
for (j = 0; j < radio->num_bss; j++) { for (j = 0; j < radio->num_bss; j++)
{
bss = radio->bsslist + j; bss = radio->bsslist + j;
memcpy(p1->ap_metric_query_bssid[k].bssid, memcpy(p1->ap_metric_query_bssid[k].bssid,
bss->bssid, 6); bss->bssid, 6);
k++; k++;
} }
} }
}
} else if (ifname && (ifname[0] != '\0')) { else if (ifname && (ifname[0] != '\0'))
{
struct tlv_ap_radio_identifier *p2; struct tlv_ap_radio_identifier *p2;
k = 0; k = 0;
radio = wifi_ifname_to_radio_element(a, ifname); radio = wifi_ifname_to_radio_element(a, ifname);
if (!radio) { if (!radio)
{
map_free_tlv_cstruct((uint8_t *)p1); map_free_tlv_cstruct((uint8_t *)p1);
goto error; goto error;
} }
...@@ -1180,13 +1230,13 @@ static struct cmdu_cstruct *prepare_ap_metrics_query( ...@@ -1180,13 +1230,13 @@ static struct cmdu_cstruct *prepare_ap_metrics_query(
cmdu->tlvs[tlv_index++] = (uint8_t *)p2; cmdu->tlvs[tlv_index++] = (uint8_t *)p2;
// #endif // #endif
for (i = 0; i < radio->num_bss; i++) { for (i = 0; i < radio->num_bss; i++)
{
bss = radio->bsslist + i; bss = radio->bsslist + i;
memcpy(p1->ap_metric_query_bssid[k].bssid, memcpy(p1->ap_metric_query_bssid[k].bssid,
bss->bssid, 6); bss->bssid, 6);
k++; k++;
} }
} }
cmdu->tlvs[tlv_index] = (uint8_t *)p1; cmdu->tlvs[tlv_index] = (uint8_t *)p1;
...@@ -1228,7 +1278,6 @@ static int prepare_assoc_sta_metric_response(void *agent, char *ifname) ...@@ -1228,7 +1278,6 @@ static int prepare_assoc_sta_metric_response(void *agent, char *ifname)
map_free_cmdu(cmdu); map_free_cmdu(cmdu);
return 0; return 0;
} }
int handle_1905_ack(void *agent, struct cmdu_cstruct *cmdu) int handle_1905_ack(void *agent, struct cmdu_cstruct *cmdu)
...@@ -1253,7 +1302,8 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) ...@@ -1253,7 +1302,8 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu)
cmdu = (struct cmdu_cstruct *)calloc(1, cmdu = (struct cmdu_cstruct *)calloc(1,
sizeof(struct cmdu_cstruct)); sizeof(struct cmdu_cstruct));
if (!cmdu) { if (!cmdu)
{
fprintf(stderr, "Out of memory!\n"); fprintf(stderr, "Out of memory!\n");
return -1; return -1;
} }
...@@ -1270,13 +1320,15 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) ...@@ -1270,13 +1320,15 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu)
//#endif PROFILE2 //#endif PROFILE2
cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *)); cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *));
if (!cmdu->tlvs) { if (!cmdu->tlvs)
{
map_free_cmdu(cmdu); map_free_cmdu(cmdu);
return -1; return -1;
} }
/* AP basic Radio Capability TLV*/ /* AP basic Radio Capability TLV*/
for (i = 0; i < a->num_radios; i++) { for (i = 0; i < a->num_radios; i++)
{
struct tlv_ap_radio_basic_cap *p; struct tlv_ap_radio_basic_cap *p;
p = agent_gen_ap_radio_basic_cap(a, cmdu, &a->radios[i]); p = agent_gen_ap_radio_basic_cap(a, cmdu, &a->radios[i]);
...@@ -1295,7 +1347,8 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) ...@@ -1295,7 +1347,8 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu)
cmdu->tlvs[tlv_index++] = (uint8_t *)p2; cmdu->tlvs[tlv_index++] = (uint8_t *)p2;
/* HT Capability */ /* HT Capability */
for (i = 0; i < a->num_radios; i++) { for (i = 0; i < a->num_radios; i++)
{
struct tlv_ap_ht_cap *p3; struct tlv_ap_ht_cap *p3;
p3 = agent_gen_ap_ht_caps(a, cmdu, i); p3 = agent_gen_ap_ht_caps(a, cmdu, i);
...@@ -1303,12 +1356,12 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) ...@@ -1303,12 +1356,12 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu)
continue; continue;
//cmdu->num_tlvs++; //cmdu->num_tlvs++;
cmdu->tlvs[tlv_index++] = (uint8_t *)p3; cmdu->tlvs[tlv_index++] = (uint8_t *)p3;
} }
/* VHT Capability */ /* VHT Capability */
for (i = 0; i < a->num_radios; i++) { for (i = 0; i < a->num_radios; i++)
{
struct tlv_ap_vht_cap *p4; struct tlv_ap_vht_cap *p4;
p4 = agent_gen_ap_vht_caps(a, cmdu, i); p4 = agent_gen_ap_vht_caps(a, cmdu, i);
...@@ -1393,9 +1446,11 @@ static uint8_t calculate_radio_rcpi(struct agent *a, char *ifname) ...@@ -1393,9 +1446,11 @@ static uint8_t calculate_radio_rcpi(struct agent *a, char *ifname)
if (!radio) if (!radio)
return 0; return 0;
for (j = 0; j < radio->num_bss; j++) { for (j = 0; j < radio->num_bss; j++)
{
bss = radio->bsslist + j; bss = radio->bsslist + j;
for (k = 0; k < bss->num_stations; k++) { for (k = 0; k < bss->num_stations; k++)
{
sta = bss->stalist + k; sta = bss->stalist + k;
rssi += sta->rssi; rssi += sta->rssi;
} }
...@@ -1485,27 +1540,31 @@ static int agent_process_policy_config(struct agent *a) ...@@ -1485,27 +1540,31 @@ static int agent_process_policy_config(struct agent *a)
struct agent_config *cfg = &a->cfg; struct agent_config *cfg = &a->cfg;
struct policy_cfg *c = cfg->pcfg; struct policy_cfg *c = cfg->pcfg;
if (c && (c->report_interval > 0)) { if (c && (c->report_interval > 0))
{
cfg->metric_report_timer.cb = agent_metric_report_timer_cb; cfg->metric_report_timer.cb = agent_metric_report_timer_cb;
uloop_timeout_set(&cfg->metric_report_timer, uloop_timeout_set(&cfg->metric_report_timer,
c->report_interval * 1000); c->report_interval * 1000);
} }
for (i = 0; i < a->num_radios; i++) { for (i = 0; i < a->num_radios; i++)
{
struct netif_fh *p; struct netif_fh *p;
p = wifi_radio_to_ap(a, a->radios[i].name); p = wifi_radio_to_ap(a, a->radios[i].name);
if (!p) if (!p)
continue; continue;
if (p->cfg->util_threshold > 0) { if (p->cfg->util_threshold > 0)
{
p->util_threshold_timer.cb = p->util_threshold_timer.cb =
agent_util_threshold_timer_cb; agent_util_threshold_timer_cb;
uloop_timeout_set(&p->util_threshold_timer, uloop_timeout_set(&p->util_threshold_timer,
UTIL_THRESHOLD_TIMER); UTIL_THRESHOLD_TIMER);
} }
if (p->cfg->rcpi_threshold > 0) { if (p->cfg->rcpi_threshold > 0)
{
p->rcpi_threshold_timer.cb = p->rcpi_threshold_timer.cb =
agent_rcpi_thresold_timer_cb; agent_rcpi_thresold_timer_cb;
uloop_timeout_set(&p->rcpi_threshold_timer, uloop_timeout_set(&p->rcpi_threshold_timer,
...@@ -1543,16 +1602,19 @@ int handle_map_policy_config(void *agent, struct cmdu_cstruct *cmdu) ...@@ -1543,16 +1602,19 @@ int handle_map_policy_config(void *agent, struct cmdu_cstruct *cmdu)
if (!ctx) if (!ctx)
return -1; return -1;
if (uci_load(ctx, "mapagent", &pkg)) { if (uci_load(ctx, "mapagent", &pkg))
{
uci_free_context(ctx); uci_free_context(ctx);
return -1; return -1;
} }
for (i = 0; i < cmdu->num_tlvs; i++) { for (i = 0; i < cmdu->num_tlvs; i++)
{
tlv = (uint8_t *)cmdu->tlvs[i]; tlv = (uint8_t *)cmdu->tlvs[i];
fprintf(stderr, "TLV: %s\n", map_stringify_tlv_type(*tlv)); fprintf(stderr, "TLV: %s\n", map_stringify_tlv_type(*tlv));
switch (*tlv) { switch (*tlv)
{
case MAP_TLV_STEERING_POLICY: case MAP_TLV_STEERING_POLICY:
{ {
struct tlv_steering_policy *p = struct tlv_steering_policy *p =
...@@ -1642,7 +1704,8 @@ int handle_channel_pref_query(void *agent, struct cmdu_cstruct *rec_cmdu) ...@@ -1642,7 +1704,8 @@ int handle_channel_pref_query(void *agent, struct cmdu_cstruct *rec_cmdu)
cmdu_data = (struct cmdu_cstruct *)calloc(1, cmdu_data = (struct cmdu_cstruct *)calloc(1,
sizeof(struct cmdu_cstruct)); sizeof(struct cmdu_cstruct));
if (!cmdu_data) { if (!cmdu_data)
{
fprintf(stderr, "Out of memory!\n"); fprintf(stderr, "Out of memory!\n");
return -1; return -1;
} }
...@@ -1655,17 +1718,20 @@ int handle_channel_pref_query(void *agent, struct cmdu_cstruct *rec_cmdu) ...@@ -1655,17 +1718,20 @@ int handle_channel_pref_query(void *agent, struct cmdu_cstruct *rec_cmdu)
cmdu_data->num_tlvs = 2 * a->num_radios + 1 + 1; /* (Preference TLV + Restriction TLV)+(CAC status + CAC_report) */ cmdu_data->num_tlvs = 2 * a->num_radios + 1 + 1; /* (Preference TLV + Restriction TLV)+(CAC status + CAC_report) */
cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs,
sizeof(uint8_t *)); sizeof(uint8_t *));
if (!cmdu_data->tlvs) { if (!cmdu_data->tlvs)
{
map_free_cmdu(cmdu_data); map_free_cmdu(cmdu_data);
return -1; return -1;
} }
/* Channel Preference TLV 17.2.13 */ /* Channel Preference TLV 17.2.13 */
for (j = 0; j < a->num_radios; j++) { for (j = 0; j < a->num_radios; j++)
{
struct tlv_channel_pref *p = struct tlv_channel_pref *p =
(struct tlv_channel_pref *)calloc(1, (struct tlv_channel_pref *)calloc(1,
sizeof(struct tlv_channel_pref)); sizeof(struct tlv_channel_pref));
if (p) { if (p)
{
p->tlv_type = MAP_TLV_CHANNEL_PREFERENCE; p->tlv_type = MAP_TLV_CHANNEL_PREFERENCE;
agent_gen_radio_channel_preference(a, p, j); agent_gen_radio_channel_preference(a, p, j);
cmdu_data->tlvs[tlv_index++] = (uint8_t *)p; cmdu_data->tlvs[tlv_index++] = (uint8_t *)p;
...@@ -1673,24 +1739,26 @@ int handle_channel_pref_query(void *agent, struct cmdu_cstruct *rec_cmdu) ...@@ -1673,24 +1739,26 @@ int handle_channel_pref_query(void *agent, struct cmdu_cstruct *rec_cmdu)
} }
/* Radio Operation Restriction TLV 17.2.14*/ /* Radio Operation Restriction TLV 17.2.14*/
for (j = 0; j < a->num_radios; j++) { for (j = 0; j < a->num_radios; j++)
{
struct tlv_radio_oper_restrict *p1 = struct tlv_radio_oper_restrict *p1 =
(struct tlv_radio_oper_restrict *)calloc(1, (struct tlv_radio_oper_restrict *)calloc(1,
sizeof(struct tlv_radio_oper_restrict)); sizeof(struct tlv_radio_oper_restrict));
if (p1) { if (p1)
{
p1->tlv_type = MAP_TLV_RADIO_OPERATION_RESTRICTION; p1->tlv_type = MAP_TLV_RADIO_OPERATION_RESTRICTION;
agent_gen_radio_restrict_channel(a, p1, j); agent_gen_radio_restrict_channel(a, p1, j);
cmdu_data->tlvs[tlv_index++] = (uint8_t *)p1; cmdu_data->tlvs[tlv_index++] = (uint8_t *)p1;
} }
} }
//#ifdef profile2 //#ifdef profile2
/*TODO CAC Completion Report TLV (section 17.2.44). [Profile-2]*/ /*TODO CAC Completion Report TLV (section 17.2.44). [Profile-2]*/
struct tlv_cac_comp_report *p2 = struct tlv_cac_comp_report *p2 =
(struct tlv_cac_comp_report *)calloc(1, (struct tlv_cac_comp_report *)calloc(1,
sizeof(struct tlv_cac_comp_report)); sizeof(struct tlv_cac_comp_report));
if (p2) { if (p2)
{
p2->tlv_type = MAP_TLV_CAC_COMPLETION_REPORT; p2->tlv_type = MAP_TLV_CAC_COMPLETION_REPORT;
agent_gen_cac_comp_report(a, p2); agent_gen_cac_comp_report(a, p2);
cmdu_data->tlvs[tlv_index++] = (uint8_t *)p2; cmdu_data->tlvs[tlv_index++] = (uint8_t *)p2;
...@@ -1700,7 +1768,8 @@ int handle_channel_pref_query(void *agent, struct cmdu_cstruct *rec_cmdu) ...@@ -1700,7 +1768,8 @@ int handle_channel_pref_query(void *agent, struct cmdu_cstruct *rec_cmdu)
struct tlv_cac_status_report *p3 = struct tlv_cac_status_report *p3 =
(struct tlv_cac_status_report *)calloc(1, (struct tlv_cac_status_report *)calloc(1,
sizeof(struct tlv_cac_status_report)); sizeof(struct tlv_cac_status_report));
if (p3) { if (p3)
{
p3->tlv_type = MAP_TLV_CAC_STATUS_REPORT; p3->tlv_type = MAP_TLV_CAC_STATUS_REPORT;
p3->nbr_available_ch = 0; //TODO dummy value p3->nbr_available_ch = 0; //TODO dummy value
p3->ch_data = NULL; //TODO dummy value p3->ch_data = NULL; //TODO dummy value
...@@ -1730,7 +1799,8 @@ int send_channel_sel_response(void *agent, struct cmdu_cstruct *rec_cmdu, ...@@ -1730,7 +1799,8 @@ int send_channel_sel_response(void *agent, struct cmdu_cstruct *rec_cmdu,
cmdu_data = (struct cmdu_cstruct *)calloc(1, cmdu_data = (struct cmdu_cstruct *)calloc(1,
sizeof(struct cmdu_cstruct)); sizeof(struct cmdu_cstruct));
if (!cmdu_data) { if (!cmdu_data)
{
fprintf(stderr, "Out of memory!\n"); fprintf(stderr, "Out of memory!\n");
return -1; return -1;
} }
...@@ -1744,13 +1814,15 @@ int send_channel_sel_response(void *agent, struct cmdu_cstruct *rec_cmdu, ...@@ -1744,13 +1814,15 @@ int send_channel_sel_response(void *agent, struct cmdu_cstruct *rec_cmdu,
cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs,
sizeof(uint8_t *)); sizeof(uint8_t *));
if (!cmdu_data->tlvs) { if (!cmdu_data->tlvs)
{
map_free_cmdu(cmdu_data); map_free_cmdu(cmdu_data);
return -1; return -1;
} }
/* Operating Channel Response TLV 17.2.16 */ /* Operating Channel Response TLV 17.2.16 */
for (j = 0; j < channel_response_nr; j++) { for (j = 0; j < channel_response_nr; j++)
{
struct tlv_ch_selection_resp *p = NULL; struct tlv_ch_selection_resp *p = NULL;
/* Here we need to check that the radio /* Here we need to check that the radio
*response is for the radio for which we get request *response is for the radio for which we get request
...@@ -1783,13 +1855,14 @@ int agent_fill_radio_max_preference(void *agent, ...@@ -1783,13 +1855,14 @@ int agent_fill_radio_max_preference(void *agent,
*channel_response_nr = a->num_radios; *channel_response_nr = a->num_radios;
for (j = 0; j < a->num_radios; j++) { for (j = 0; j < a->num_radios; j++)
{
radio = a->radios + j; radio = a->radios + j;
memcpy(channel_resp[j].radio_id, radio->macaddr, 6); memcpy(channel_resp[j].radio_id, radio->macaddr, 6);
for (k = 0; k < radio->num_supp_opclass; k++) { for (k = 0; k < radio->num_supp_opclass; k++)
for (l = 0; l < radio->supp_opclass[k]. {
num_supported_channels; l++) for (l = 0; l < radio->supp_opclass[k].num_supported_channels; l++)
radio->supp_opclass[k].supp_chanlist[l].pref = radio->supp_opclass[k].supp_chanlist[l].pref =
0xff; 0xff;
} }
...@@ -1810,10 +1883,12 @@ int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p, ...@@ -1810,10 +1883,12 @@ int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p,
struct wifi_radio_element *radio; struct wifi_radio_element *radio;
trace("\tradio_id: " MACFMT "\n", MAC2STR(p->radio_id)); trace("\tradio_id: " MACFMT "\n", MAC2STR(p->radio_id));
for (l = 0; l < a->num_radios; l++) { for (l = 0; l < a->num_radios; l++)
{
radio = a->radios + l; radio = a->radios + l;
match = memcmp(radio->macaddr, p->radio_id, 6); match = memcmp(radio->macaddr, p->radio_id, 6);
if (match == 0) { if (match == 0)
{
found = 1; found = 1;
memcpy(channel_resp[*channel_resp_nr].radio_id, memcpy(channel_resp[*channel_resp_nr].radio_id,
radio->macaddr, 6); radio->macaddr, 6);
...@@ -1821,7 +1896,8 @@ int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p, ...@@ -1821,7 +1896,8 @@ int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p,
break; break;
} }
} }
if (found == 0) { if (found == 0)
{
memcpy(channel_resp[*channel_resp_nr].radio_id, memcpy(channel_resp[*channel_resp_nr].radio_id,
p->radio_id, 6); p->radio_id, 6);
/* Here response code is a Reserved code /* Here response code is a Reserved code
...@@ -1833,10 +1909,13 @@ int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p, ...@@ -1833,10 +1909,13 @@ int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p,
} }
trace("ch_preference_op_class_nr: %d\n", p->ch_preference_op_class_nr); trace("ch_preference_op_class_nr: %d\n", p->ch_preference_op_class_nr);
for (j = 0; j < p->ch_preference_op_class_nr; j++) { for (j = 0; j < p->ch_preference_op_class_nr; j++)
{
/* Here we need to search the operating class in the radio */ /* Here we need to search the operating class in the radio */
for (l = 0; l < radio->num_supp_opclass; l++) { for (l = 0; l < radio->num_supp_opclass; l++)
if (radio->supp_opclass[l].id == p->op_class[j].op_class) { {
if (radio->supp_opclass[l].id == p->op_class[j].op_class)
{
int k; int k;
/* Here we reset all the channels preferences /* Here we reset all the channels preferences
...@@ -1850,22 +1929,22 @@ int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p, ...@@ -1850,22 +1929,22 @@ int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p,
for (k = 0; k < for (k = 0; k <
radio->supp_opclass[l].num_supported_channels; radio->supp_opclass[l].num_supported_channels;
k++) k++)
radio->supp_opclass[l]. radio->supp_opclass[l].supp_chanlist[k].pref = 0xff;
supp_chanlist[k].pref = 0xff;
for (k = 0; k < p->op_class[j].channel_nr; k++) { for (k = 0; k < p->op_class[j].channel_nr; k++)
{
int m; int m;
for (m = 0; m < for (m = 0; m <
radio->supp_opclass[l]. radio->supp_opclass[l].num_supported_channels;
num_supported_channels ; m++) { m++)
{
trace("channel %d\n", trace("channel %d\n",
p->op_class[j].channel_list[k]); p->op_class[j].channel_list[k]);
if (p->op_class[j].channel_list[k] == if (p->op_class[j].channel_list[k] ==
radio->supp_opclass[l]. radio->supp_opclass[l].supp_chanlist[m].channel)
supp_chanlist[m].channel) { {
radio->supp_opclass[l]. radio->supp_opclass[l].supp_chanlist[m].pref =
supp_chanlist[m].pref =
p->op_class[j].preference; p->op_class[j].preference;
trace("channel pref is %d\n", trace("channel pref is %d\n",
...@@ -1897,18 +1976,20 @@ int handle_channel_sel_request(void *agent, struct cmdu_cstruct *cmdu) ...@@ -1897,18 +1976,20 @@ int handle_channel_sel_request(void *agent, struct cmdu_cstruct *cmdu)
* from the channel selection request * from the channel selection request
* then send the CMDU for channel selection response * then send the CMDU for channel selection response
*/ */
if (cmdu->num_tlvs != 0) { if (cmdu->num_tlvs != 0)
for (i = 0; i < cmdu->num_tlvs; i++) { {
for (i = 0; i < cmdu->num_tlvs; i++)
{
tlv = (uint8_t *)cmdu->tlvs[i]; tlv = (uint8_t *)cmdu->tlvs[i];
switch (*tlv) { switch (*tlv)
{
case MAP_TLV_CHANNEL_PREFERENCE: case MAP_TLV_CHANNEL_PREFERENCE:
{ {
struct tlv_channel_pref *p = struct tlv_channel_pref *p =
(struct tlv_channel_pref *)tlv; (struct tlv_channel_pref *)tlv;
pref_tlv_present = 1; pref_tlv_present = 1;
ret = agent_process_channel_pref_tlv ret = agent_process_channel_pref_tlv(agent, p, channel_resp,
(agent, p, channel_resp,
&channel_resp_nr); &channel_resp_nr);
} }
case MAP_TLV_TRANSMIT_POWER_LIMIT: case MAP_TLV_TRANSMIT_POWER_LIMIT:
...@@ -1919,10 +2000,12 @@ int handle_channel_sel_request(void *agent, struct cmdu_cstruct *cmdu) ...@@ -1919,10 +2000,12 @@ int handle_channel_sel_request(void *agent, struct cmdu_cstruct *cmdu)
trace("tlv radio_id: " MACFMT "\n", trace("tlv radio_id: " MACFMT "\n",
MAC2STR(p->radio_id)); MAC2STR(p->radio_id));
for (l = 0; l < a->num_radios; l++) { for (l = 0; l < a->num_radios; l++)
{
radio = a->radios + l; radio = a->radios + l;
match = memcmp(radio->macaddr, p->radio_id, 6); match = memcmp(radio->macaddr, p->radio_id, 6);
if (match == 0) { if (match == 0)
{
/* Here we set the /* Here we set the
* transmit_power_limit * transmit_power_limit
* of the radio * of the radio
...@@ -1941,7 +2024,8 @@ int handle_channel_sel_request(void *agent, struct cmdu_cstruct *cmdu) ...@@ -1941,7 +2024,8 @@ int handle_channel_sel_request(void *agent, struct cmdu_cstruct *cmdu)
} }
} }
if (cmdu->num_tlvs == 0 || pref_tlv_present == 0) { if (cmdu->num_tlvs == 0 || pref_tlv_present == 0)
{
/* Here the condition is that the /* Here the condition is that the
* channel selection request have no tlvs or only transmit power tlv * channel selection request have no tlvs or only transmit power tlv
* so we need to set all the prefernce in all radios to max 15 * so we need to set all the prefernce in all radios to max 15
...@@ -1980,7 +2064,8 @@ int handle_sta_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) ...@@ -1980,7 +2064,8 @@ int handle_sta_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu)
return -1; return -1;
cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct));
if (!cmdu) { if (!cmdu)
{
dbg("Out of memory!\n"); dbg("Out of memory!\n");
return -1; return -1;
} }
...@@ -2015,23 +2100,26 @@ int handle_sta_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) ...@@ -2015,23 +2100,26 @@ int handle_sta_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu)
memcpy(p2->addr, query->client_addr, 6); memcpy(p2->addr, query->client_addr, 6);
fh = get_netif_by_bssid(a, query->bssid); fh = get_netif_by_bssid(a, query->bssid);
if (!fh) { if (!fh)
{
dbg("BSS not found!\n"); dbg("BSS not found!\n");
goto send_cmdu; goto send_cmdu;
} }
list_for_each_entry(s, &fh->stalist, list) list_for_each_entry(s, &fh->stalist, list) if (!memcmp(s->macaddr, query->client_addr, 6))
if (!memcmp(s->macaddr, query->client_addr, 6)) { {
found = true; found = true;
break; break;
} }
if (!found || !s) { if (!found || !s)
{
p2->reason_code = 0x02; p2->reason_code = 0x02;
dbg("Missing client!\n"); dbg("Missing client!\n");
goto send_cmdu; goto send_cmdu;
} }
if (!s->assoc_frame) { if (!s->assoc_frame)
{
dbg("Missing assoc frame!\n"); dbg("Missing assoc frame!\n");
goto send_cmdu; goto send_cmdu;
} }
...@@ -2151,18 +2239,22 @@ int validate_sta_bssid_assoc(struct netif_fh *fh, struct tlv_steer_Req *p, ...@@ -2151,18 +2239,22 @@ int validate_sta_bssid_assoc(struct netif_fh *fh, struct tlv_steer_Req *p,
uint32_t count = 0; uint32_t count = 0;
uint32_t res = 0, found = 0; uint32_t res = 0, found = 0;
for (l = 0; l < p->sta_list_cnt; l++) { for (l = 0; l < p->sta_list_cnt; l++)
list_for_each_entry(s, &fh->stalist, list) { {
list_for_each_entry(s, &fh->stalist, list)
{
trace("stalist :" MACFMT "\n", trace("stalist :" MACFMT "\n",
MAC2STR(s->macaddr)); MAC2STR(s->macaddr));
res = memcmp(s->macaddr, p->steering_req_macs[l].addr, 6); res = memcmp(s->macaddr, p->steering_req_macs[l].addr, 6);
if (res == 0) { if (res == 0)
{
found = 1; found = 1;
/** /**
* Here as the sta is present check that in this case * Here as the sta is present check that in this case
* for steering opportunity put that in the array * for steering opportunity put that in the array
*/ */
if (p->request_mode == 0x00) { if (p->request_mode == 0x00)
{
memcpy(a->sta_steer_list[a->sta_steerlist_count].sta_mac, memcpy(a->sta_steer_list[a->sta_steerlist_count].sta_mac,
p->steering_req_macs[l].addr, 6); p->steering_req_macs[l].addr, 6);
a->sta_steerlist_count = a->sta_steerlist_count + 1; a->sta_steerlist_count = a->sta_steerlist_count + 1;
...@@ -2170,7 +2262,8 @@ int validate_sta_bssid_assoc(struct netif_fh *fh, struct tlv_steer_Req *p, ...@@ -2170,7 +2262,8 @@ int validate_sta_bssid_assoc(struct netif_fh *fh, struct tlv_steer_Req *p,
break; break;
} }
} }
if (found == 0 || !s) { if (found == 0 || !s)
{
dbg("Missing STA client!\n"); dbg("Missing STA client!\n");
memcpy(sta_resp[count].sta_mac, p->steering_req_macs[l].addr, 6); memcpy(sta_resp[count].sta_mac, p->steering_req_macs[l].addr, 6);
sta_resp[count].response = 0x02; sta_resp[count].response = 0x02;
...@@ -2205,13 +2298,15 @@ int agent_send_request_transition(void *agent, uint8_t *client_sta, ...@@ -2205,13 +2298,15 @@ int agent_send_request_transition(void *agent, uint8_t *client_sta,
blobmsg_add_string(&bb, NULL, bssid_str); blobmsg_add_string(&bb, NULL, bssid_str);
blobmsg_close_table(&bb, tbl); blobmsg_close_table(&bb, tbl);
if (timeout) { if (timeout)
{
//fill the timeout //fill the timeout
} }
ret = ubus_invoke(a->ubus_ctx, fh->wifi, "request_transition", bb.head, ret = ubus_invoke(a->ubus_ctx, fh->wifi, "request_transition", bb.head,
NULL, NULL, UBUS_TIMEOUT); NULL, NULL, UBUS_TIMEOUT);
if (ret) { if (ret)
{
trace("[%s:%d] ubus call failed for |wifi.ap. send|", trace("[%s:%d] ubus call failed for |wifi.ap. send|",
__func__, __LINE__); __func__, __LINE__);
goto out; goto out;
...@@ -2232,11 +2327,13 @@ int agent_search_bssid_for_sta(struct agent *a, uint8_t *sta, uint8_t *bssid, ...@@ -2232,11 +2327,13 @@ int agent_search_bssid_for_sta(struct agent *a, uint8_t *sta, uint8_t *bssid,
int ret = 0; int ret = 0;
trace("agent: %s: --->\n", __func__); trace("agent: %s: --->\n", __func__);
list_for_each_entry(p, &a->fhlist, list) { list_for_each_entry(p, &a->fhlist, list)
{
trace("bssid = " MACFMT " pbssid = " MACFMT "\n", trace("bssid = " MACFMT " pbssid = " MACFMT "\n",
MAC2STR(bssid), MAC2STR(p->bssid)); MAC2STR(bssid), MAC2STR(p->bssid));
ret = memcmp(src_bssid, p->bssid, 6); ret = memcmp(src_bssid, p->bssid, 6);
if (ret != 0) { if (ret != 0)
{
memcpy(bssid, p->bssid, 6); memcpy(bssid, p->bssid, 6);
return 0; return 0;
} }
...@@ -2259,7 +2356,8 @@ int send_1905_acknowledge(void *agent, ...@@ -2259,7 +2356,8 @@ int send_1905_acknowledge(void *agent,
cmdu_data = (struct cmdu_cstruct *)calloc(1, cmdu_data = (struct cmdu_cstruct *)calloc(1,
sizeof(struct cmdu_cstruct)); sizeof(struct cmdu_cstruct));
if (!cmdu_data) { if (!cmdu_data)
{
fprintf(stderr, "Out of memory!\n"); fprintf(stderr, "Out of memory!\n");
return -1; return -1;
} }
...@@ -2273,13 +2371,15 @@ int send_1905_acknowledge(void *agent, ...@@ -2273,13 +2371,15 @@ int send_1905_acknowledge(void *agent,
cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs,
sizeof(uint8_t *)); sizeof(uint8_t *));
if (!cmdu_data->tlvs) { if (!cmdu_data->tlvs)
{
map_free_cmdu(cmdu_data); map_free_cmdu(cmdu_data);
return -1; return -1;
} }
/* Error Code TLV 17.2.36 */ /* Error Code TLV 17.2.36 */
for (j = 0; j < sta_count; j++) { for (j = 0; j < sta_count; j++)
{
struct tlv_error_code *p = NULL; struct tlv_error_code *p = NULL;
/** /**
* Here we need to check that the sta error * Here we need to check that the sta error
...@@ -2316,7 +2416,8 @@ int agent_send_restrict_sta(void *agent, uint32_t count_sta, ...@@ -2316,7 +2416,8 @@ int agent_send_restrict_sta(void *agent, uint32_t count_sta,
blob_buf_init(&bb, 0); blob_buf_init(&bb, 0);
tbl = blobmsg_open_array(&bb, "client"); tbl = blobmsg_open_array(&bb, "client");
for (i = 0; i < count_sta; i++) { for (i = 0; i < count_sta; i++)
{
hwaddr_ntoa(client_sta[i], client_macstr); hwaddr_ntoa(client_sta[i], client_macstr);
trace("agent: stalist :" MACFMT "\n", trace("agent: stalist :" MACFMT "\n",
MAC2STR(client_sta[i])); MAC2STR(client_sta[i]));
...@@ -2327,7 +2428,8 @@ int agent_send_restrict_sta(void *agent, uint32_t count_sta, ...@@ -2327,7 +2428,8 @@ int agent_send_restrict_sta(void *agent, uint32_t count_sta,
trace("Enable value is %d\n", enable); trace("Enable value is %d\n", enable);
ret = ubus_invoke(a->ubus_ctx, fh->wifi, "assoc_control", bb.head, ret = ubus_invoke(a->ubus_ctx, fh->wifi, "assoc_control", bb.head,
NULL, NULL, UBUS_TIMEOUT); NULL, NULL, UBUS_TIMEOUT);
if (ret) { if (ret)
{
trace("[%s:%d] ubus call failed for assoc_control", trace("[%s:%d] ubus call failed for assoc_control",
__func__, __LINE__); __func__, __LINE__);
} }
...@@ -2344,7 +2446,8 @@ static void wifi_restrict_sta_timeout(struct uloop_timeout *t) ...@@ -2344,7 +2446,8 @@ static void wifi_restrict_sta_timeout(struct uloop_timeout *t)
trace("agent: %s: --->\n", __func__); trace("agent: %s: --->\n", __func__);
fh = s->vif; fh = s->vif;
if (!fh) { if (!fh)
{
trace("[%s:%d] Error BSSID not present", __func__, __LINE__); trace("[%s:%d] Error BSSID not present", __func__, __LINE__);
return -1; return -1;
} }
...@@ -2365,11 +2468,14 @@ int agent_check_start_validity_tmr(uint16_t validity_period, ...@@ -2365,11 +2468,14 @@ int agent_check_start_validity_tmr(uint16_t validity_period,
if (stalist == NULL) if (stalist == NULL)
return -1; return -1;
for (i = 0; i < sta_count; i++) { for (i = 0; i < sta_count; i++)
{
// check if the sta is already running a timer // check if the sta is already running a timer
// delete the timer // delete the timer
list_for_each_entry_safe(s, tmp, &fh->restrict_stalist, list) { list_for_each_entry_safe(s, tmp, &fh->restrict_stalist, list)
if (!memcmp(s->sta, stalist[i], 6)) { {
if (!memcmp(s->sta, stalist[i], 6))
{
uloop_timeout_cancel(&s->restrict_timer); uloop_timeout_cancel(&s->restrict_timer);
list_del(&s->list); list_del(&s->list);
free(s); free(s);
...@@ -2378,7 +2484,8 @@ int agent_check_start_validity_tmr(uint16_t validity_period, ...@@ -2378,7 +2484,8 @@ int agent_check_start_validity_tmr(uint16_t validity_period,
// If the timer is not already running // If the timer is not already running
ss = calloc(1, sizeof(struct restrict_sta_entry)); ss = calloc(1, sizeof(struct restrict_sta_entry));
if (ss) { if (ss)
{
memcpy(ss->sta, stalist[i], 6); memcpy(ss->sta, stalist[i], 6);
//memcpy(ss->bssid, fh->bssid, 6); //memcpy(ss->bssid, fh->bssid, 6);
ss->vif = fh; ss->vif = fh;
...@@ -2401,12 +2508,16 @@ int agent_check_stop_validity_tmr(uint32_t sta_count, uint8_t stalist[][6], ...@@ -2401,12 +2508,16 @@ int agent_check_stop_validity_tmr(uint32_t sta_count, uint8_t stalist[][6],
if (stalist == NULL) if (stalist == NULL)
return -1; return -1;
for (i = 0; i < sta_count; i++) { for (i = 0; i < sta_count; i++)
{
// check if the sta is already running a timer // check if the sta is already running a timer
// delete the timer // delete the timer
list_for_each_entry_safe(s, tmp, &fh->restrict_stalist, list) { list_for_each_entry_safe(s, tmp, &fh->restrict_stalist, list)
if (s != NULL) { {
if (!memcmp(s->sta, stalist[i], 6)) { if (s != NULL)
{
if (!memcmp(s->sta, stalist[i], 6))
{
uloop_timeout_cancel(&s->restrict_timer); uloop_timeout_cancel(&s->restrict_timer);
list_del(&s->list); list_del(&s->list);
free(s); free(s);
...@@ -2437,17 +2548,20 @@ int agent_process_assoc_cntl_tlv(void *agent, ...@@ -2437,17 +2548,20 @@ int agent_process_assoc_cntl_tlv(void *agent,
memcpy(sta_list[m], p->client_assoc_ctrl_req_stas[m].addr, 6); memcpy(sta_list[m], p->client_assoc_ctrl_req_stas[m].addr, 6);
fh = get_netif_by_bssid(a, p->bssid); fh = get_netif_by_bssid(a, p->bssid);
if (!fh) { if (!fh)
{
trace("[%s:%d] Error BSSID not present", __func__, __LINE__); trace("[%s:%d] Error BSSID not present", __func__, __LINE__);
return -1; return -1;
} }
/*Here we first validate that the STA has been sent for /*Here we first validate that the STA has been sent for
* blocking */ * blocking */
if (p->assoc_control == 0x00) { if (p->assoc_control == 0x00)
{
/*Check if the validity timer value is not zero*/ /*Check if the validity timer value is not zero*/
if (p->validity_period == 0) { if (p->validity_period == 0)
{
trace("[%s:%d] Error validity period is invalid\n", __func__, __LINE__); trace("[%s:%d] Error validity period is invalid\n", __func__, __LINE__);
return -1; return -1;
} }
...@@ -2457,17 +2571,21 @@ int agent_process_assoc_cntl_tlv(void *agent, ...@@ -2457,17 +2571,21 @@ int agent_process_assoc_cntl_tlv(void *agent,
* be associated with the bssid for which the blocking mode is * be associated with the bssid for which the blocking mode is
* set */ * set */
for (l = 0; l < p->sta_list_cnt; l++) { for (l = 0; l < p->sta_list_cnt; l++)
list_for_each_entry(s, &fh->stalist, list) { {
list_for_each_entry(s, &fh->stalist, list)
{
trace("stalist :" MACFMT "\n", trace("stalist :" MACFMT "\n",
MAC2STR(s->macaddr)); MAC2STR(s->macaddr));
res = memcmp(s->macaddr, p->client_assoc_ctrl_req_stas[l].addr, 6); res = memcmp(s->macaddr, p->client_assoc_ctrl_req_stas[l].addr, 6);
if (res == 0) { if (res == 0)
{
found = 1; found = 1;
break; break;
} }
} }
if (found == 1) { if (found == 1)
{
dbg("STA client already associated with the bssid!\n"); dbg("STA client already associated with the bssid!\n");
memcpy(sta_resp[count].sta_mac, p->client_assoc_ctrl_req_stas[l].addr, 6); memcpy(sta_resp[count].sta_mac, p->client_assoc_ctrl_req_stas[l].addr, 6);
sta_resp[count].response = 0x01; sta_resp[count].response = 0x01;
...@@ -2477,7 +2595,8 @@ int agent_process_assoc_cntl_tlv(void *agent, ...@@ -2477,7 +2595,8 @@ int agent_process_assoc_cntl_tlv(void *agent,
/*Here we need the logic to block the STA*/ /*Here we need the logic to block the STA*/
ret = agent_send_restrict_sta(agent, p->sta_list_cnt, ret = agent_send_restrict_sta(agent, p->sta_list_cnt,
sta_list, fh, p->assoc_control); sta_list, fh, p->assoc_control);
if (ret != 0) { if (ret != 0)
{
trace("[%s:%d] Error in agent_send_restrict_sta\n", __func__, __LINE__); trace("[%s:%d] Error in agent_send_restrict_sta\n", __func__, __LINE__);
return -1; return -1;
} }
...@@ -2485,29 +2604,36 @@ int agent_process_assoc_cntl_tlv(void *agent, ...@@ -2485,29 +2604,36 @@ int agent_process_assoc_cntl_tlv(void *agent,
* per the validity period also need to check if the sta is all * per the validity period also need to check if the sta is all
* in the blocking list */ * in the blocking list */
ret = agent_check_start_validity_tmr(p->validity_period, p->sta_list_cnt, sta_list, fh); ret = agent_check_start_validity_tmr(p->validity_period, p->sta_list_cnt, sta_list, fh);
if (ret != 0) { if (ret != 0)
{
trace("[%s:%d] Error in start validity tmr\n", __func__, __LINE__); trace("[%s:%d] Error in start validity tmr\n", __func__, __LINE__);
return -1; return -1;
} }
} else if (p->assoc_control == 0x01) { }
else if (p->assoc_control == 0x01)
{
/*Here we will ignore the validity timer value in the request /*Here we will ignore the validity timer value in the request
* as the validity timer value is ignored in the unblock case */ * as the validity timer value is ignored in the unblock case */
/*Here we need to check if the validity timer is already running /*Here we need to check if the validity timer is already running
* in that case we need to stop the validity timer */ * in that case we need to stop the validity timer */
ret = agent_check_stop_validity_tmr(p->sta_list_cnt, sta_list, fh); ret = agent_check_stop_validity_tmr(p->sta_list_cnt, sta_list, fh);
if (ret != 0) { if (ret != 0)
{
trace("[%s:%d] Error in stop validity tmr\n", __func__, __LINE__); trace("[%s:%d] Error in stop validity tmr\n", __func__, __LINE__);
return -1; return -1;
} }
/*Here we need the logic to unblock the STA */ /*Here we need the logic to unblock the STA */
ret = agent_send_restrict_sta(agent, p->sta_list_cnt, ret = agent_send_restrict_sta(agent, p->sta_list_cnt,
sta_list, fh, p->assoc_control); sta_list, fh, p->assoc_control);
if (ret != 0) { if (ret != 0)
{
trace("[%s:%d] Error in agent_send_restrict_sta\n", __func__, __LINE__); trace("[%s:%d] Error in agent_send_restrict_sta\n", __func__, __LINE__);
return -1; return -1;
} }
} else { }
else
{
trace("[%s:%d] Reserved mode is called", __func__, __LINE__); trace("[%s:%d] Reserved mode is called", __func__, __LINE__);
} }
...@@ -2538,9 +2664,11 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, ...@@ -2538,9 +2664,11 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p,
trace("request_mode: %d\n", trace("request_mode: %d\n",
p->request_mode); p->request_mode);
if (p->request_mode == 0x00) { if (p->request_mode == 0x00)
{
/* Here we start the steer opportunity timer */ /* Here we start the steer opportunity timer */
if (a->is_sta_steer_start == 1) { if (a->is_sta_steer_start == 1)
{
trace("Error steering opportunity timer already running\n"); trace("Error steering opportunity timer already running\n");
return 1; return 1;
} }
...@@ -2549,7 +2677,8 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, ...@@ -2549,7 +2677,8 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p,
* Here we need to check the three conditions that needs to be * Here we need to check the three conditions that needs to be
* satisfied according to section 11.2 * satisfied according to section 11.2
*/ */
if (p->steer_opp_window == 0) { if (p->steer_opp_window == 0)
{
trace("Error steering opportunity timer value is zero\n"); trace("Error steering opportunity timer value is zero\n");
return 1; return 1;
} }
...@@ -2562,8 +2691,9 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, ...@@ -2562,8 +2691,9 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p,
a->is_sta_steer_start = 1; a->is_sta_steer_start = 1;
a->sta_steerlist_count = 0; a->sta_steerlist_count = 0;
uloop_timeout_set(&a->sta_steer_req_timer, p->steer_opp_window * 1000); uloop_timeout_set(&a->sta_steer_req_timer, p->steer_opp_window * 1000);
}
} else if (p->request_mode != 0x01) { else if (p->request_mode != 0x01)
{
trace("Invalid request mode"); trace("Invalid request mode");
return 1; return 1;
} }
...@@ -2596,9 +2726,11 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, ...@@ -2596,9 +2726,11 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p,
/* Here we validate if the sta is associated with the src bssid */ /* Here we validate if the sta is associated with the src bssid */
fh = get_netif_by_bssid(a, p->bssid); fh = get_netif_by_bssid(a, p->bssid);
if (!fh) { if (!fh)
{
trace("[%s:%d] Error BSSID not present", __func__, __LINE__); trace("[%s:%d] Error BSSID not present", __func__, __LINE__);
for (l = 0; l < p->sta_list_cnt; l++) { for (l = 0; l < p->sta_list_cnt; l++)
{
memcpy(sta_resp[count].sta_mac, p->steering_req_macs[l].addr, 6); memcpy(sta_resp[count].sta_mac, p->steering_req_macs[l].addr, 6);
sta_resp[count].response = 0x02; sta_resp[count].response = 0x02;
count++; count++;
...@@ -2611,8 +2743,10 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, ...@@ -2611,8 +2743,10 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p,
goto send_ack; goto send_ack;
/* Number of STAs and BSSIDs are equal, map STA to BSSID */ /* Number of STAs and BSSIDs are equal, map STA to BSSID */
if (p->sta_list_cnt > 0 && p->sta_list_cnt == p->target_bssid_list_cnt) { if (p->sta_list_cnt > 0 && p->sta_list_cnt == p->target_bssid_list_cnt)
for (l = 0; l < p->sta_list_cnt; l++) { {
for (l = 0; l < p->sta_list_cnt; l++)
{
trace("sta_addr: " MACFMT "\n", trace("sta_addr: " MACFMT "\n",
MAC2STR(p->steering_req_macs[l].addr)); MAC2STR(p->steering_req_macs[l].addr));
trace("target bssid: " MACFMT "\n", trace("target bssid: " MACFMT "\n",
...@@ -2627,26 +2761,30 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, ...@@ -2627,26 +2761,30 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p,
*/ */
present = 0; present = 0;
trace("count of error code sta %d\n", count); trace("count of error code sta %d\n", count);
for (m = 0; m < count; m++) { for (m = 0; m < count; m++)
{
trace("steer mac: " MACFMT "\n", trace("steer mac: " MACFMT "\n",
MAC2STR(p->steering_req_macs[l].addr)); MAC2STR(p->steering_req_macs[l].addr));
trace("sta error mac: " MACFMT "\n", trace("sta error mac: " MACFMT "\n",
MAC2STR(sta_resp[m].sta_mac)); MAC2STR(sta_resp[m].sta_mac));
res = memcmp(p->steering_req_macs[l].addr, res = memcmp(p->steering_req_macs[l].addr,
sta_resp[m].sta_mac, 6); sta_resp[m].sta_mac, 6);
if (res == 0) { if (res == 0)
{
present = 1; present = 1;
break; break;
} }
} }
if (present != 1) { if (present != 1)
{
/*Here we call for transition of sta*/ /*Here we call for transition of sta*/
ret = agent_transition_sta(a, p, fh, l, l); ret = agent_transition_sta(a, p, fh, l, l);
} }
} }
} }
/* Multiple STAs and single BSSID, send all STAs to same BSSID */ /* Multiple STAs and single BSSID, send all STAs to same BSSID */
else if (p->sta_list_cnt > 0 && p->target_bssid_list_cnt == 1) { else if (p->sta_list_cnt > 0 && p->target_bssid_list_cnt == 1)
{
trace("target bssid: " MACFMT "\n", trace("target bssid: " MACFMT "\n",
MAC2STR(p->steering_req_target_bssids[0].bssid)); MAC2STR(p->steering_req_target_bssids[0].bssid));
trace("op_class: %d\n", trace("op_class: %d\n",
...@@ -2654,7 +2792,8 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, ...@@ -2654,7 +2792,8 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p,
trace("channel: %d\n", trace("channel: %d\n",
p->steering_req_target_bssids[0].channel); p->steering_req_target_bssids[0].channel);
for (l = 0; l < p->sta_list_cnt; l++) { for (l = 0; l < p->sta_list_cnt; l++)
{
/* Here we need to call the ubus method */ /* Here we need to call the ubus method */
trace("sta_addr: " MACFMT "\n", trace("sta_addr: " MACFMT "\n",
MAC2STR(p->steering_req_macs[l].addr)); MAC2STR(p->steering_req_macs[l].addr));
...@@ -2663,15 +2802,18 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, ...@@ -2663,15 +2802,18 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p,
* the src bssid or not * the src bssid or not
*/ */
present = 0; present = 0;
for (m = 0; m < count; m++) { for (m = 0; m < count; m++)
{
res = memcmp(p->steering_req_macs[l].addr, res = memcmp(p->steering_req_macs[l].addr,
sta_resp[m].sta_mac, 6); sta_resp[m].sta_mac, 6);
if (res == 0) { if (res == 0)
{
present = 1; present = 1;
break; break;
} }
} }
if (present != 1) { if (present != 1)
{
/*Here we call for transition of sta*/ /*Here we call for transition of sta*/
ret = agent_transition_sta(a, p, fh, l, 0); ret = agent_transition_sta(a, p, fh, l, 0);
} }
...@@ -2681,21 +2823,28 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, ...@@ -2681,21 +2823,28 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p,
* No STA provided, Steering request applies to all associated STAs * No STA provided, Steering request applies to all associated STAs
* in the BSS, per policy setting. * in the BSS, per policy setting.
*/ */
else if (p->sta_list_cnt == 0 && p->target_bssid_list_cnt == 1) { else if (p->sta_list_cnt == 0 && p->target_bssid_list_cnt == 1)
{
result = memcmp(p->steering_req_target_bssids[0].bssid, wildcard, 6); result = memcmp(p->steering_req_target_bssids[0].bssid, wildcard, 6);
if (result == 0) { if (result == 0)
{
trace("[%s:%d] bssid id wildcard", __func__, __LINE__); trace("[%s:%d] bssid id wildcard", __func__, __LINE__);
ret = agent_search_bssid_for_sta(a, ret = agent_search_bssid_for_sta(a,
p->steering_req_macs[l].addr, wildcard_bssid, p->bssid); p->steering_req_macs[l].addr, wildcard_bssid, p->bssid);
if (ret != 0) { if (ret != 0)
list_for_each_entry(s, &fh->stalist, list) { {
list_for_each_entry(s, &fh->stalist, list)
{
ret = agent_send_request_transition( ret = agent_send_request_transition(
agent, s->macaddr, agent, s->macaddr,
fh, wildcard_bssid, 0); fh, wildcard_bssid, 0);
} }
} }
} else { }
list_for_each_entry(s, &fh->stalist, list) { else
{
list_for_each_entry(s, &fh->stalist, list)
{
ret = agent_send_request_transition( ret = agent_send_request_transition(
agent, s->macaddr, agent, s->macaddr,
fh, p->steering_req_target_bssids[0].bssid, 0); fh, p->steering_req_target_bssids[0].bssid, 0);
...@@ -2703,14 +2852,17 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, ...@@ -2703,14 +2852,17 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p,
} }
} }
/* No BSSID specified for the STAs */ /* No BSSID specified for the STAs */
else if (p->sta_list_cnt > 0 && p->target_bssid_list_cnt == 0) { else if (p->sta_list_cnt > 0 && p->target_bssid_list_cnt == 0)
if (p->request_mode != 0x00) { {
if (p->request_mode != 0x00)
{
trace("[%s:%d]Error steer mandate target BSSID not present\n", trace("[%s:%d]Error steer mandate target BSSID not present\n",
__func__, __LINE__); __func__, __LINE__);
return 1; return 1;
} }
trace("[%s:%d] target BSSID not present\n", __func__, __LINE__); trace("[%s:%d] target BSSID not present\n", __func__, __LINE__);
for (l = 0; l < p->sta_list_cnt; l++) { for (l = 0; l < p->sta_list_cnt; l++)
{
trace("sta_addr: " MACFMT "\n", trace("sta_addr: " MACFMT "\n",
MAC2STR(p->steering_req_macs[l].addr)); MAC2STR(p->steering_req_macs[l].addr));
/** /**
...@@ -2718,14 +2870,17 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, ...@@ -2718,14 +2870,17 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p,
* src bssid or not * src bssid or not
*/ */
present = 0; present = 0;
for (m = 0; m < count; m++) { for (m = 0; m < count; m++)
{
res = memcmp(p->steering_req_macs[l].addr, sta_resp[m].sta_mac, 6); res = memcmp(p->steering_req_macs[l].addr, sta_resp[m].sta_mac, 6);
if (res == 0) { if (res == 0)
{
present = 1; present = 1;
break; break;
} }
} }
if (present != 1) { if (present != 1)
{
/** /**
* Here we need to get the bssids that are best * Here we need to get the bssids that are best
* for the STAs in case of steering opportunity * for the STAs in case of steering opportunity
...@@ -2741,10 +2896,13 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, ...@@ -2741,10 +2896,13 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p,
} }
} }
/* No BSSID or STAs */ /* No BSSID or STAs */
else if (p->sta_list_cnt == 0 && p->target_bssid_list_cnt == 0) { else if (p->sta_list_cnt == 0 && p->target_bssid_list_cnt == 0)
{
trace("[%s:%d] Error No STA and target BSSID present\n", __func__, __LINE__); trace("[%s:%d] Error No STA and target BSSID present\n", __func__, __LINE__);
return 1; return 1;
} else { }
else
{
trace("[%s:%d] Error condition\n", __func__, __LINE__); trace("[%s:%d] Error condition\n", __func__, __LINE__);
return 1; return 1;
} }
...@@ -2763,10 +2921,13 @@ int handle_sta_steer_request(void *agent, struct cmdu_cstruct *cmdu) ...@@ -2763,10 +2921,13 @@ int handle_sta_steer_request(void *agent, struct cmdu_cstruct *cmdu)
uint8_t *tlv = NULL; uint8_t *tlv = NULL;
/* Here we first parse the steer request */ /* Here we first parse the steer request */
if (cmdu->num_tlvs != 0) { if (cmdu->num_tlvs != 0)
for (i = 0; i < cmdu->num_tlvs; i++) { {
for (i = 0; i < cmdu->num_tlvs; i++)
{
tlv = (uint8_t *)cmdu->tlvs[i]; tlv = (uint8_t *)cmdu->tlvs[i];
switch (*tlv) { switch (*tlv)
{
case MAP_TLV_STEERING_REQUEST: case MAP_TLV_STEERING_REQUEST:
{ {
struct tlv_steer_Req *p = struct tlv_steer_Req *p =
...@@ -2809,7 +2970,8 @@ int agent_transition_sta(struct agent *a, struct tlv_steer_Req *p, struct netif_ ...@@ -2809,7 +2970,8 @@ int agent_transition_sta(struct agent *a, struct tlv_steer_Req *p, struct netif_
hwaddr_aton(wildcard_str, wildcard); hwaddr_aton(wildcard_str, wildcard);
result = memcmp(p->steering_req_target_bssids[l].bssid, wildcard, 6); result = memcmp(p->steering_req_target_bssids[l].bssid, wildcard, 6);
if (result == 0) { if (result == 0)
{
/** /**
* code to search bssid as the bssid is a * code to search bssid as the bssid is a
* wildcard * wildcard
...@@ -2823,7 +2985,9 @@ int agent_transition_sta(struct agent *a, struct tlv_steer_Req *p, struct netif_ ...@@ -2823,7 +2985,9 @@ int agent_transition_sta(struct agent *a, struct tlv_steer_Req *p, struct netif_
ret = agent_send_request_transition(a, ret = agent_send_request_transition(a,
p->steering_req_macs[l].addr, p->steering_req_macs[l].addr,
fh, wildcard_bssid, 0); fh, wildcard_bssid, 0);
} else { }
else
{
ret = agent_send_request_transition(a, ret = agent_send_request_transition(a,
p->steering_req_macs[l].addr, p->steering_req_macs[l].addr,
fh, p->steering_req_target_bssids[m].bssid, 0); fh, p->steering_req_target_bssids[m].bssid, 0);
...@@ -2840,10 +3004,13 @@ int handle_sta_assoc_control_request(void *agent, struct cmdu_cstruct *cmdu) ...@@ -2840,10 +3004,13 @@ int handle_sta_assoc_control_request(void *agent, struct cmdu_cstruct *cmdu)
uint8_t *tlv = NULL; uint8_t *tlv = NULL;
/* Here we first parse the steer request */ /* Here we first parse the steer request */
if (cmdu->num_tlvs != 0) { if (cmdu->num_tlvs != 0)
for (i = 0; i < cmdu->num_tlvs; i++) { {
for (i = 0; i < cmdu->num_tlvs; i++)
{
tlv = (uint8_t *)cmdu->tlvs[i]; tlv = (uint8_t *)cmdu->tlvs[i];
switch (*tlv) { switch (*tlv)
{
case MAP_TLV_CLIENT_ASSOCIATION_CONTROL_REQUEST: case MAP_TLV_CLIENT_ASSOCIATION_CONTROL_REQUEST:
{ {
struct tlv_client_assoc_control_req *p = struct tlv_client_assoc_control_req *p =
...@@ -2887,7 +3054,8 @@ int handle_backhaul_sta_steer_request(void *agent, ...@@ -2887,7 +3054,8 @@ int handle_backhaul_sta_steer_request(void *agent,
cmdu = (struct cmdu_cstruct *)calloc(1, cmdu = (struct cmdu_cstruct *)calloc(1,
sizeof(struct cmdu_cstruct)); sizeof(struct cmdu_cstruct));
if (!cmdu) { if (!cmdu)
{
fprintf(stderr, "Out of memory!\n"); fprintf(stderr, "Out of memory!\n");
return -1; return -1;
} }
...@@ -3329,7 +3497,6 @@ static const map_cmdu_handler_t agent_mapftable[] = { ...@@ -3329,7 +3497,6 @@ static const map_cmdu_handler_t agent_mapftable[] = {
/* [0x33] = handle_failed_connection_msg, */ /* [0x33] = handle_failed_connection_msg, */
}; };
const char *tlv_friendlyname[] = { const char *tlv_friendlyname[] = {
"supported_service", "supported_service",
"searched_service", "searched_service",
...@@ -3399,7 +3566,6 @@ const char *tlv_friendlyname[] = { ...@@ -3399,7 +3566,6 @@ const char *tlv_friendlyname[] = {
"backhaul_bss_config", "backhaul_bss_config",
}; };
bool is_cmdu_for_us(struct agent *a, uint16_t type) bool is_cmdu_for_us(struct agent *a, uint16_t type)
{ {
// TODO: handle only cmdu types relevant for module's role/profile. // TODO: handle only cmdu types relevant for module's role/profile.
...@@ -3413,10 +3579,13 @@ bool is_cmdu_for_us(struct agent *a, uint16_t type) ...@@ -3413,10 +3579,13 @@ bool is_cmdu_for_us(struct agent *a, uint16_t type)
/* until then, the following should be okay.. */ /* until then, the following should be okay.. */
if (type >= CMDU_TYPE_1905_START && type <= CMDU_TYPE_1905_END) { if (type >= CMDU_TYPE_1905_START && type <= CMDU_TYPE_1905_END)
{
if (i1905ftable[type]) if (i1905ftable[type])
return true; return true;
} else if (type >= CMDU_TYPE_MAP_START && type <= CMDU_TYPE_MAP_END) { }
else if (type >= CMDU_TYPE_MAP_START && type <= CMDU_TYPE_MAP_END)
{
if (agent_mapftable[type - CMDU_TYPE_MAP_START]) if (agent_mapftable[type - CMDU_TYPE_MAP_START])
return true; return true;
} }
...@@ -3447,7 +3616,8 @@ static void send_cmdu_cb(struct ubus_request *req, ...@@ -3447,7 +3616,8 @@ static void send_cmdu_cb(struct ubus_request *req,
uint16_t *mid; uint16_t *mid;
char *str; char *str;
if (!msg || !req->priv) { if (!msg || !req->priv)
{
fprintf(stderr, "%s:Message recieved is NULL\n", __func__); fprintf(stderr, "%s:Message recieved is NULL\n", __func__);
return; return;
} }
...@@ -3455,7 +3625,8 @@ static void send_cmdu_cb(struct ubus_request *req, ...@@ -3455,7 +3625,8 @@ static void send_cmdu_cb(struct ubus_request *req,
mid = (uint16_t *)req->priv; mid = (uint16_t *)req->priv;
str = (char *)blobmsg_format_json_indent(msg, true, -1); str = (char *)blobmsg_format_json_indent(msg, true, -1);
if (str) { if (str)
{
jobj = json_tokener_parse(str); jobj = json_tokener_parse(str);
free(str); free(str);
} }
...@@ -3463,7 +3634,8 @@ static void send_cmdu_cb(struct ubus_request *req, ...@@ -3463,7 +3634,8 @@ static void send_cmdu_cb(struct ubus_request *req,
if (jobj == NULL) if (jobj == NULL)
return; return;
if (json_object_object_get_ex(jobj, "mid", &tmp)) { if (json_object_object_get_ex(jobj, "mid", &tmp))
{
*mid = json_object_get_int(tmp); *mid = json_object_get_int(tmp);
fprintf(stdout, "%s:%d agent map-mid:%d\n", __func__, __LINE__, *mid); fprintf(stdout, "%s:%d agent map-mid:%d\n", __func__, __LINE__, *mid);
} }
...@@ -3503,14 +3675,18 @@ uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu) ...@@ -3503,14 +3675,18 @@ uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu)
trace("|%s:%d|cmdu:%s|egress:%s|dst:%s|\n", __func__, __LINE__, trace("|%s:%d|cmdu:%s|egress:%s|dst:%s|\n", __func__, __LINE__,
map_stringify_cmdu_type(cmdu->message_type), map_stringify_cmdu_type(cmdu->message_type),
cmdu->intf_name, dst_addr); cmdu->intf_name, dst_addr);
if (cmdu->num_tlvs > 0) { if (cmdu->num_tlvs > 0)
for (i = 0; i < cmdu->num_tlvs; i++) { {
for (i = 0; i < cmdu->num_tlvs; i++)
{
len = 0; len = 0;
ss = map_put_tlv_cstruct(cmdu->tlvs[i], &len); ss = map_put_tlv_cstruct(cmdu->tlvs[i], &len);
if (ss) { if (ss)
{
tlv_str = (char *)calloc((2 * len) + 1, tlv_str = (char *)calloc((2 * len) + 1,
sizeof(char)); sizeof(char));
if (!tlv_str) { if (!tlv_str)
{
free(ss); free(ss);
goto out; goto out;
} }
...@@ -3520,7 +3696,8 @@ uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu) ...@@ -3520,7 +3696,8 @@ uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu)
tlv_data_len += tlv_str_len; tlv_data_len += tlv_str_len;
tlv_data = realloc(tlv_data, tlv_data = realloc(tlv_data,
tlv_data_len * sizeof(char)); tlv_data_len * sizeof(char));
if (!tlv_data) { if (!tlv_data)
{
fprintf(stderr, "%s:%d out of memory.!\n", fprintf(stderr, "%s:%d out of memory.!\n",
__func__, __LINE__); __func__, __LINE__);
free(ss); free(ss);
...@@ -3543,16 +3720,18 @@ uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu) ...@@ -3543,16 +3720,18 @@ uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu)
} }
} }
if (ubus_lookup_id(a->ubus_ctx, "map.1905", &id)) { if (ubus_lookup_id(a->ubus_ctx, "map.1905", &id))
{
trace("[%s:%d] not present", __func__, __LINE__); trace("[%s:%d] not present", __func__, __LINE__);
goto out; goto out;
} }
log_cmdu(cmdu, false);
ret = ubus_invoke(a->ubus_ctx, id, "send", ret = ubus_invoke(a->ubus_ctx, id, "send",
b.head, send_cmdu_cb, b.head, send_cmdu_cb,
(void *)&msgid, (void *)&msgid,
UBUS_TIMEOUT); UBUS_TIMEOUT);
if (ret) { if (ret)
{
trace("[%s:%d] ubus call failed for |map.1905 send|", trace("[%s:%d] ubus call failed for |map.1905 send|",
__func__, __LINE__); __func__, __LINE__);
goto out; goto out;
...@@ -3575,21 +3754,28 @@ int agent_handle_map_event(struct agent *a, uint16_t cmdutype, uint16_t mid, ...@@ -3575,21 +3754,28 @@ int agent_handle_map_event(struct agent *a, uint16_t cmdutype, uint16_t mid,
trace("%s: ---> cmdu = %d\n", __func__, cmdutype); trace("%s: ---> cmdu = %d\n", __func__, cmdutype);
if (cmdutype >= CMDU_TYPE_MAP_START) { if (cmdutype >= CMDU_TYPE_MAP_START)
{
idx = cmdutype - CMDU_TYPE_MAP_START; idx = cmdutype - CMDU_TYPE_MAP_START;
f = agent_mapftable; f = agent_mapftable;
} else { }
else
{
idx = cmdutype; idx = cmdutype;
f = i1905ftable; f = i1905ftable;
} }
if (f[idx]) { if (f[idx])
{
cmdu = map_build_cmdu(cmdutype, mid, rxif, src, tlvs); cmdu = map_build_cmdu(cmdutype, mid, rxif, src, tlvs);
if (cmdu) { if (cmdu)
test_cmdu(cmdu); {
log_cmdu(cmdu, true);
ret = f[idx](a, cmdu); ret = f[idx](a, cmdu);
map_free_cmdu(cmdu); map_free_cmdu(cmdu);
} else { }
else
{
dbg("agent: %s: map_build_cmdu() failed!\n", __func__); dbg("agent: %s: map_build_cmdu() failed!\n", __func__);
} }
} }
... ...
......
...@@ -40,9 +40,12 @@ void start_logging(void) ...@@ -40,9 +40,12 @@ void start_logging(void)
if (syslogging) if (syslogging)
openlog(PROG_NAME, 0, LOG_DAEMON); openlog(PROG_NAME, 0, LOG_DAEMON);
if (!outfile) { if (!outfile)
if (outfile_path) { {
if (usefifo) { if (outfile_path)
{
if (usefifo)
{
struct stat st; struct stat st;
int rfd; int rfd;
...@@ -55,15 +58,20 @@ void start_logging(void) ...@@ -55,15 +58,20 @@ void start_logging(void)
return; return;
rfd = open(outfile_path, rfd = open(outfile_path,
O_RDONLY | O_NONBLOCK); O_RDONLY | O_NONBLOCK);
if (rfd) { if (rfd)
{
ffd = open(outfile_path, ffd = open(outfile_path,
O_WRONLY | O_NONBLOCK); O_WRONLY | O_NONBLOCK);
close(rfd); close(rfd);
} }
} else { }
else
{
outfile = fopen(outfile_path, "w+"); outfile = fopen(outfile_path, "w+");
} }
} else { }
else
{
outfile = stderr; outfile = stderr;
} }
} }
...@@ -77,7 +85,8 @@ void stop_logging(void) ...@@ -77,7 +85,8 @@ void stop_logging(void)
if (outfile) if (outfile)
fclose(outfile); fclose(outfile);
if (ffd) { if (ffd)
{
close(ffd); close(ffd);
unlink(outfile_path); unlink(outfile_path);
} }
...@@ -87,8 +96,10 @@ void log_message(int level, const char *fmt, ...) ...@@ -87,8 +96,10 @@ void log_message(int level, const char *fmt, ...)
{ {
va_list args; va_list args;
if (level > verbose) { if (level > verbose)
if (usefifo && ffd) { {
if (usefifo && ffd)
{
time_t now = time(NULL); time_t now = time(NULL);
struct tm *tm_now = localtime(&now); struct tm *tm_now = localtime(&now);
const char *tm_fmt = "[%d-%02d-%02d %02d:%02d:%02d] "; const char *tm_fmt = "[%d-%02d-%02d %02d:%02d:%02d] ";
...@@ -127,7 +138,8 @@ void dump(unsigned char *buf, int len, char *label) ...@@ -127,7 +138,8 @@ void dump(unsigned char *buf, int len, char *label)
if (label) if (label)
printf("---- %s ----", label); printf("---- %s ----", label);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++)
{
if (!(i % 4)) if (!(i % 4))
printf(" "); printf(" ");
if (!(i % 16)) if (!(i % 16))
...@@ -142,9 +154,12 @@ void dump(unsigned char *buf, int len, char *label) ...@@ -142,9 +154,12 @@ void dump(unsigned char *buf, int len, char *label)
// TODO: duplicate of start_logging // TODO: duplicate of start_logging
void start_test_logging(void) void start_test_logging(void)
{ {
if (!testfile) { if (!testfile)
if (testfile_path) { {
if (usefifo) { if (testfile_path)
{
if (usefifo)
{
struct stat st; struct stat st;
int rfd; int rfd;
...@@ -158,15 +173,20 @@ void start_test_logging(void) ...@@ -158,15 +173,20 @@ void start_test_logging(void)
rfd = open(testfile_path, rfd = open(testfile_path,
O_RDONLY | O_NONBLOCK); O_RDONLY | O_NONBLOCK);
if (rfd) { if (rfd)
{
tfd = open(testfile_path, tfd = open(testfile_path,
O_WRONLY | O_NONBLOCK); O_WRONLY | O_NONBLOCK);
close(rfd); close(rfd);
} }
} else { }
else
{
testfile = fopen(testfile_path, "w+"); testfile = fopen(testfile_path, "w+");
} }
} else { }
else
{
testfile = stderr; testfile = stderr;
} }
} }
...@@ -177,7 +197,8 @@ void stop_test_logging(void) ...@@ -177,7 +197,8 @@ void stop_test_logging(void)
if (testfile) if (testfile)
fclose(testfile); fclose(testfile);
if (tfd) { if (tfd)
{
close(tfd); close(tfd);
unlink(testfile_path); unlink(testfile_path);
} }
...@@ -201,23 +222,65 @@ void log_test(int level, void *var, int len) ...@@ -201,23 +222,65 @@ void log_test(int level, void *var, int len)
free(bstr); free(bstr);
} }
void log_cmdu(int level, void *var) void _log_cmdu(int level, void *var, bool flag)
{ {
struct cmdu_cstruct *cmdu = (struct cmdu_cstruct *)var; struct cmdu_cstruct *cmdu = (struct cmdu_cstruct *)var;
struct json_object *msgversion, *msgtype, *msgid, *msg;
struct json_object *intfname, *tlvarray, *direction;
struct json_object *main_object;
char *bstr;
int i; int i;
main_object = json_object_new_object();
tlvarray = json_object_new_array();
if (level > verbose) if (level > verbose)
return; return;
for (i = 0; i < cmdu->num_tlvs; i++) { for (i = 0; i < cmdu->num_tlvs; i++)
{
uint16_t len; uint16_t len;
uint8_t *btlv; uint8_t *btlv;
struct json_object *tlv;
struct json_object *tlv_type;
struct json_object *tlv_object;
tlv_object = json_object_new_object();
uint8_t *type;
btlv = map_put_tlv_cstruct(cmdu->tlvs[i], &len); btlv = map_put_tlv_cstruct(cmdu->tlvs[i], &len);
type = cmdu->tlvs[i];
if (!btlv) if (!btlv)
continue; continue;
bstr = calloc(1, (len * 2) + 1);
log_test(level, btlv, len); if (!bstr)
return;
btostr(btlv, len, bstr);
tlv = json_object_new_string(bstr);
tlv_type = json_object_new_string(map_stringify_tlv_type(*type));
json_object_object_add(tlv_object, "data", tlv);
json_object_object_add(tlv_object, "type", tlv_type);
json_object_array_add(tlvarray, tlv_object);
free(btlv); free(btlv);
free(bstr);
} }
msgversion = json_object_new_int(cmdu->message_version);
msgtype = json_object_new_int(cmdu->message_type);
direction = json_object_new_boolean(flag);
msgid = json_object_new_int(cmdu->message_id);
intfname = json_object_new_string(cmdu->intf_name);
msg = json_object_new_string(map_stringify_cmdu_type(cmdu->message_type));
json_object_object_add(main_object, "message_version", msgversion);
json_object_object_add(main_object, "message_type", msgtype);
json_object_object_add(main_object, "message_id", msgid);
json_object_object_add(main_object, "interface_name", intfname);
json_object_object_add(main_object, "message", msg);
json_object_object_add(main_object, "direction", direction);
json_object_object_add(main_object, "tlvs", tlvarray);
fprintf(testfile, "%s\n", json_object_to_json_string(main_object));
fflush(testfile);
json_object_put(main_object);
} }
\ No newline at end of file
...@@ -18,7 +18,7 @@ void start_test_logging(void); ...@@ -18,7 +18,7 @@ void start_test_logging(void);
void stop_test_logging(void); void stop_test_logging(void);
void log_message(int level, const char *fmt, ...); void log_message(int level, const char *fmt, ...);
void log_test(int level, void *var, int len); void log_test(int level, void *var, int len);
void log_cmdu(int level, void *var); void _log_cmdu(int level, void *var, bool flag);
#define DEBUG_COLOR 1 #define DEBUG_COLOR 1
...@@ -45,7 +45,7 @@ void log_cmdu(int level, void *var); ...@@ -45,7 +45,7 @@ void log_cmdu(int level, void *var);
#define loud(fmt, ...) log_message(5, fmt, ## __VA_ARGS__) #define loud(fmt, ...) log_message(5, fmt, ## __VA_ARGS__)
//#define test(fmt, ...) log_test(6, fmt, ## __VA_ARGS__) //#define test(fmt, ...) log_test(6, fmt, ## __VA_ARGS__)
#define test(var, len) log_test(6, var, len) #define test(var, len) log_test(6, var, len)
#define test_cmdu(var) log_cmdu(6, var) #define log_cmdu(var, flag) _log_cmdu(6, var, flag)
#else #else
#define logrec(...) log_message(-1, __VA_ARGS__) #define logrec(...) log_message(-1, __VA_ARGS__)
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment