nl80211: Use shared code for netlink initialization
This commit is contained in:
parent
7da3abe711
commit
9fff9fdcf9
1 changed files with 55 additions and 84 deletions
|
@ -1007,28 +1007,12 @@ static void wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data *drv,
|
||||||
* wpa_driver_nl80211_init - Initialize nl80211 driver interface
|
void *ctx)
|
||||||
* @ctx: context to be used when calling wpa_supplicant functions,
|
|
||||||
* e.g., wpa_supplicant_event()
|
|
||||||
* @ifname: interface name, e.g., wlan0
|
|
||||||
* Returns: Pointer to private data, %NULL on failure
|
|
||||||
*/
|
|
||||||
static void * wpa_driver_nl80211_init(void *ctx, const char *ifname)
|
|
||||||
{
|
{
|
||||||
int s, ret;
|
int ret;
|
||||||
struct sockaddr_nl local;
|
|
||||||
struct wpa_driver_nl80211_data *drv;
|
|
||||||
|
|
||||||
drv = os_zalloc(sizeof(*drv));
|
/* Initialize generic netlink and nl80211 */
|
||||||
if (drv == NULL)
|
|
||||||
return NULL;
|
|
||||||
drv->ctx = ctx;
|
|
||||||
os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
|
|
||||||
#ifdef CONFIG_AP
|
|
||||||
drv->monitor_ifidx = -1;
|
|
||||||
drv->monitor_sock = -1;
|
|
||||||
#endif /* CONFIG_AP */
|
|
||||||
|
|
||||||
drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
|
drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
|
||||||
if (drv->nl_cb == NULL) {
|
if (drv->nl_cb == NULL) {
|
||||||
|
@ -1050,12 +1034,21 @@ static void * wpa_driver_nl80211_init(void *ctx, const char *ifname)
|
||||||
goto err3;
|
goto err3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_LIBNL20
|
||||||
|
if (genl_ctrl_alloc_cache(drv->nl_handle, &drv->nl_cache) < 0) {
|
||||||
|
wpa_printf(MSG_ERROR, "nl80211: Failed to allocate generic "
|
||||||
|
"netlink cache");
|
||||||
|
goto err3;
|
||||||
|
}
|
||||||
|
#else /* CONFIG_LIBNL20 */
|
||||||
drv->nl_cache = genl_ctrl_alloc_cache(drv->nl_handle);
|
drv->nl_cache = genl_ctrl_alloc_cache(drv->nl_handle);
|
||||||
if (drv->nl_cache == NULL) {
|
if (drv->nl_cache == NULL) {
|
||||||
wpa_printf(MSG_ERROR, "nl80211: Failed to allocate generic "
|
wpa_printf(MSG_ERROR, "nl80211: Failed to allocate generic "
|
||||||
"netlink cache");
|
"netlink cache");
|
||||||
goto err3;
|
goto err3;
|
||||||
}
|
}
|
||||||
|
#endif /* CONFIG_LIBNL20 */
|
||||||
|
|
||||||
|
|
||||||
drv->nl80211 = genl_ctrl_search_by_name(drv->nl_cache, "nl80211");
|
drv->nl80211 = genl_ctrl_search_by_name(drv->nl_cache, "nl80211");
|
||||||
if (drv->nl80211 == NULL) {
|
if (drv->nl80211 == NULL) {
|
||||||
|
@ -1083,11 +1076,51 @@ static void * wpa_driver_nl80211_init(void *ctx, const char *ifname)
|
||||||
ret, strerror(-ret));
|
ret, strerror(-ret));
|
||||||
goto err4;
|
goto err4;
|
||||||
}
|
}
|
||||||
drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
|
|
||||||
|
|
||||||
eloop_register_read_sock(nl_socket_get_fd(drv->nl_handle),
|
eloop_register_read_sock(nl_socket_get_fd(drv->nl_handle),
|
||||||
wpa_driver_nl80211_event_receive, drv, ctx);
|
wpa_driver_nl80211_event_receive, drv, ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
err4:
|
||||||
|
nl_cache_free(drv->nl_cache);
|
||||||
|
err3:
|
||||||
|
nl_handle_destroy(drv->nl_handle);
|
||||||
|
err2:
|
||||||
|
nl_cb_put(drv->nl_cb);
|
||||||
|
err1:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wpa_driver_nl80211_init - Initialize nl80211 driver interface
|
||||||
|
* @ctx: context to be used when calling wpa_supplicant functions,
|
||||||
|
* e.g., wpa_supplicant_event()
|
||||||
|
* @ifname: interface name, e.g., wlan0
|
||||||
|
* Returns: Pointer to private data, %NULL on failure
|
||||||
|
*/
|
||||||
|
static void * wpa_driver_nl80211_init(void *ctx, const char *ifname)
|
||||||
|
{
|
||||||
|
int s;
|
||||||
|
struct sockaddr_nl local;
|
||||||
|
struct wpa_driver_nl80211_data *drv;
|
||||||
|
|
||||||
|
drv = os_zalloc(sizeof(*drv));
|
||||||
|
if (drv == NULL)
|
||||||
|
return NULL;
|
||||||
|
drv->ctx = ctx;
|
||||||
|
os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
|
||||||
|
#ifdef CONFIG_AP
|
||||||
|
drv->monitor_ifidx = -1;
|
||||||
|
drv->monitor_sock = -1;
|
||||||
|
#endif /* CONFIG_AP */
|
||||||
|
|
||||||
|
if (wpa_driver_nl80211_init_nl(drv, ctx))
|
||||||
|
goto err1;
|
||||||
|
|
||||||
|
drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
|
||||||
|
|
||||||
drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
|
drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
|
||||||
if (drv->ioctl_sock < 0) {
|
if (drv->ioctl_sock < 0) {
|
||||||
perror("socket(PF_INET,SOCK_DGRAM)");
|
perror("socket(PF_INET,SOCK_DGRAM)");
|
||||||
|
@ -1127,11 +1160,8 @@ err6:
|
||||||
close(drv->ioctl_sock);
|
close(drv->ioctl_sock);
|
||||||
err5:
|
err5:
|
||||||
genl_family_put(drv->nl80211);
|
genl_family_put(drv->nl80211);
|
||||||
err4:
|
|
||||||
nl_cache_free(drv->nl_cache);
|
nl_cache_free(drv->nl_cache);
|
||||||
err3:
|
|
||||||
nl_handle_destroy(drv->nl_handle);
|
nl_handle_destroy(drv->nl_handle);
|
||||||
err2:
|
|
||||||
nl_cb_put(drv->nl_cb);
|
nl_cb_put(drv->nl_cb);
|
||||||
err1:
|
err1:
|
||||||
os_free(drv);
|
os_free(drv);
|
||||||
|
@ -4127,7 +4157,6 @@ static int i802_ht_scan(struct wpa_driver_nl80211_data *drv)
|
||||||
static int i802_init_sockets(struct wpa_driver_nl80211_data *drv, const u8 *bssid)
|
static int i802_init_sockets(struct wpa_driver_nl80211_data *drv, const u8 *bssid)
|
||||||
{
|
{
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
int ret;
|
|
||||||
|
|
||||||
drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
|
drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
|
||||||
if (drv->ioctl_sock < 0) {
|
if (drv->ioctl_sock < 0) {
|
||||||
|
@ -4152,66 +4181,8 @@ static int i802_init_sockets(struct wpa_driver_nl80211_data *drv, const u8 *bssi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (wpa_driver_nl80211_init_nl(drv, drv->hapd))
|
||||||
* initialise generic netlink and nl80211
|
|
||||||
*/
|
|
||||||
drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
|
|
||||||
if (!drv->nl_cb) {
|
|
||||||
printf("Failed to allocate netlink callbacks.\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
drv->nl_handle = nl_handle_alloc_cb(drv->nl_cb);
|
|
||||||
if (!drv->nl_handle) {
|
|
||||||
printf("Failed to allocate netlink handle.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (genl_connect(drv->nl_handle)) {
|
|
||||||
printf("Failed to connect to generic netlink.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_LIBNL20
|
|
||||||
if (genl_ctrl_alloc_cache(drv->nl_handle, &drv->nl_cache) < 0) {
|
|
||||||
printf("Failed to allocate generic netlink cache.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#else /* CONFIG_LIBNL20 */
|
|
||||||
drv->nl_cache = genl_ctrl_alloc_cache(drv->nl_handle);
|
|
||||||
if (!drv->nl_cache) {
|
|
||||||
printf("Failed to allocate generic netlink cache.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif /* CONFIG_LIBNL20 */
|
|
||||||
|
|
||||||
drv->nl80211 = genl_ctrl_search_by_name(drv->nl_cache, "nl80211");
|
|
||||||
if (!drv->nl80211) {
|
|
||||||
printf("nl80211 not found.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = nl_get_multicast_id(drv, "nl80211", "scan");
|
|
||||||
if (ret >= 0)
|
|
||||||
ret = nl_socket_add_membership(drv->nl_handle, ret);
|
|
||||||
if (ret < 0) {
|
|
||||||
wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
|
|
||||||
"membership for scan events: %d (%s)",
|
|
||||||
ret, strerror(-ret));
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = nl_get_multicast_id(drv, "nl80211", "mlme");
|
|
||||||
if (ret >= 0)
|
|
||||||
ret = nl_socket_add_membership(drv->nl_handle, ret);
|
|
||||||
if (ret < 0) {
|
|
||||||
wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
|
|
||||||
"membership for mlme events: %d (%s)",
|
|
||||||
ret, strerror(-ret));
|
|
||||||
}
|
|
||||||
|
|
||||||
eloop_register_read_sock(nl_socket_get_fd(drv->nl_handle),
|
|
||||||
wpa_driver_nl80211_event_receive, drv,
|
|
||||||
drv->hapd);
|
|
||||||
|
|
||||||
#ifdef CONFIG_IEEE80211N
|
#ifdef CONFIG_IEEE80211N
|
||||||
if (drv->ht_40mhz_scan) {
|
if (drv->ht_40mhz_scan) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue