struct bss_scan_info_t *bss_info = (struct bss_scan_info_t *)list->data;
if ((g_strcmp0(bss_info->ssid, ssid) == 0) && (bss_info->security_type == sec_type)
&& (bss_info->encryption_type == enc_type)) {
+ g_free(vsie);
return NL_SKIP;
}
}
gchar *key;
gboolean ssid_found = FALSE;
int mcid = __netconfig_get_multicast_id(socket, "nl80211", "scan");
- nl_socket_add_membership(socket, mcid);
+
+ ret = nl_socket_add_membership(socket, mcid);
+ if (ret < 0) {
+ DBG("Failed to add membership, error: (%s)", nl_geterror(-ret));
+ return ret;
+ }
msg = nlmsg_alloc();
if (!msg) {
DBG("Failed to allocate msg");
+ nl_socket_drop_membership(socket, mcid);
return -ENOMEM;
}
ssids = nlmsg_alloc();
if (!ssids) {
DBG("Failed to allocate ssids");
nlmsg_free(msg);
+ nl_socket_drop_membership(socket, mcid);
return -ENOMEM;
}
cb = nl_cb_alloc(NL_CB_DEFAULT);
DBG("Failed to allocate callbacks");
nlmsg_free(msg);
nlmsg_free(ssids);
+ nl_socket_drop_membership(socket, mcid);
return -ENOMEM;
}
/** Set nl message and callback functions. */
genlmsg_put(msg, 0, 0, id, 0, 0, NL80211_CMD_TRIGGER_SCAN, 0);
- nla_put_u32(msg, NL80211_ATTR_IFINDEX, if_index);
+ ret = nla_put_u32(msg, NL80211_ATTR_IFINDEX, if_index);
+ if (ret < 0) {
+ DBG("Failed to add integer attribute to netlink message, error: (%s)", nl_geterror(-ret));
+ goto out;
+ }
g_variant_get(params, "a{sv}", &iter);
while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
ssid_found = TRUE;
DBG("ssid [%s]", ssid);
- nla_put(ssids, 1, strlen(ssid), ssid);
+ ret = nla_put(ssids, 1, strlen(ssid), ssid);
g_free(ssid);
+ if (ret < 0) {
+ DBG("Failed to add ssid to netlink message, error: (%s)", nl_geterror(-ret));
+ g_variant_iter_free(iter);
+ goto out;
+ }
}
} else if (g_strcmp0(key, "VSIE") == 0) {
if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
}
g_variant_iter_free(iter);
- if (!ssid_found)
- nla_put(ssids, 1, 0, "");
+ if (!ssid_found) {
+ ret = nla_put(ssids, 1, 0, "");
+ if (ret < 0) {
+ DBG("nla_put error: (%s)", nl_geterror(-ret));
+ goto out;
+ }
+ }
nla_put_nested(msg, NL80211_ATTR_SCAN_SSIDS, ssids);
- nlmsg_free(ssids);
if (ies[0] == NETCONFIG_VENDOR_SPECIFIC_ID && ies[1] >= 4) {
DBG("ies_len: %d ies: %02x %02x %02x %02x %02x %02x %02x", ies_len,
ies[0], ies[1], ies[2], ies[3], ies[4], ies[5], ies[6]);
- nla_put(msg, NL80211_ATTR_IE, ies_len, ies);
+ ret = nla_put(msg, NL80211_ATTR_IE, ies_len, ies);
+ if (ret < 0) {
+ DBG("Failed to add vsie data to netlink message, error: (%s)", nl_geterror(-ret));
+ goto out;
+ }
}
err = 1;
/** Send NL80211_CMD_TRIGGER_SCAN to start the scan. */
ret = nl_send_auto_complete(socket, msg);
+ if (ret < 0) {
+ DBG("nl_send_auto_complete() error: (%s)", nl_geterror(-ret));
+ goto out;
+ }
+
DBG("Sent %d bytes to the kernel", ret);
ssid_found = FALSE;
if (ret < 0) {
DBG("nl_recvmsgs() ret: %d (%s)", ret, nl_geterror(-ret));
- nl_cb_put(cb);
- return ret;
+ goto out;
}
while (!results.done)
DBG("scan aborted");
return 1;
}
- DBG("Scan done");
+out:
/** Release memory */
+ nlmsg_free(ssids);
nlmsg_free(msg);
nl_cb_put(cb);
nl_socket_drop_membership(socket, mcid);
+
+ if (ret < 0)
+ return ret;
+
+ DBG("Scan done");
return 0;
}
static int __netconfig_initialize_nl_msg(netconfig_nl_global *global)
{
+ int rv;
+
if (global == NULL) {
DBG("Invalid parameter.");
return -EINVAL;
/* Set command into message */
genlmsg_put(global->msg, 0, 0, global->id, 0, NLM_F_DUMP, NL80211_CMD_GET_SCAN, 0);
- nla_put_u32(global->msg, NL80211_ATTR_IFINDEX, global->if_index);
+ rv = nla_put_u32(global->msg, NL80211_ATTR_IFINDEX, global->if_index);
+ if (rv < 0) {
+ DBG("Failed to add integer attribute to netlink message.");
+ nlmsg_free(global->msg);
+ return rv;
+ }
nl_socket_modify_cb(global->socket, NL_CB_VALID, NL_CB_CUSTOM, __netconfig_netlink_scan_cb, NULL);
return 0;