wireless_device_create(drv, s->e.name, b.head);
}
-static struct wireless_interface*
-config_parse_wireless_interface(struct wireless_device *wdev, struct uci_section *s)
+static void
+config_parse_wireless_vlan(struct wireless_interface *vif, struct uci_section *s)
{
char *name;
sprintf(name, "@%s[%d]", s->type, config_section_idx(s));
blob_buf_init(&b, 0);
- uci_to_blob(&b, s, wdev->drv->interface.config);
- return wireless_interface_create(wdev, b.head, s->anonymous ? name : s->e.name);
+ uci_to_blob(&b, s, vif->wdev->drv->vlan.config);
+ wireless_vlan_create(vif, b.head, s->anonymous ? name : s->e.name);
}
static void
-config_parse_wireless_vlan(struct wireless_device *wdev, char *vif, struct uci_section *s)
+config_parse_wireless_station(struct wireless_interface *vif, struct uci_section *s)
{
char *name;
sprintf(name, "@%s[%d]", s->type, config_section_idx(s));
blob_buf_init(&b, 0);
- uci_to_blob(&b, s, wdev->drv->vlan.config);
- wireless_vlan_create(wdev, vif, b.head, s->anonymous ? name : s->e.name);
+ uci_to_blob(&b, s, vif->wdev->drv->station.config);
+ wireless_station_create(vif, b.head, s->anonymous ? name : s->e.name);
}
static void
-config_parse_wireless_station(struct wireless_device *wdev, char *vif, struct uci_section *s)
+config_parse_wireless_interface(struct wireless_device *wdev, struct uci_section *s)
{
+ struct wireless_interface *vif;
+ struct uci_element *f;
char *name;
name = alloca(strlen(s->type) + 16);
sprintf(name, "@%s[%d]", s->type, config_section_idx(s));
blob_buf_init(&b, 0);
- uci_to_blob(&b, s, wdev->drv->station.config);
- wireless_station_create(wdev, vif, b.head, s->anonymous ? name : s->e.name);
+ uci_to_blob(&b, s, wdev->drv->interface.config);
+ vif = wireless_interface_create(wdev, b.head, s->anonymous ? name : s->e.name);
+ if (!vif)
+ return;
+
+ vif->vlan_idx = vif->sta_idx = 0;
+ vlist_update(&vif->vlans);
+ vlist_update(&vif->stations);
+
+ if (s->anonymous)
+ goto out;
+
+ uci_foreach_element(&uci_wireless->sections, f) {
+ struct uci_section *cur = uci_to_section(f);
+ const char *vif_name;
+
+ if (strcmp(cur->type, "wifi-vlan") != 0)
+ continue;
+
+ vif_name = uci_lookup_option_string(uci_ctx, cur, "iface");
+ if (vif_name && strcmp(s->e.name, vif_name))
+ continue;
+ config_parse_wireless_vlan(vif, cur);
+ }
+
+ uci_foreach_element(&uci_wireless->sections, f) {
+ struct uci_section *cur = uci_to_section(f);
+ const char *vif_name;
+
+ if (strcmp(cur->type, "wifi-station") != 0)
+ continue;
+
+ vif_name = uci_lookup_option_string(uci_ctx, cur, "iface");
+ if (vif_name && strcmp(s->e.name, vif_name))
+ continue;
+ config_parse_wireless_station(vif, cur);
+ }
+
+out:
+ vlist_flush(&vif->vlans);
+ vlist_flush(&vif->stations);
}
static void
vlist_for_each_element(&wireless_devices, wdev, node) {
wdev->vif_idx = 0;
vlist_update(&wdev->interfaces);
- wdev->vlan_idx = 0;
- vlist_update(&wdev->vlans);
- wdev->sta_idx = 0;
- vlist_update(&wdev->stations);
}
uci_foreach_element(&uci_wireless->sections, e) {
struct uci_section *s = uci_to_section(e);
- struct wireless_interface *vif;
- struct uci_element *f;
if (strcmp(s->type, "wifi-iface") != 0)
continue;
continue;
}
- vif = config_parse_wireless_interface(wdev, s);
-
- if (!vif || s->anonymous)
- continue;
- uci_foreach_element(&uci_wireless->sections, f) {
- struct uci_section *s = uci_to_section(f);
- const char *vif_name;
-
- if (strcmp(s->type, "wifi-vlan") != 0)
- continue;
-
- vif_name = uci_lookup_option_string(uci_ctx, s, "iface");
- if (vif_name && strcmp(e->name, vif_name))
- continue;
- config_parse_wireless_vlan(wdev, vif->name, s);
- }
-
- uci_foreach_element(&uci_wireless->sections, f) {
- struct uci_section *s = uci_to_section(f);
- const char *vif_name;
-
- if (strcmp(s->type, "wifi-station") != 0)
- continue;
-
- vif_name = uci_lookup_option_string(uci_ctx, s, "iface");
- if (vif_name && strcmp(e->name, vif_name))
- continue;
- config_parse_wireless_station(wdev, vif->name, s);
- }
+ config_parse_wireless_interface(wdev, s);
}
- vlist_for_each_element(&wireless_devices, wdev, node) {
+ vlist_for_each_element(&wireless_devices, wdev, node)
vlist_flush(&wdev->interfaces);
- vlist_flush(&wdev->vlans);
- vlist_flush(&wdev->stations);
- }
}
blobmsg_add_blob(&b, vif->data);
j = blobmsg_open_table(&b, "vlans");
- vlist_for_each_element(&wdev->vlans, vlan, node) {
- if (strcmp(vlan->vif, vif->name))
- continue;
+ vlist_for_each_element(&vif->vlans, vlan, node) {
k = blobmsg_open_table(&b, vlan->name);
vif_config_add_bridge(&b, vlan->network, up);
put_container(&b, vlan->config, "config");
blobmsg_close_table(&b, j);
j = blobmsg_open_table(&b, "stas");
- vlist_for_each_element(&wdev->stations, sta, node) {
- if (strcmp(sta->vif, vif->name))
- continue;
+ vlist_for_each_element(&vif->stations, sta, node) {
k = blobmsg_open_table(&b, sta->name);
put_container(&b, sta->config, "config");
if (sta->data)
free(vif->data);
vif->data = NULL;
vif->ifname = NULL;
- }
- vlist_for_each_element(&wdev->vlans, vlan, node) {
- free(vlan->data);
- vlan->data = NULL;
- vlan->ifname = NULL;
- }
- vlist_for_each_element(&wdev->stations, sta, node) {
- free(sta->data);
- sta->data = NULL;
+ vlist_for_each_element(&vif->vlans, vlan, node) {
+ free(vlan->data);
+ vlan->data = NULL;
+ vlan->ifname = NULL;
+ }
+ vlist_for_each_element(&vif->stations, sta, node) {
+ free(sta->data);
+ sta->data = NULL;
+ }
}
}
{
wireless_handler_stop(wdev);
vlist_flush_all(&wdev->interfaces);
- vlist_flush_all(&wdev->vlans);
- vlist_flush_all(&wdev->stations);
avl_delete(&wireless_devices.avl, &wdev->node.avl);
free(wdev->config);
free(wdev->prev_config);
netifd_log_message(L_NOTICE, "Wireless device '%s' is now down\n", wdev->name);
- vlist_for_each_element(&wdev->vlans, vlan, node)
- wireless_vlan_handle_link(vlan, false);
- vlist_for_each_element(&wdev->interfaces, vif, node)
+ vlist_for_each_element(&wdev->interfaces, vif, node) {
wireless_interface_handle_link(vif, NULL, false);
+ vlist_for_each_element(&vif->vlans, vlan, node)
+ wireless_vlan_handle_link(vlan, false);
+ }
wireless_process_kill_all(wdev, SIGTERM, true);
netifd_log_message(L_NOTICE, "Wireless device '%s' is now up\n", wdev->name);
wdev->retry = WIRELESS_SETUP_RETRY;
wdev->state = IFS_UP;
- vlist_for_each_element(&wdev->interfaces, vif, node)
+ vlist_for_each_element(&wdev->interfaces, vif, node) {
wireless_interface_handle_link(vif, NULL, true);
- vlist_for_each_element(&wdev->vlans, vlan, node)
- wireless_vlan_handle_link(vlan, true);
+ vlist_for_each_element(&vif->vlans, vlan, node)
+ wireless_vlan_handle_link(vlan, true);
+ }
}
static void
vif->multicast_to_unicast = cur ? blobmsg_get_bool(cur) : -1;
}
+static void
+vif_free(struct wireless_interface *vif)
+{
+ vlist_flush_all(&vif->vlans);
+ vlist_flush_all(&vif->stations);
+ free((void *) vif->section);
+ free(vif->config);
+ free(vif);
+}
+
/* vlist update call for wireless interface list */
static void
vif_update(struct vlist_tree *tree, struct vlist_node *node_new,
} else if (vif_old) {
D(WIRELESS, "Delete wireless interface %s on device %s\n", vif_old->name, wdev->name);
wireless_interface_handle_link(vif_old, NULL, false);
- free((void *) vif_old->section);
- free(vif_old->config);
- free(vif_old);
+ vif_free(vif_old);
}
wdev->config_update = true;
vlan_update(struct vlist_tree *tree, struct vlist_node *node_new,
struct vlist_node *node_old)
{
- struct wireless_vlan *vlan_old = container_of(node_old, struct wireless_vlan, node);
- struct wireless_vlan *vlan_new = container_of(node_new, struct wireless_vlan, node);
- struct wireless_device *wdev;
-
- if (vlan_old)
- wdev = vlan_old->wdev;
- else
- wdev = vlan_new->wdev;
+ struct wireless_vlan *vlan_old = container_of_safe(node_old, struct wireless_vlan, node);
+ struct wireless_vlan *vlan_new = container_of_safe(node_new, struct wireless_vlan, node);
+ struct wireless_interface *vif = container_of(tree, struct wireless_interface, vlans);
+ struct wireless_device *wdev = vif->wdev;
if (vlan_old && vlan_new) {
free((void *) vlan_old->section);
vlan_new->config = blob_memdup(vlan_new->config);
wireless_vlan_init_config(vlan_new);
} else if (vlan_old) {
- D(WIRELESS, "Delete wireless interface %s on device %s\n", vlan_old->name, wdev->name);
+ D(WIRELESS, "Delete wireless vlan %s on device %s\n", vlan_old->name, wdev->name);
wireless_vlan_handle_link(vlan_old, false);
free((void *) vlan_old->section);
free(vlan_old->config);
station_update(struct vlist_tree *tree, struct vlist_node *node_new,
struct vlist_node *node_old)
{
- struct wireless_station *sta_old = container_of(node_old, struct wireless_station, node);
- struct wireless_station *sta_new = container_of(node_new, struct wireless_station, node);
- struct wireless_device *wdev;
-
- if (sta_old)
- wdev = sta_old->wdev;
- else
- wdev = sta_new->wdev;
+ struct wireless_station *sta_old = container_of_safe(node_old, struct wireless_station, node);
+ struct wireless_station *sta_new = container_of_safe(node_new, struct wireless_station, node);
+ struct wireless_interface *vif = container_of(tree, struct wireless_interface, stations);
+ struct wireless_device *wdev = vif->wdev;
if (sta_old && sta_new) {
free((void *) sta_old->section);
INIT_LIST_HEAD(&wdev->script_proc);
vlist_init(&wdev->interfaces, avl_strcmp, vif_update);
wdev->interfaces.keep_old = true;
- vlist_init(&wdev->vlans, avl_strcmp, vlan_update);
- wdev->vlans.keep_old = true;
- vlist_init(&wdev->stations, avl_strcmp, station_update);
- wdev->stations.keep_old = true;
wdev->timeout.cb = wireless_device_setup_timeout;
wdev->script_task.cb = wireless_device_script_task_cb;
/* creates a wireless station object. Called by config */
void
-wireless_station_create(struct wireless_device *wdev, char *vif, struct blob_attr *data, const char *section)
+wireless_station_create(struct wireless_interface *vif, struct blob_attr *data, const char *section)
{
struct wireless_station *sta;
struct blob_attr *tb[__STA_ATTR_MAX];
struct blob_attr *cur;
- char *name_buf, *vif_buf;
+ char *name_buf;
char name[8];
blobmsg_parse(sta_policy, __STA_ATTR_MAX, tb, blob_data(data), blob_len(data));
if (cur && blobmsg_get_bool(cur))
return;
- sprintf(name, "%d", wdev->sta_idx++);
+ sprintf(name, "%d", vif->sta_idx++);
sta = calloc_a(sizeof(*sta),
- &name_buf, strlen(name) + 1,
- &vif_buf, strlen(vif) + 1);
+ &name_buf, strlen(name) + 1);
sta->name = strcpy(name_buf, name);
- sta->vif = strcpy(vif_buf, vif);
- sta->wdev = wdev;
sta->config = data;
sta->section = section;
- vlist_add(&wdev->stations, &sta->node, sta->name);
+ vlist_add(&vif->stations, &sta->node, sta->name);
}
/* ubus callback network.wireless.status, runs for every interface, encode the station */
/* create a vlan object. Called by config */
void
-wireless_vlan_create(struct wireless_device *wdev, char *vif, struct blob_attr *data, const char *section)
+wireless_vlan_create(struct wireless_interface *vif, struct blob_attr *data, const char *section)
{
struct wireless_vlan *vlan;
struct blob_attr *tb[__VLAN_ATTR_MAX];
struct blob_attr *cur;
- char *name_buf, *vif_buf;
+ char *name_buf;
char name[8];
blobmsg_parse(vlan_policy, __VLAN_ATTR_MAX, tb, blob_data(data), blob_len(data));
if (cur && blobmsg_get_bool(cur))
return;
- sprintf(name, "%d", wdev->vlan_idx++);
+ sprintf(name, "%d", vif->vlan_idx++);
- vlan = calloc_a(sizeof(*vlan),
- &name_buf, strlen(name) + 1,
- &vif_buf, strlen(vif) + 1);
+ vlan = calloc_a(sizeof(*vlan), &name_buf, strlen(name) + 1);
vlan->name = strcpy(name_buf, name);
- vlan->vif = strcpy(vif_buf, vif);
- vlan->wdev = wdev;
vlan->config = data;
vlan->section = section;
- vlan->isolate = false;
- vlist_add(&wdev->vlans, &vlan->node, vlan->name);
+ vlist_add(&vif->vlans, &vlan->node, vlan->name);
}
/* ubus callback network.wireless.status, runs for every interface, encode the vlan informations */
vif->section = section;
vif->isolate = false;
+ vlist_init(&vif->vlans, avl_strcmp, vlan_update);
+ vif->vlans.keep_old = true;
+
+ vlist_init(&vif->stations, avl_strcmp, station_update);
+ vif->stations.keep_old = true;
+
vlist_add(&wdev->interfaces, &vif->node, vif->name);
return vlist_find(&wdev->interfaces, name, vif, node);
blobmsg_add_string(b, "ifname", iface->ifname);
put_container(b, iface->config, "config");
j = blobmsg_open_array(b, "vlans");
- vlist_for_each_element(&iface->wdev->vlans, vlan, node)
- if (!strcmp(iface->name, vlan->vif))
- wireless_vlan_status(vlan, b);
+ vlist_for_each_element(&iface->vlans, vlan, node)
+ wireless_vlan_status(vlan, b);
blobmsg_close_array(b, j);
j = blobmsg_open_array(b, "stations");
- vlist_for_each_element(&iface->wdev->stations, sta, node)
- if (!strcmp(iface->name, sta->vif))
- wireless_station_status(sta, b);
+ vlist_for_each_element(&iface->stations, sta, node)
+ wireless_station_status(sta, b);
blobmsg_close_array(b, j);
blobmsg_close_table(b, i);
}
}
if ((cur = tb[NOTIFY_ATTR_VLAN]) != NULL) {
- vlan = vlist_find(&wdev->vlans, blobmsg_data(cur), vlan, node);
+ if (!vif)
+ return UBUS_STATUS_NOT_FOUND;
+ vlan = vlist_find(&vif->vlans, blobmsg_data(cur), vlan, node);
if (!vlan)
return UBUS_STATUS_NOT_FOUND;
}
wireless_device_mark_up(wdev);
break;
case NOTIFY_CMD_SET_DATA:
- if (vif)
- pdata = &vif->data;
- else if (vlan)
+ if (vlan)
pdata = &vlan->data;
+ else if (vif)
+ pdata = &vif->data;
else
pdata = &wdev->data;
free(*pdata);
*pdata = blob_memdup(cur);
- if (vif)
- wireless_interface_set_data(vif);
- else if (vlan)
+ if (vlan)
wireless_vlan_set_data(vlan);
+ else if (vif)
+ wireless_interface_set_data(vif);
break;
case NOTIFY_CMD_PROCESS_ADD:
return wireless_device_add_process(wdev, cur);