qsap: Convert SIOCGIWMODE to nl80211 for qsap_get_mode

Wireless extension is deprecated, hence convert SIOCGIWMODE to nl80211
for qsap_get_mode.

Change-Id: I30c3b4c2859b7c9c621f3f74d51e0e039837dcc9
CRs-Fixed: 2274099
This commit is contained in:
Hu Wang
2018-07-06 15:40:54 +08:00
committed by Gerrit - the friendly Code Review server
parent bfad727b06
commit 76d63aadc7

View File

@@ -1304,54 +1304,93 @@ error:
} }
static int iftypeCallback(struct nl_msg* msg, void* arg)
{
struct nlmsghdr* ret_hdr = nlmsg_hdr(msg);
struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
int* type = arg;
struct genlmsghdr *gnlh = (struct genlmsghdr*) nlmsg_data(ret_hdr);
nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
if (tb_msg[NL80211_ATTR_IFTYPE]) {
*type = nla_get_u32(tb_msg[NL80211_ATTR_IFTYPE]);
}
return NL_SKIP;
}
/** /**
* Get the mode of operation. * Get the mode of operation.
*/ */
int qsap_get_mode(s32 *pmode) int qsap_get_mode(s32 *pmode)
{ {
int sock; int ret = eERR_UNKNOWN;
struct iwreq wrq; struct nl_sock* sk = NULL;
int nl80211_id = -1;
int if_type = -1;
s8 interface[MAX_CONF_LINE_LEN]; s8 interface[MAX_CONF_LINE_LEN];
u32 len = MAX_CONF_LINE_LEN; u32 len = MAX_CONF_LINE_LEN;
s8 *pif; s8 *pif;
int ret; struct nl_msg* msg = NULL;
sap_auto_channel_info sap_autochan_info;
s32 *pchan;
*pmode = -1; //get interface name
if(NULL == (pif = qsap_get_config_value(pconffile, if(NULL == (pif = qsap_get_config_value(pconffile,
&qsap_str[STR_INTERFACE], interface, &len))) { &qsap_str[STR_INTERFACE], interface, &len))) {
ALOGD("%s :interface error \n", __func__); ALOGD("%s :interface error \n", __func__);
goto error; goto nla_put_failure;
} }
interface[len] = '\0'; interface[len] = '\0';
sock = socket(AF_INET, SOCK_DGRAM, 0); //allocate socket
if(sock < 0) { sk = nl_socket_alloc();
ALOGD("%s :socket error \n", __func__);
goto error; //connect to generic netlink
if (genl_connect(sk)) {
ALOGE( "Netlink socket Connection failure");
ret = eERR_UNKNOWN;
goto nla_put_failure;
} }
memset(&wrq, 0, sizeof(wrq)); //find the nl80211 driver ID
strlcpy(wrq.ifr_name, pif, sizeof(wrq.ifr_name)); nl80211_id = genl_ctrl_resolve(sk, "nl80211");
ret = ioctl(sock, SIOCGIWMODE, &wrq); //attach a callback
nl_socket_modify_cb(sk, NL_CB_VALID, NL_CB_CUSTOM,
iftypeCallback, &if_type);
//allocate a message
msg = nlmsg_alloc();
// setup the message
genlmsg_put(msg, 0, 0, nl80211_id, 0, 0, NL80211_CMD_GET_INTERFACE, 0);
//add message attributes
NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(pif));
// Send the message
ret = nl_send_auto_complete(sk, msg);
if (ret < 0 ) { if (ret < 0 ) {
ALOGE("%s: ioctl failure \n",__func__); ALOGE( "nl_send_auto_complete failure");
close(sock); ret = eERR_UNKNOWN;
goto error; goto nla_put_failure;
} }
*pmode = *(s32 *)(&wrq.u.mode); //block for message to return
ALOGE("%s: ioctl Get Mode = %d \n",__func__, (int)*pmode); nl_recvmsgs_default(sk);
close(sock); *pmode = if_type;
return eSUCCESS; ALOGI("%s: (%s) NL80211 Get Mode = %d \n",__func__, pif, (int)*pmode);
ret = eSUCCESS;
error: nla_put_failure:
*pmode = -1; if (sk)
ALOGE("%s: (Failure) ioctl Get Mode = %d \n",__func__, (int)*pmode); nl_socket_free(sk);
return eERR_UNKNOWN; if (msg)
nlmsg_free(msg);
return ret;
} }
/** /**