Add new features:-
1. AP Auto shut off 2. Energy Detect Threshold Change-Id: I454dd0c999131a0d0910b415cf73590d3458f2ad
This commit is contained in:
@@ -1,393 +1,405 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
|
* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
* met:
|
* met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above
|
* * Redistributions in binary form must reproduce the above
|
||||||
* copyright notice, this list of conditions and the following
|
* copyright notice, this list of conditions and the following
|
||||||
* disclaimer in the documentation and/or other materials provided
|
* disclaimer in the documentation and/or other materials provided
|
||||||
* with the distribution.
|
* with the distribution.
|
||||||
* * Neither the name of Code Aurora Forum, Inc. nor the names of its
|
* * Neither the name of Code Aurora Forum, Inc. nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived
|
* contributors may be used to endorse or promote products derived
|
||||||
* from this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
|
|
||||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "QWiFiSoftApCfg.h"
|
#include "QWiFiSoftApCfg.h"
|
||||||
|
|
||||||
#define UPDATE_ERROR_CODE(msg, code) \
|
#define UPDATE_ERROR_CODE(msg, code) \
|
||||||
{ \
|
{ \
|
||||||
int rc; \
|
int rc; \
|
||||||
rc = snprintf(resp, sizeof(resp), "failure %s:%s",msg, code); \
|
rc = snprintf(resp, sizeof(resp), "failure %s:%s",msg, code); \
|
||||||
if ( rc == sizeof(resp)) resp[sizeof(resp)-1] = 0; \
|
if ( rc == sizeof(resp)) resp[sizeof(resp)-1] = 0; \
|
||||||
LOGE(resp); \
|
LOGE(resp); \
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct sockaddr_nl rtnl_local;
|
static struct sockaddr_nl rtnl_local;
|
||||||
static int rtnl_fd = -1;
|
static int rtnl_fd = -1;
|
||||||
static char evt_buf[MAX_EVT_BUF_SIZE];
|
static char evt_buf[MAX_EVT_BUF_SIZE];
|
||||||
static int evt_len;
|
static int evt_len;
|
||||||
|
|
||||||
|
static void softap_handle_custom_event(char * buf, int len)
|
||||||
static void softap_handle_associated_event(char *mac_addr)
|
{
|
||||||
{
|
if (strncmp(buf, "AUTO-SHUT.indication ", strlen("AUTO-SHUT.indication ")) == 0)
|
||||||
snprintf(evt_buf, sizeof(evt_buf), "102 Station " HWA_FORM " Associated",
|
{
|
||||||
HWA_ARG(mac_addr));
|
LOGD("EVENT: Custom Event\n");
|
||||||
}
|
snprintf(evt_buf, sizeof(evt_buf), "105 AP Shutdown");
|
||||||
|
}
|
||||||
static void softap_handle_disassociated_event(char *mac_addr)
|
}
|
||||||
{
|
|
||||||
snprintf(evt_buf, sizeof(evt_buf), "103 Station " HWA_FORM " Disassociated",
|
static void softap_handle_associated_event(char *mac_addr)
|
||||||
HWA_ARG(mac_addr));
|
{
|
||||||
}
|
snprintf(evt_buf, sizeof(evt_buf), "102 Station " HWA_FORM " Associated",
|
||||||
|
HWA_ARG(mac_addr));
|
||||||
static void softap_handle_wireless_event(char *atr, int atrlen)
|
}
|
||||||
{
|
|
||||||
int len = 0;
|
static void softap_handle_disassociated_event(char *mac_addr)
|
||||||
struct iw_event iwe;
|
{
|
||||||
char *buffer = atr + RTA_ALIGN(RTATTRLEN);
|
snprintf(evt_buf, sizeof(evt_buf), "103 Station " HWA_FORM " Disassociated",
|
||||||
|
HWA_ARG(mac_addr));
|
||||||
atrlen -= RTA_ALIGN(RTATTRLEN);
|
}
|
||||||
|
|
||||||
while ((len + (int)IW_EV_LCP_LEN) < atrlen) {
|
static void softap_handle_wireless_event(char *atr, int atrlen)
|
||||||
memcpy((char *)&iwe, buffer + len, sizeof(struct iw_event));
|
{
|
||||||
|
int len = 0;
|
||||||
if (iwe.len <= IW_EV_LCP_LEN)
|
struct iw_event iwe;
|
||||||
break;
|
char *buffer = atr + RTA_ALIGN(RTATTRLEN);
|
||||||
|
|
||||||
LOGD("Received Wireless Event: cmd=0x%x len=%d",
|
atrlen -= RTA_ALIGN(RTATTRLEN);
|
||||||
iwe.cmd, iwe.len);
|
|
||||||
|
while ((len + (int)IW_EV_LCP_LEN) < atrlen) {
|
||||||
switch (iwe.cmd) {
|
memcpy((char *)&iwe, buffer + len, sizeof(struct iw_event));
|
||||||
case IWEVEXPIRED:
|
|
||||||
LOGD("EVENT: IWEVEXPIRED\n");
|
if (iwe.len <= IW_EV_LCP_LEN)
|
||||||
softap_handle_disassociated_event(iwe.u.addr.sa_data);
|
break;
|
||||||
break;
|
|
||||||
|
LOGD("Received Wireless Event: cmd=0x%x len=%d", iwe.cmd, iwe.len);
|
||||||
case IWEVREGISTERED:
|
|
||||||
LOGD("EVENT: IWEVREGISTERED\n");
|
switch (iwe.cmd) {
|
||||||
softap_handle_associated_event(iwe.u.addr.sa_data);
|
case IWEVEXPIRED:
|
||||||
break;
|
LOGD("EVENT: IWEVEXPIRED\n");
|
||||||
|
softap_handle_disassociated_event(iwe.u.addr.sa_data);
|
||||||
default:
|
break;
|
||||||
break;
|
|
||||||
}
|
case IWEVREGISTERED:
|
||||||
|
LOGD("EVENT: IWEVREGISTERED\n");
|
||||||
len += iwe.len;
|
softap_handle_associated_event(iwe.u.addr.sa_data);
|
||||||
}
|
break;
|
||||||
|
|
||||||
return;
|
case IWEVCUSTOM:
|
||||||
}
|
LOGD("EVENT: Custom Event\n");
|
||||||
|
softap_handle_custom_event(buffer + len + IW_EV_POINT_LEN, iwe.u.data.length);
|
||||||
void softap_handle_rtm_link_event(struct nlmsghdr *hdr)
|
break;
|
||||||
{
|
|
||||||
char *ptr = (char *)NLMSG_DATA(hdr);
|
default:
|
||||||
struct rtattr *atr;
|
break;
|
||||||
int atr_len;
|
}
|
||||||
|
|
||||||
if ((hdr->nlmsg_len - MSGHDRLEN) < IFINFOLEN) {
|
len += iwe.len;
|
||||||
LOGD("Message Length Problem1");
|
}
|
||||||
return;
|
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
if ((atr_len = hdr->nlmsg_len - NLMSG_ALIGN(IFINFOLEN)) < 0) {
|
|
||||||
LOGD("Message Length Problem2");
|
void softap_handle_rtm_link_event(struct nlmsghdr *hdr)
|
||||||
return;
|
{
|
||||||
}
|
char *ptr = (char *)NLMSG_DATA(hdr);
|
||||||
|
struct rtattr *atr;
|
||||||
ptr += NLMSG_ALIGN(IFINFOLEN);
|
int atr_len;
|
||||||
atr = (struct rtattr *)ptr;
|
|
||||||
|
if ((hdr->nlmsg_len - MSGHDRLEN) < IFINFOLEN) {
|
||||||
while (RTA_OK(atr, atr_len)) {
|
LOGD("Message Length Problem1");
|
||||||
switch (atr->rta_type) {
|
return;
|
||||||
case IFLA_WIRELESS:
|
}
|
||||||
softap_handle_wireless_event((char *)atr,
|
|
||||||
atr->rta_len);
|
if ((atr_len = hdr->nlmsg_len - NLMSG_ALIGN(IFINFOLEN)) < 0) {
|
||||||
break;
|
LOGD("Message Length Problem2");
|
||||||
|
return;
|
||||||
default:
|
}
|
||||||
break;
|
|
||||||
}
|
ptr += NLMSG_ALIGN(IFINFOLEN);
|
||||||
|
atr = (struct rtattr *)ptr;
|
||||||
atr = RTA_NEXT(atr, atr_len);
|
|
||||||
}
|
while (RTA_OK(atr, atr_len)) {
|
||||||
|
switch (atr->rta_type) {
|
||||||
return;
|
case IFLA_WIRELESS:
|
||||||
}
|
softap_handle_wireless_event((char *)atr,
|
||||||
|
atr->rta_len);
|
||||||
static void softap_handle_iface_event(void)
|
break;
|
||||||
{
|
|
||||||
int cnt, mlen = 0;
|
default:
|
||||||
char *ptr, buffer[MAX_RECV_BUF_SIZE];
|
break;
|
||||||
socklen_t slen;
|
}
|
||||||
struct nlmsghdr * hdr;
|
|
||||||
|
atr = RTA_NEXT(atr, atr_len);
|
||||||
while (1) {
|
}
|
||||||
cnt = recvfrom(rtnl_fd, buffer, sizeof(buffer),
|
|
||||||
MSG_DONTWAIT,
|
return;
|
||||||
(struct sockaddr *)&rtnl_local, &slen);
|
}
|
||||||
|
|
||||||
if (cnt <= 0) {
|
static void softap_handle_iface_event(void)
|
||||||
buffer[0] = '\0';
|
{
|
||||||
LOGD("recvfrom failed");
|
int cnt, mlen = 0;
|
||||||
return;
|
char *ptr, buffer[MAX_RECV_BUF_SIZE];
|
||||||
}
|
socklen_t slen;
|
||||||
|
struct nlmsghdr * hdr;
|
||||||
ptr = buffer;
|
|
||||||
|
while (1) {
|
||||||
while (cnt >= MSGHDRLEN) {
|
cnt = recvfrom(rtnl_fd, buffer, sizeof(buffer),
|
||||||
hdr = (struct nlmsghdr *)ptr;
|
MSG_DONTWAIT,
|
||||||
|
(struct sockaddr *)&rtnl_local, &slen);
|
||||||
mlen = hdr->nlmsg_len;
|
|
||||||
|
if (cnt <= 0) {
|
||||||
if ((mlen > cnt) || ((mlen - MSGHDRLEN) < 0)) {
|
buffer[0] = '\0';
|
||||||
break;
|
LOGD("recvfrom failed");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
switch (hdr->nlmsg_type) {
|
|
||||||
case RTM_NEWLINK:
|
ptr = buffer;
|
||||||
case RTM_DELLINK:
|
|
||||||
softap_handle_rtm_link_event(hdr);
|
while (cnt >= MSGHDRLEN) {
|
||||||
break;
|
hdr = (struct nlmsghdr *)ptr;
|
||||||
}
|
|
||||||
|
mlen = hdr->nlmsg_len;
|
||||||
mlen = NLMSG_ALIGN(hdr->nlmsg_len);
|
|
||||||
cnt -= mlen;
|
if ((mlen > cnt) || ((mlen - MSGHDRLEN) < 0)) {
|
||||||
ptr += mlen;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
switch (hdr->nlmsg_type) {
|
||||||
return;
|
case RTM_NEWLINK:
|
||||||
}
|
case RTM_DELLINK:
|
||||||
|
softap_handle_rtm_link_event(hdr);
|
||||||
static inline int softap_rtnl_wait(void)
|
break;
|
||||||
{
|
}
|
||||||
fd_set fds;
|
|
||||||
int oldfd, ret;
|
mlen = NLMSG_ALIGN(hdr->nlmsg_len);
|
||||||
|
cnt -= mlen;
|
||||||
if (rtnl_fd < 0) {
|
ptr += mlen;
|
||||||
LOGD("Netlink Socket Not Available");
|
}
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
|
return;
|
||||||
/* Initialize fds */
|
}
|
||||||
FD_ZERO(&fds);
|
|
||||||
FD_SET(rtnl_fd, &fds);
|
static inline int softap_rtnl_wait(void)
|
||||||
oldfd = rtnl_fd;
|
{
|
||||||
|
fd_set fds;
|
||||||
/* Wait for some trigger event */
|
int oldfd, ret;
|
||||||
ret = select(oldfd + 1, &fds, NULL, NULL, NULL);
|
|
||||||
|
if (rtnl_fd < 0) {
|
||||||
if (ret < 0) {
|
LOGD("Netlink Socket Not Available");
|
||||||
/* Error Occurred */
|
return -1;
|
||||||
LOGD("Select on Netlink Socket Failed");
|
}
|
||||||
return ret;
|
|
||||||
} else if (!ret) {
|
/* Initialize fds */
|
||||||
LOGD("Select on Netlink Socket Timed Out");
|
FD_ZERO(&fds);
|
||||||
/* Timeout Occurred */
|
FD_SET(rtnl_fd, &fds);
|
||||||
return -1;
|
oldfd = rtnl_fd;
|
||||||
}
|
|
||||||
|
/* Wait for some trigger event */
|
||||||
/* Check if any event is available for us */
|
ret = select(oldfd + 1, &fds, NULL, NULL, NULL);
|
||||||
if (FD_ISSET(rtnl_fd, &fds)) {
|
|
||||||
softap_handle_iface_event();
|
if (ret < 0) {
|
||||||
}
|
/* Error Occurred */
|
||||||
|
LOGD("Select on Netlink Socket Failed");
|
||||||
return 0;
|
return ret;
|
||||||
}
|
} else if (!ret) {
|
||||||
|
LOGD("Select on Netlink Socket Timed Out");
|
||||||
static void softap_rtnl_close(void)
|
/* Timeout Occurred */
|
||||||
{
|
return -1;
|
||||||
close(rtnl_fd);
|
}
|
||||||
}
|
|
||||||
|
/* Check if any event is available for us */
|
||||||
static int softap_rtnl_open(void)
|
if (FD_ISSET(rtnl_fd, &fds)) {
|
||||||
{
|
softap_handle_iface_event();
|
||||||
int addr_len;
|
}
|
||||||
|
|
||||||
rtnl_fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
|
return 0;
|
||||||
|
}
|
||||||
if (rtnl_fd < 0) {
|
|
||||||
LOGE("open netlink socket failed");
|
static void softap_rtnl_close(void)
|
||||||
return -1;
|
{
|
||||||
}
|
close(rtnl_fd);
|
||||||
|
}
|
||||||
memset(&rtnl_local, 0, sizeof(rtnl_local));
|
|
||||||
rtnl_local.nl_family = AF_NETLINK;
|
static int softap_rtnl_open(void)
|
||||||
rtnl_local.nl_groups = RTMGRP_LINK;
|
{
|
||||||
|
int addr_len;
|
||||||
if (bind(rtnl_fd, (struct sockaddr*)&rtnl_local,
|
|
||||||
sizeof(rtnl_local)) < 0) {
|
rtnl_fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
|
||||||
LOGE("bind netlink socket failed");
|
|
||||||
return -1;
|
if (rtnl_fd < 0) {
|
||||||
}
|
LOGE("open netlink socket failed");
|
||||||
|
return -1;
|
||||||
addr_len = sizeof(rtnl_local);
|
}
|
||||||
|
|
||||||
if (getsockname(rtnl_fd, (struct sockaddr*)&rtnl_local,
|
memset(&rtnl_local, 0, sizeof(rtnl_local));
|
||||||
(socklen_t *) &addr_len) < 0) {
|
rtnl_local.nl_family = AF_NETLINK;
|
||||||
LOGE("getsockname failed");
|
rtnl_local.nl_groups = RTMGRP_LINK;
|
||||||
return -1;
|
|
||||||
}
|
if (bind(rtnl_fd, (struct sockaddr*)&rtnl_local,
|
||||||
|
sizeof(rtnl_local)) < 0) {
|
||||||
if (addr_len != sizeof(rtnl_local)) {
|
LOGE("bind netlink socket failed");
|
||||||
LOGE("Wrong address length %d\n", addr_len);
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
|
addr_len = sizeof(rtnl_local);
|
||||||
if (rtnl_local.nl_family != AF_NETLINK) {
|
|
||||||
LOGE("Wrong address family %d\n", rtnl_local.nl_family);
|
if (getsockname(rtnl_fd, (struct sockaddr*)&rtnl_local,
|
||||||
return -1;
|
(socklen_t *) &addr_len) < 0) {
|
||||||
}
|
LOGE("getsockname failed");
|
||||||
|
return -1;
|
||||||
return 0;
|
}
|
||||||
}
|
|
||||||
|
if (addr_len != sizeof(rtnl_local)) {
|
||||||
JNIEXPORT void JNICALL
|
LOGE("Wrong address length %d\n", addr_len);
|
||||||
Java_com_qualcomm_wifi_softap_QWiFiSoftApCfg_SapCloseNetlink
|
return -1;
|
||||||
(JNIEnv *env, jobject obj)
|
}
|
||||||
{
|
|
||||||
softap_rtnl_close();
|
if (rtnl_local.nl_family != AF_NETLINK) {
|
||||||
return;
|
LOGE("Wrong address family %d\n", rtnl_local.nl_family);
|
||||||
}
|
return -1;
|
||||||
|
}
|
||||||
JNIEXPORT jstring JNICALL
|
|
||||||
Java_com_qualcomm_wifi_softap_QWiFiSoftApCfg_SapWaitForEvent
|
return 0;
|
||||||
(JNIEnv *env, jobject obj)
|
}
|
||||||
{
|
|
||||||
int ret;
|
JNIEXPORT void JNICALL
|
||||||
|
Java_com_qualcomm_wifi_softap_QWiFiSoftApCfg_SapCloseNetlink
|
||||||
do {
|
(JNIEnv *env, jobject obj)
|
||||||
evt_len = 0;
|
{
|
||||||
memset(evt_buf, 0, sizeof(evt_buf));
|
softap_rtnl_close();
|
||||||
|
return;
|
||||||
ret = softap_rtnl_wait();
|
}
|
||||||
} while (!strlen(evt_buf));
|
|
||||||
|
JNIEXPORT jstring JNICALL
|
||||||
return (*env)->NewStringUTF(env, evt_buf);
|
Java_com_qualcomm_wifi_softap_QWiFiSoftApCfg_SapWaitForEvent
|
||||||
}
|
(JNIEnv *env, jobject obj)
|
||||||
|
{
|
||||||
JNIEXPORT jboolean JNICALL
|
int ret;
|
||||||
Java_com_qualcomm_wifi_softap_QWiFiSoftApCfg_SapOpenNetlink
|
|
||||||
(JNIEnv *env, jobject obj)
|
do {
|
||||||
{
|
evt_len = 0;
|
||||||
if (softap_rtnl_open() != 0) {
|
memset(evt_buf, 0, sizeof(evt_buf));
|
||||||
LOGD("Netlink Open Fail");
|
|
||||||
return JNI_FALSE;
|
ret = softap_rtnl_wait();
|
||||||
}
|
} while (!strlen(evt_buf));
|
||||||
|
|
||||||
return JNI_TRUE;
|
return (*env)->NewStringUTF(env, evt_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL
|
JNIEXPORT jboolean JNICALL
|
||||||
Java_com_qualcomm_wifi_softap_QWiFiSoftApCfg_SapSendCommand
|
Java_com_qualcomm_wifi_softap_QWiFiSoftApCfg_SapOpenNetlink
|
||||||
(JNIEnv *env, jobject obj, jstring jcmd)
|
(JNIEnv *env, jobject obj)
|
||||||
{
|
{
|
||||||
const char *pcmd;
|
if (softap_rtnl_open() != 0) {
|
||||||
char cmd[MAX_CMD_SIZE];
|
LOGD("Netlink Open Fail");
|
||||||
char resp[MAX_RESP_SIZE];
|
return JNI_FALSE;
|
||||||
int sock, rc;
|
}
|
||||||
int done = 0;
|
|
||||||
char code[32] = {0};
|
return JNI_TRUE;
|
||||||
int connect_retry;
|
}
|
||||||
|
|
||||||
strncpy(cmd, "softap qccmd ", sizeof(cmd));
|
JNIEXPORT jstring JNICALL
|
||||||
|
Java_com_qualcomm_wifi_softap_QWiFiSoftApCfg_SapSendCommand
|
||||||
pcmd = (char *) ((*env)->GetStringUTFChars(env, jcmd, NULL));
|
(JNIEnv *env, jobject obj, jstring jcmd)
|
||||||
|
{
|
||||||
if ( pcmd == NULL ) {
|
const char *pcmd;
|
||||||
UPDATE_ERROR_CODE("Command not handled","");
|
char cmd[MAX_CMD_SIZE];
|
||||||
goto end;
|
char resp[MAX_RESP_SIZE];
|
||||||
}
|
int sock, rc;
|
||||||
|
int done = 0;
|
||||||
LOGD("Received Command: %s\n", pcmd);
|
char code[32] = {0};
|
||||||
|
int connect_retry;
|
||||||
if ((strlen(cmd) + strlen(pcmd)) > sizeof(cmd)) {
|
|
||||||
UPDATE_ERROR_CODE("Command length is larger than MAX_CMD_SIZE", "");
|
strncpy(cmd, "softap qccmd ", sizeof(cmd));
|
||||||
goto end;
|
|
||||||
}
|
pcmd = (char *) ((*env)->GetStringUTFChars(env, jcmd, NULL));
|
||||||
|
|
||||||
strcat(cmd, pcmd);
|
if ( pcmd == NULL ) {
|
||||||
|
UPDATE_ERROR_CODE("Command not handled","");
|
||||||
connect_retry = 0;
|
goto end;
|
||||||
|
}
|
||||||
while ( 1 ) {
|
|
||||||
if ((sock = socket_local_client("netd",
|
LOGD("Received Command: %s\n", pcmd);
|
||||||
ANDROID_SOCKET_NAMESPACE_RESERVED,
|
|
||||||
SOCK_STREAM)) < 0) {
|
if ((strlen(cmd) + strlen(pcmd)) > sizeof(cmd)) {
|
||||||
if (connect_retry > 3) {
|
UPDATE_ERROR_CODE("Command length is larger than MAX_CMD_SIZE", "");
|
||||||
UPDATE_ERROR_CODE("Error connecting",
|
goto end;
|
||||||
strerror(errno));
|
}
|
||||||
goto end;
|
|
||||||
}
|
strcat(cmd, pcmd);
|
||||||
|
|
||||||
LOGW("netd might have crashed, wait for it to "
|
connect_retry = 0;
|
||||||
"start back\n");
|
|
||||||
sleep(1);
|
while ( 1 ) {
|
||||||
} else {
|
if ((sock = socket_local_client("netd",
|
||||||
break;
|
ANDROID_SOCKET_NAMESPACE_RESERVED,
|
||||||
}
|
SOCK_STREAM)) < 0) {
|
||||||
|
if (connect_retry > 3) {
|
||||||
connect_retry++;
|
UPDATE_ERROR_CODE("Error connecting",
|
||||||
}
|
strerror(errno));
|
||||||
|
goto end;
|
||||||
if (write(sock, cmd, strlen(cmd) + 1) < 0) {
|
}
|
||||||
UPDATE_ERROR_CODE("Error Writing to socket", strerror(errno));
|
|
||||||
goto end;
|
LOGW("netd might have crashed, wait for it to "
|
||||||
}
|
"start back\n");
|
||||||
|
sleep(1);
|
||||||
while (!done) {
|
} else {
|
||||||
int i;
|
break;
|
||||||
|
}
|
||||||
if ((rc = read(sock, resp, sizeof(resp))) <= 0) {
|
|
||||||
if (rc == 0) {
|
connect_retry++;
|
||||||
UPDATE_ERROR_CODE("Lost connection to Netd",
|
}
|
||||||
strerror(errno));
|
|
||||||
} else {
|
if (write(sock, cmd, strlen(cmd) + 1) < 0) {
|
||||||
UPDATE_ERROR_CODE("Error reading data",
|
UPDATE_ERROR_CODE("Error Writing to socket", strerror(errno));
|
||||||
strerror(errno));
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
done = 1;
|
while (!done) {
|
||||||
} else {
|
int i;
|
||||||
/* skip broadcase messages */
|
|
||||||
i = 0;
|
if ((rc = read(sock, resp, sizeof(resp))) <= 0) {
|
||||||
|
if (rc == 0) {
|
||||||
while(resp[i] && (i<(int)(sizeof(code)-1)) &&
|
UPDATE_ERROR_CODE("Lost connection to Netd",
|
||||||
(resp[i] != ' ') && (resp[i] != '\t')) {
|
strerror(errno));
|
||||||
code[i] = resp[i];
|
} else {
|
||||||
i++;
|
UPDATE_ERROR_CODE("Error reading data",
|
||||||
}
|
strerror(errno));
|
||||||
|
}
|
||||||
code[i] = '\0';
|
|
||||||
|
done = 1;
|
||||||
if ( (!strcmp(code, "success")) ||
|
} else {
|
||||||
(!strcmp(code, "failure")) ) {
|
/* skip broadcase messages */
|
||||||
done=1;
|
i = 0;
|
||||||
} else {
|
|
||||||
LOGW("Code(%s)\n", code);
|
while(resp[i] && (i<(int)(sizeof(code)-1)) &&
|
||||||
LOGW("Ignore messages : %s\n", resp);
|
(resp[i] != ' ') && (resp[i] != '\t')) {
|
||||||
}
|
code[i] = resp[i];
|
||||||
}
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
code[i] = '\0';
|
||||||
(*env)->ReleaseStringUTFChars(env, jcmd, pcmd);
|
|
||||||
|
if ( (!strcmp(code, "success")) ||
|
||||||
return (*env)->NewStringUTF(env, resp);
|
(!strcmp(code, "failure")) ) {
|
||||||
}
|
done=1;
|
||||||
|
} else {
|
||||||
|
LOGW("Code(%s)\n", code);
|
||||||
|
LOGW("Ignore messages : %s\n", resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
(*env)->ReleaseStringUTFChars(env, jcmd, pcmd);
|
||||||
|
|
||||||
|
return (*env)->NewStringUTF(env, resp);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,87 +1,87 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
|
* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
* met:
|
* met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above
|
* * Redistributions in binary form must reproduce the above
|
||||||
* copyright notice, this list of conditions and the following
|
* copyright notice, this list of conditions and the following
|
||||||
* disclaimer in the documentation and/or other materials provided
|
* disclaimer in the documentation and/or other materials provided
|
||||||
* with the distribution.
|
* with the distribution.
|
||||||
* * Neither the name of Code Aurora Forum, Inc. nor the names of its
|
* * Neither the name of Code Aurora Forum, Inc. nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived
|
* contributors may be used to endorse or promote products derived
|
||||||
* from this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
|
|
||||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __QWIFISOFTAPCFG
|
#ifndef __QWIFISOFTAPCFG
|
||||||
#define __QWIFISOFTAPCFG
|
#define __QWIFISOFTAPCFG
|
||||||
|
|
||||||
#define LOG_TAG "QWIFIAPCFG"
|
#define LOG_TAG "QWIFIAPCFG"
|
||||||
|
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
|
||||||
#include <linux/if.h>
|
#include <linux/if.h>
|
||||||
#include <linux/if_arp.h>
|
#include <linux/if_arp.h>
|
||||||
#include <linux/if_ether.h>
|
#include <linux/if_ether.h>
|
||||||
#include <linux/netlink.h>
|
#include <linux/netlink.h>
|
||||||
#include <linux/rtnetlink.h>
|
#include <linux/rtnetlink.h>
|
||||||
#include <linux/wireless.h>
|
#include <linux/wireless.h>
|
||||||
|
|
||||||
#include <cutils/sockets.h>
|
#include <cutils/sockets.h>
|
||||||
#include <private/android_filesystem_config.h>
|
#include <private/android_filesystem_config.h>
|
||||||
|
|
||||||
typedef unsigned char u8;
|
typedef unsigned char u8;
|
||||||
|
|
||||||
#define HWA_FORM "%02X:%02X:%02X:%02X:%02X:%02X"
|
#define HWA_FORM "%02X:%02X:%02X:%02X:%02X:%02X"
|
||||||
#define HWA_ARG(x) *(((u8 *)x + 0)), *(((u8 *)x + 1)), \
|
#define HWA_ARG(x) *(((u8 *)x + 0)), *(((u8 *)x + 1)), \
|
||||||
*(((u8 *)x + 2)), *(((u8 *)x + 3)), \
|
*(((u8 *)x + 2)), *(((u8 *)x + 3)), \
|
||||||
*(((u8 *)x + 4)), *(((u8 *)x + 5))
|
*(((u8 *)x + 4)), *(((u8 *)x + 5))
|
||||||
|
|
||||||
#define MAX_RESP_SIZE 256
|
#define MAX_RESP_SIZE 256
|
||||||
#define MAX_CMD_SIZE 256
|
#define MAX_CMD_SIZE 256
|
||||||
#define MAX_EVT_BUF_SIZE 256
|
#define MAX_EVT_BUF_SIZE 256
|
||||||
#define MAX_RECV_BUF_SIZE 256
|
#define MAX_RECV_BUF_SIZE 256
|
||||||
|
|
||||||
#define MSGHDRLEN ((int)(sizeof(struct nlmsghdr)))
|
#define MSGHDRLEN ((int)(sizeof(struct nlmsghdr)))
|
||||||
#define IFINFOLEN ((int)(sizeof(struct ifinfomsg)))
|
#define IFINFOLEN ((int)(sizeof(struct ifinfomsg)))
|
||||||
#define RTATTRLEN ((int)(sizeof(struct rtattr)))
|
#define RTATTRLEN ((int)(sizeof(struct rtattr)))
|
||||||
|
|
||||||
#ifndef IFLA_WIRELESS
|
#ifndef IFLA_WIRELESS
|
||||||
#define IFLA_WIRELESS (IFLA_MASTER + 1)
|
#define IFLA_WIRELESS (IFLA_MASTER + 1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,437 +1,459 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
|
* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
* met:
|
* met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above
|
* * Redistributions in binary form must reproduce the above
|
||||||
* copyright notice, this list of conditions and the following
|
* copyright notice, this list of conditions and the following
|
||||||
* disclaimer in the documentation and/or other materials provided
|
* disclaimer in the documentation and/or other materials provided
|
||||||
* with the distribution.
|
* with the distribution.
|
||||||
* * Neither the name of Code Aurora Forum, Inc. nor the names of its
|
* * Neither the name of Code Aurora Forum, Inc. nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived
|
* contributors may be used to endorse or promote products derived
|
||||||
* from this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
|
|
||||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <linux/if.h>
|
#include <linux/if.h>
|
||||||
#include <linux/wireless.h>
|
#include <linux/wireless.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#define LOG_TAG "QCLDR-"
|
#define LOG_TAG "QCLDR-"
|
||||||
|
|
||||||
#include "cutils/log.h"
|
#include "cutils/log.h"
|
||||||
#include "cutils/memory.h"
|
#include "cutils/memory.h"
|
||||||
#include "cutils/misc.h"
|
#include "cutils/misc.h"
|
||||||
#include "cutils/properties.h"
|
#include "cutils/properties.h"
|
||||||
#include "private/android_filesystem_config.h"
|
#include "private/android_filesystem_config.h"
|
||||||
|
|
||||||
#include "qsap_api.h"
|
#include "qsap_api.h"
|
||||||
#include "qsap.h"
|
#include "qsap.h"
|
||||||
#include "libwpa_client/wpa_ctrl.h"
|
#include "libwpa_client/wpa_ctrl.h"
|
||||||
|
|
||||||
#include <sys/system_properties.h>
|
#include <sys/system_properties.h>
|
||||||
|
|
||||||
#ifndef WIFI_DRIVER_MODULE_PATH
|
#ifndef WIFI_DRIVER_MODULE_PATH
|
||||||
#define WIFI_DRIVER_MODULE_PATH "/system/lib/modules/wlan.ko"
|
#define WIFI_DRIVER_MODULE_PATH "/system/lib/modules/wlan.ko"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WIFI_DRIVER_MODULE_NAME
|
#ifndef WIFI_DRIVER_MODULE_NAME
|
||||||
#define WIFI_DRIVER_MODULE_NAME "wlan"
|
#define WIFI_DRIVER_MODULE_NAME "wlan"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WIFI_SDIO_IF_DRIVER_MODULE_PATH
|
#ifndef WIFI_SDIO_IF_DRIVER_MODULE_PATH
|
||||||
#define WIFI_SDIO_IF_DRIVER_MODULE_PATH "/system/lib/modules/librasdioif.ko"
|
#define WIFI_SDIO_IF_DRIVER_MODULE_PATH "/system/lib/modules/librasdioif.ko"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WIFI_SDIO_IF_DRIVER_MODULE_NAME
|
#ifndef WIFI_SDIO_IF_DRIVER_MODULE_NAME
|
||||||
#define WIFI_SDIO_IF_DRIVER_MODULE_NAME "librasdioif"
|
#define WIFI_SDIO_IF_DRIVER_MODULE_NAME "librasdioif"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WIFI_SDIO_IF_DRIVER_MODULE_ARG
|
#ifndef WIFI_SDIO_IF_DRIVER_MODULE_ARG
|
||||||
#define WIFI_SDIO_IF_DRIVER_MODULE_ARG ""
|
#define WIFI_SDIO_IF_DRIVER_MODULE_ARG ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIFI_DRIVER_MODULE_ARG
|
#ifdef WIFI_DRIVER_MODULE_ARG
|
||||||
#undef WIFI_DRIVER_MODULE_ARG
|
#undef WIFI_DRIVER_MODULE_ARG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WIFI_DRIVER_MODULE_ARG "con_mode=1"
|
#define WIFI_DRIVER_MODULE_ARG "con_mode=1"
|
||||||
|
|
||||||
extern int init_module(const char *name, u32, const s8 *);
|
extern int init_module(const char *name, u32, const s8 *);
|
||||||
extern int delete_module(const char *name, int);
|
extern int delete_module(const char *name, int);
|
||||||
|
|
||||||
static s32 check_driver_loaded( const s8 * tag)
|
static s32 check_driver_loaded( const s8 * tag)
|
||||||
{
|
{
|
||||||
FILE *proc;
|
FILE *proc;
|
||||||
s8 line[126];
|
s8 line[126];
|
||||||
|
|
||||||
if ((proc = fopen("/proc/modules", "r")) == NULL) {
|
if ((proc = fopen("/proc/modules", "r")) == NULL) {
|
||||||
LOGW("Could not open %s: %s", "/proc/modules", strerror(errno));
|
LOGW("Could not open %s: %s", "/proc/modules", strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((fgets(line, sizeof(line), proc)) != NULL) {
|
while ((fgets(line, sizeof(line), proc)) != NULL) {
|
||||||
if (strncmp(line, tag, strlen(tag)) == 0) {
|
if (strncmp(line, tag, strlen(tag)) == 0) {
|
||||||
fclose(proc);
|
fclose(proc);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(proc);
|
fclose(proc);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static s32 insmod(const s8 *filename, const s8 *args, const s8 * tag)
|
static s32 insmod(const s8 *filename, const s8 *args, const s8 * tag)
|
||||||
{
|
{
|
||||||
#ifndef SDK_TEST
|
#ifndef SDK_TEST
|
||||||
void *module;
|
void *module;
|
||||||
s32 size;
|
s32 size;
|
||||||
s32 ret = 0;
|
s32 ret = 0;
|
||||||
|
|
||||||
if ( check_driver_loaded(tag) ) {
|
if ( check_driver_loaded(tag) ) {
|
||||||
LOGE("Driver: %s already loaded\n", filename);
|
LOGE("Driver: %s already loaded\n", filename);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGD("Loading Driver: %s %s\n", filename, args);
|
LOGD("Loading Driver: %s %s\n", filename, args);
|
||||||
|
|
||||||
module = (void*)load_file(filename, (unsigned int*)&size);
|
module = (void*)load_file(filename, (unsigned int*)&size);
|
||||||
|
|
||||||
if (!module) {
|
if (!module) {
|
||||||
LOGE("Cannot load file: %s\n", filename);
|
LOGE("Cannot load file: %s\n", filename);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = init_module(module, size, args);
|
ret = init_module(module, size, args);
|
||||||
|
|
||||||
if ( ret ) {
|
if ( ret ) {
|
||||||
LOGE("init_module (%s:%d) failed\n", filename, (int)size);
|
LOGE("init_module (%s:%d) failed\n", filename, (int)size);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(module);
|
free(module);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static s32 rmmod(const s8 *modname)
|
static s32 rmmod(const s8 *modname)
|
||||||
{
|
{
|
||||||
#ifndef SDK_TEST
|
#ifndef SDK_TEST
|
||||||
s32 ret = 0;
|
s32 ret = 0;
|
||||||
s32 maxtry = 10;
|
s32 maxtry = 10;
|
||||||
|
|
||||||
while (maxtry-- > 0) {
|
while (maxtry-- > 0) {
|
||||||
ret = delete_module(modname, O_NONBLOCK | O_EXCL);
|
ret = delete_module(modname, O_NONBLOCK | O_EXCL);
|
||||||
|
|
||||||
if (ret < 0 && errno == EAGAIN){
|
if (ret < 0 && errno == EAGAIN){
|
||||||
usleep(50000);
|
usleep(50000);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
LOGD("Unable to unload driver module \"%s\": %s\n",
|
LOGD("Unable to unload driver module \"%s\": %s\n",
|
||||||
modname, strerror(errno));
|
modname, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static const s8 SDIO_POLLING_ON[] = "/etc/init.qcom.sdio.sh 1";
|
static const s8 SDIO_POLLING_ON[] = "/etc/init.qcom.sdio.sh 1";
|
||||||
static const s8 SDIO_POLLING_OFF[] = "/etc/init.qcom.sdio.sh 0";
|
static const s8 SDIO_POLLING_OFF[] = "/etc/init.qcom.sdio.sh 0";
|
||||||
|
|
||||||
s32 wifi_qsap_load_driver(void)
|
s32 wifi_qsap_load_driver(void)
|
||||||
{
|
{
|
||||||
s32 size;
|
s32 size;
|
||||||
s32 ret = 0;
|
s32 ret = 0;
|
||||||
s32 retry;
|
s32 retry;
|
||||||
|
|
||||||
/* Unload the station mode driver first */
|
/* Unload the station mode driver first */
|
||||||
wifi_qsap_unload_wifi_sta_driver();
|
wifi_qsap_unload_wifi_sta_driver();
|
||||||
|
|
||||||
if (system(SDIO_POLLING_ON)) {
|
if (system(SDIO_POLLING_ON)) {
|
||||||
LOGE("Could not turn on the polling...");
|
LOGE("Could not turn on the polling...");
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = insmod(WIFI_SDIO_IF_DRIVER_MODULE_PATH, WIFI_SDIO_IF_DRIVER_MODULE_ARG, WIFI_SDIO_IF_DRIVER_MODULE_NAME " ");
|
ret = insmod(WIFI_SDIO_IF_DRIVER_MODULE_PATH, WIFI_SDIO_IF_DRIVER_MODULE_ARG, WIFI_SDIO_IF_DRIVER_MODULE_NAME " ");
|
||||||
|
|
||||||
if ( ret != 0 ) {
|
if ( ret != 0 ) {
|
||||||
LOGE("init_module failed sdioif\n");
|
LOGE("init_module failed sdioif\n");
|
||||||
goto end;
|
ret = eERR_LOAD_FAILED_SDIOIF;
|
||||||
}
|
goto end;
|
||||||
|
}
|
||||||
sched_yield();
|
|
||||||
|
sched_yield();
|
||||||
ret = insmod(WIFI_DRIVER_MODULE_PATH, WIFI_DRIVER_MODULE_ARG, WIFI_DRIVER_MODULE_NAME " ");
|
|
||||||
|
ret = insmod(WIFI_DRIVER_MODULE_PATH, WIFI_DRIVER_MODULE_ARG, WIFI_DRIVER_MODULE_NAME " ");
|
||||||
if ( ret != 0 ) {
|
|
||||||
LOGE("init_module failed libra_softap\n");
|
if ( ret != 0 ) {
|
||||||
goto end;
|
if ( check_driver_loaded(WIFI_SDIO_IF_DRIVER_MODULE_NAME " ") ) {
|
||||||
}
|
if ( rmmod(WIFI_SDIO_IF_DRIVER_MODULE_NAME) ) {
|
||||||
|
LOGE("Unable to unload the station mode librasdioif driver\n");
|
||||||
sched_yield();
|
}
|
||||||
end:
|
}
|
||||||
if(system(SDIO_POLLING_OFF)) {
|
LOGE("init_module failed libra_softap\n");
|
||||||
LOGE("Could not turn off the polling...");
|
ret = eERR_LOAD_FAILED_SOFTAP;
|
||||||
}
|
goto end;
|
||||||
|
}
|
||||||
return ret;
|
|
||||||
}
|
sched_yield();
|
||||||
|
|
||||||
s32 wifi_qsap_unload_wifi_sta_driver(void)
|
ret = eSUCCESS;
|
||||||
{
|
|
||||||
s32 ret = 0;
|
end:
|
||||||
|
if(system(SDIO_POLLING_OFF)) {
|
||||||
if(system(SDIO_POLLING_ON)) {
|
LOGE("Could not turn off the polling...");
|
||||||
LOGE("Could not turn on the polling...");
|
}
|
||||||
}
|
|
||||||
|
return ret;
|
||||||
if ( check_driver_loaded(WIFI_DRIVER_MODULE_NAME " ") ) {
|
}
|
||||||
if ( rmmod(WIFI_DRIVER_MODULE_NAME) ) {
|
|
||||||
LOGE("Unable to unload the station mode wifi driver...\n");
|
s32 wifi_qsap_unload_wifi_sta_driver(void)
|
||||||
ret = 1;
|
{
|
||||||
goto end;
|
s32 ret = 0;
|
||||||
}
|
|
||||||
}
|
if(system(SDIO_POLLING_ON)) {
|
||||||
|
LOGE("Could not turn on the polling...");
|
||||||
sched_yield();
|
}
|
||||||
|
|
||||||
if ( check_driver_loaded(WIFI_SDIO_IF_DRIVER_MODULE_NAME " ") ) {
|
if ( check_driver_loaded(WIFI_DRIVER_MODULE_NAME " ") ) {
|
||||||
if ( rmmod(WIFI_SDIO_IF_DRIVER_MODULE_NAME) ) {
|
if ( rmmod(WIFI_DRIVER_MODULE_NAME) ) {
|
||||||
LOGE("Unable to unload the station mode librasdioif driver\n");
|
LOGE("Unable to unload the station mode wifi driver...\n");
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
sched_yield();
|
||||||
if(system(SDIO_POLLING_OFF)) {
|
|
||||||
LOGE("Could not turn off the polling...");
|
if ( check_driver_loaded(WIFI_SDIO_IF_DRIVER_MODULE_NAME " ") ) {
|
||||||
}
|
if ( rmmod(WIFI_SDIO_IF_DRIVER_MODULE_NAME) ) {
|
||||||
sched_yield();
|
LOGE("Unable to unload the station mode librasdioif driver\n");
|
||||||
return 0;
|
ret = 1;
|
||||||
}
|
goto end;
|
||||||
|
}
|
||||||
s32 wifi_qsap_unload_driver()
|
}
|
||||||
{
|
|
||||||
s32 ret = 0;
|
end:
|
||||||
|
if(system(SDIO_POLLING_OFF)) {
|
||||||
if(system(SDIO_POLLING_ON)) {
|
LOGE("Could not turn off the polling...");
|
||||||
LOGE("Could not turn on the polling...");
|
}
|
||||||
}
|
sched_yield();
|
||||||
|
return 0;
|
||||||
if ( check_driver_loaded(WIFI_DRIVER_MODULE_NAME " ") ) {
|
}
|
||||||
if ( rmmod(WIFI_DRIVER_MODULE_NAME) ) {
|
|
||||||
LOGE("Unable to unload the libra_softap driver\n");
|
s32 wifi_qsap_unload_driver()
|
||||||
ret = 1;
|
{
|
||||||
goto end;
|
s32 ret = eSUCCESS;
|
||||||
}
|
|
||||||
}
|
if(system(SDIO_POLLING_ON)) {
|
||||||
|
LOGE("Could not turn on the polling...");
|
||||||
sched_yield();
|
}
|
||||||
|
|
||||||
if ( check_driver_loaded(WIFI_SDIO_IF_DRIVER_MODULE_NAME " ") ) {
|
if ( check_driver_loaded(WIFI_DRIVER_MODULE_NAME " ") ) {
|
||||||
if ( rmmod(WIFI_SDIO_IF_DRIVER_MODULE_NAME) ) {
|
if ( rmmod(WIFI_DRIVER_MODULE_NAME) ) {
|
||||||
LOGE("Unable to unload the librasdioif driver\n");
|
LOGE("Unable to unload the libra_softap driver\n");
|
||||||
ret = 1;
|
ret = eERR_UNLOAD_FAILED_SOFTAP;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end:
|
|
||||||
if(system(SDIO_POLLING_OFF)) {
|
sched_yield();
|
||||||
LOGE("Could not turn off the polling...");
|
|
||||||
}
|
if ( check_driver_loaded(WIFI_SDIO_IF_DRIVER_MODULE_NAME " ") ) {
|
||||||
|
if ( rmmod(WIFI_SDIO_IF_DRIVER_MODULE_NAME) ) {
|
||||||
return 0;
|
LOGE("Unable to unload the librasdioif driver\n");
|
||||||
}
|
ret = eERR_UNLOAD_FAILED_SDIO;
|
||||||
|
goto end;
|
||||||
s32 wifi_qsap_stop_bss(void)
|
}
|
||||||
{
|
}
|
||||||
#define QCIEEE80211_IOCTL_STOPBSS (SIOCIWFIRSTPRIV + 6)
|
end:
|
||||||
s32 sock;
|
if(system(SDIO_POLLING_OFF)) {
|
||||||
s32 ret = eERR_STOP_BSS;
|
LOGE("Could not turn off the polling...");
|
||||||
s8 cmd[] = "stopbss";
|
}
|
||||||
s8 interface[128];
|
|
||||||
s8 *iface;
|
return ret;
|
||||||
s32 len = 128;
|
}
|
||||||
struct iwreq wrq;
|
|
||||||
struct iw_priv_args *priv_ptr;
|
s32 wifi_qsap_stop_bss(void)
|
||||||
|
{
|
||||||
if(NULL == (iface = qsap_get_config_value(CONFIG_FILE, "interface", interface, (u32*)&len))) {
|
#define QCIEEE80211_IOCTL_STOPBSS (SIOCIWFIRSTPRIV + 6)
|
||||||
LOGE("%s :interface error \n", __func__);
|
s32 sock;
|
||||||
return ret;
|
s32 ret = eERR_STOP_BSS;
|
||||||
}
|
s8 cmd[] = "stopbss";
|
||||||
|
s8 interface[128];
|
||||||
/* Issue the stopbss command to driver */
|
s8 *iface;
|
||||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
s32 len = 128;
|
||||||
|
struct iwreq wrq;
|
||||||
if (sock < 0) {
|
struct iw_priv_args *priv_ptr;
|
||||||
LOGE("Failed to open socket");
|
|
||||||
return eERR_STOP_BSS;
|
if(ENABLE != is_softap_enabled()) {
|
||||||
}
|
ret = eERR_BSS_NOT_STARTED;
|
||||||
|
return ret;
|
||||||
strncpy(wrq.ifr_name, iface, sizeof(wrq.ifr_name));
|
}
|
||||||
wrq.u.data.length = sizeof(cmd);
|
|
||||||
wrq.u.data.pointer = cmd;
|
if(NULL == (iface = qsap_get_config_value(CONFIG_FILE, "interface", interface, (u32*)&len))) {
|
||||||
wrq.u.data.flags = 0;
|
LOGE("%s :interface error \n", __func__);
|
||||||
|
return ret;
|
||||||
ret = ioctl(sock, QCIEEE80211_IOCTL_STOPBSS, &wrq);
|
}
|
||||||
|
|
||||||
/* Here IOCTL is always returning non Zero: temporary fix untill driver is fixed*/
|
/* Issue the stopbss command to driver */
|
||||||
ret = 0;
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
close(sock);
|
|
||||||
|
if (sock < 0) {
|
||||||
if (ret) {
|
LOGE("Failed to open socket");
|
||||||
LOGE("IOCTL stopbss failed: %ld", ret);
|
return eERR_STOP_BSS;
|
||||||
ret = eERR_STOP_BSS;
|
}
|
||||||
} else {
|
|
||||||
LOGD("STOP BSS ISSUED");
|
strncpy(wrq.ifr_name, iface, sizeof(wrq.ifr_name));
|
||||||
ret = eSUCCESS;
|
wrq.u.data.length = sizeof(cmd);
|
||||||
}
|
wrq.u.data.pointer = cmd;
|
||||||
|
wrq.u.data.flags = 0;
|
||||||
sched_yield();
|
|
||||||
return ret;
|
ret = ioctl(sock, QCIEEE80211_IOCTL_STOPBSS, &wrq);
|
||||||
}
|
|
||||||
|
/* Here IOCTL is always returning non Zero: temporary fix untill driver is fixed*/
|
||||||
s32 is_softap_enabled(void)
|
ret = 0;
|
||||||
{
|
close(sock);
|
||||||
s8 stat[32] = {0};
|
|
||||||
|
if (ret) {
|
||||||
if ( property_get("init.svc.hostapd", stat, NULL) &&
|
LOGE("IOCTL stopbss failed: %ld", ret);
|
||||||
(strcmp(stat, "running") == 0)) {
|
ret = eERR_STOP_BSS;
|
||||||
LOGD("HOSTAPD enabled \n");
|
} else {
|
||||||
return ENABLE;
|
LOGD("STOP BSS ISSUED");
|
||||||
}
|
ret = eSUCCESS;
|
||||||
|
}
|
||||||
LOGD("HOSTAPD disabled \n");
|
|
||||||
return DISABLE;
|
sched_yield();
|
||||||
}
|
return ret;
|
||||||
|
}
|
||||||
s32 commit(void)
|
|
||||||
{
|
s32 is_softap_enabled(void)
|
||||||
#ifndef SDK_TEST
|
{
|
||||||
s32 ret = eERR_COMMIT;
|
s8 stat[32] = {0};
|
||||||
|
|
||||||
if ( is_softap_enabled() ) {
|
if ( property_get("init.svc.hostapd", stat, NULL) &&
|
||||||
/** Stop BSS */
|
(strcmp(stat, "running") == 0)) {
|
||||||
if(eSUCCESS != wifi_qsap_stop_bss()) {
|
LOGD("HOSTAPD enabled \n");
|
||||||
LOGE("%s: stop bss failed \n", __func__);
|
return ENABLE;
|
||||||
return ret;
|
}
|
||||||
}
|
|
||||||
sleep(1);
|
LOGD("HOSTAPD disabled \n");
|
||||||
}
|
return DISABLE;
|
||||||
|
}
|
||||||
ret = wifi_qsap_start_softap();
|
|
||||||
|
s32 commit(void)
|
||||||
if( eSUCCESS != ret )
|
{
|
||||||
wifi_qsap_unload_driver();
|
#ifndef SDK_TEST
|
||||||
|
s32 ret = eERR_COMMIT;
|
||||||
return ret;
|
|
||||||
#else
|
if ( is_softap_enabled() ) {
|
||||||
return eSUCCESS;
|
/** Stop BSS */
|
||||||
#endif
|
if(eSUCCESS != (ret = wifi_qsap_stop_bss())) {
|
||||||
}
|
LOGE("%s: stop bss failed \n", __func__);
|
||||||
|
return ret;
|
||||||
s32 wifi_qsap_start_softap()
|
}
|
||||||
{
|
sleep(1);
|
||||||
s32 retry = 4;
|
}
|
||||||
|
|
||||||
LOGD("Starting Soft AP...\n");
|
ret = wifi_qsap_start_softap();
|
||||||
|
|
||||||
while(--retry ) {
|
if( eSUCCESS != ret )
|
||||||
/** Stop hostapd */
|
wifi_qsap_unload_driver();
|
||||||
if(0 != property_set("ctl.start", "hostapd")) {
|
|
||||||
LOGE("failed \n");
|
return ret;
|
||||||
continue;
|
#else
|
||||||
}
|
return eSUCCESS;
|
||||||
|
#endif
|
||||||
sleep(1);
|
}
|
||||||
|
|
||||||
if ( is_softap_enabled() ) {
|
s32 wifi_qsap_start_softap()
|
||||||
LOGD("success \n");
|
{
|
||||||
return eSUCCESS;
|
s32 retry = 4;
|
||||||
}
|
|
||||||
}
|
LOGD("Starting Soft AP...\n");
|
||||||
|
|
||||||
LOGE("Unable to start the SoftAP\n");
|
/* Delete control interface if it was left over because of previous crash */
|
||||||
return eERR_START_SAP;
|
if ( !is_softap_enabled() ) {
|
||||||
}
|
qsap_del_ctrl_iface();
|
||||||
|
}
|
||||||
s32 wifi_qsap_stop_softap()
|
|
||||||
{
|
while(--retry ) {
|
||||||
if ( is_softap_enabled() ) {
|
/** Stop hostapd */
|
||||||
LOGD("Stopping BSS ..... ");
|
if(0 != property_set("ctl.start", "hostapd")) {
|
||||||
|
LOGE("failed \n");
|
||||||
/** Stop the BSS */
|
continue;
|
||||||
if (eSUCCESS != wifi_qsap_stop_bss()) {
|
}
|
||||||
LOGE("failed \n");
|
|
||||||
return eERR_STOP_SAP;
|
sleep(1);
|
||||||
}
|
|
||||||
sleep(1);
|
if ( is_softap_enabled() ) {
|
||||||
}
|
LOGD("success \n");
|
||||||
|
return eSUCCESS;
|
||||||
return eSUCCESS;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 wifi_qsap_reload_softap()
|
LOGE("Unable to start the SoftAP\n");
|
||||||
{
|
return eERR_START_SAP;
|
||||||
s32 ret = eERR_RELOAD_SAP;
|
}
|
||||||
|
|
||||||
/** SDK API to reload the firmware */
|
s32 wifi_qsap_stop_softap()
|
||||||
if (eSUCCESS != wifi_qsap_stop_softap()) {
|
{
|
||||||
return ret;
|
s32 ret = eSUCCESS;
|
||||||
}
|
|
||||||
|
if ( is_softap_enabled() ) {
|
||||||
if (eSUCCESS != wifi_qsap_unload_driver()) {
|
LOGD("Stopping BSS ..... ");
|
||||||
return ret;
|
|
||||||
}
|
/** Stop the BSS */
|
||||||
|
if (eSUCCESS != (ret = wifi_qsap_stop_bss()) ) {
|
||||||
usleep(500000);
|
LOGE("failed \n");
|
||||||
|
return ret;
|
||||||
if (eSUCCESS != wifi_qsap_load_driver()) {
|
}
|
||||||
return ret;
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(1);
|
return ret;
|
||||||
|
}
|
||||||
if (eSUCCESS != wifi_qsap_start_softap()) {
|
|
||||||
wifi_qsap_unload_driver();
|
s32 wifi_qsap_reload_softap()
|
||||||
return ret;
|
{
|
||||||
}
|
s32 ret = eERR_RELOAD_SAP;
|
||||||
|
|
||||||
return eSUCCESS;
|
/** SDK API to reload the firmware */
|
||||||
}
|
if (eSUCCESS != (ret = wifi_qsap_stop_softap())) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eSUCCESS != (ret = wifi_qsap_unload_driver())) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
usleep(500000);
|
||||||
|
|
||||||
|
if (eSUCCESS != (ret = wifi_qsap_load_driver())) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
if (eSUCCESS != (ret = wifi_qsap_start_softap())) {
|
||||||
|
wifi_qsap_unload_driver();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return eSUCCESS;
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
#define QCSAP_IOCTL_GET_CHANNEL (SIOCIWFIRSTPRIV+9)
|
#define QCSAP_IOCTL_GET_CHANNEL (SIOCIWFIRSTPRIV+9)
|
||||||
#define QCSAP_IOCTL_ASSOC_STA_MACADDR (SIOCIWFIRSTPRIV+10)
|
#define QCSAP_IOCTL_ASSOC_STA_MACADDR (SIOCIWFIRSTPRIV+10)
|
||||||
#define QCSAP_IOCTL_DISASSOC_STA (SIOCIWFIRSTPRIV+11)
|
#define QCSAP_IOCTL_DISASSOC_STA (SIOCIWFIRSTPRIV+11)
|
||||||
|
#define QCSAP_IOCTL_AP_STATS (SIOCIWFIRSTPRIV+12)
|
||||||
|
|
||||||
//#define LOG_TAG "QCSDK-"
|
//#define LOG_TAG "QCSDK-"
|
||||||
|
|
||||||
@@ -134,6 +135,9 @@ static s8 *cmd_list[eCMD_LAST] = {
|
|||||||
"country_code",
|
"country_code",
|
||||||
"intra_bss_forward",
|
"intra_bss_forward",
|
||||||
"regulatory_domain",
|
"regulatory_domain",
|
||||||
|
"apstat",
|
||||||
|
"auto_shut_off_time",
|
||||||
|
"energy_detect_threshold",
|
||||||
};
|
};
|
||||||
|
|
||||||
static s8 *qsap_str[eSTR_LAST] = {
|
static s8 *qsap_str[eSTR_LAST] = {
|
||||||
@@ -153,7 +157,9 @@ static s8 *qsap_str[eSTR_LAST] = {
|
|||||||
"ieee80211n",
|
"ieee80211n",
|
||||||
"ctrl_interface",
|
"ctrl_interface",
|
||||||
"interface",
|
"interface",
|
||||||
"eap_server"
|
"eap_server",
|
||||||
|
"gAPAutoShutOff",
|
||||||
|
"gEnablePhyAgcListenMode",
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Supported operating mode */
|
/** Supported operating mode */
|
||||||
@@ -775,7 +781,7 @@ static void qsap_remove_from_file(s8 *pfile, s8 *pVal, s8 *presp, u32 *plen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(MAX_CONF_LINE_LEN == snprintf(buf, MAX_CONF_LINE_LEN, "%s~", pfile)) {
|
if(MAX_CONF_LINE_LEN == snprintf(buf, MAX_CONF_LINE_LEN, "%s~", pfile)) {
|
||||||
buf[MAX_CONF_LINE_LEN] = '\0';
|
buf[MAX_CONF_LINE_LEN-1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Open a temporary file */
|
/** Open a temporary file */
|
||||||
@@ -827,7 +833,7 @@ static void qsap_remove_from_file(s8 *pfile, s8 *pVal, s8 *presp, u32 *plen)
|
|||||||
fclose(ftmp);
|
fclose(ftmp);
|
||||||
|
|
||||||
if(MAX_CONF_LINE_LEN == snprintf(buf, MAX_CONF_LINE_LEN, "%s~", pfile)) {
|
if(MAX_CONF_LINE_LEN == snprintf(buf, MAX_CONF_LINE_LEN, "%s~", pfile)) {
|
||||||
buf[MAX_CONF_LINE_LEN] = '\0';
|
buf[MAX_CONF_LINE_LEN-1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Restore the configuration file */
|
/** Restore the configuration file */
|
||||||
@@ -1106,6 +1112,10 @@ int qsap_get_operating_channel(s32 *pchan)
|
|||||||
s8 *pif;
|
s8 *pif;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if(ENABLE != is_softap_enabled()) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if(NULL == (pif = qsap_get_config_value(pconffile, qsap_str[STR_INTERFACE], interface, &len))) {
|
if(NULL == (pif = qsap_get_config_value(pconffile, qsap_str[STR_INTERFACE], interface, &len))) {
|
||||||
LOGE("%s :interface error \n", __func__);
|
LOGE("%s :interface error \n", __func__);
|
||||||
goto error;
|
goto error;
|
||||||
@@ -1209,6 +1219,10 @@ void qsap_get_associated_sta_mac(s8 *presp, u32 *plen)
|
|||||||
u32 recvLen;
|
u32 recvLen;
|
||||||
u32 tlen;
|
u32 tlen;
|
||||||
|
|
||||||
|
if(ENABLE != is_softap_enabled()) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if(NULL == (pif = qsap_get_config_value(pconffile, qsap_str[STR_INTERFACE], interface, &len))) {
|
if(NULL == (pif = qsap_get_config_value(pconffile, qsap_str[STR_INTERFACE], interface, &len))) {
|
||||||
LOGE("%s :interface error \n", __func__);
|
LOGE("%s :interface error \n", __func__);
|
||||||
goto error;
|
goto error;
|
||||||
@@ -1290,6 +1304,90 @@ static void qsap_read_wep_key(s8 *pfile, s8 *pcmd, s8 *presp, u32 *plen, s8 *var
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void qsap_read_ap_stats(s8 *presp, u32 *plen)
|
||||||
|
{
|
||||||
|
int sock, ret;
|
||||||
|
struct iwreq wrq;
|
||||||
|
s8 interface[MAX_CONF_LINE_LEN];
|
||||||
|
u32 len = MAX_CONF_LINE_LEN;
|
||||||
|
s8 *pif;
|
||||||
|
s8 *pbuf, *pout;
|
||||||
|
u32 recvLen;
|
||||||
|
u32 tlen;
|
||||||
|
|
||||||
|
if(ENABLE != is_softap_enabled()) {
|
||||||
|
*plen = snprintf(presp, *plen, "%s", ERR_SOFTAP_NOT_STARTED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(NULL == (pif = qsap_get_config_value(pconffile, qsap_str[STR_INTERFACE], interface, &len))) {
|
||||||
|
LOGE("%s :interface error \n", __func__);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
interface[len] = '\0';
|
||||||
|
|
||||||
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
if(sock < 0) {
|
||||||
|
LOGE("%s :socket failure \n", __func__);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
pbuf = (s8 *)malloc(MAX_RESP_LEN);
|
||||||
|
if(NULL == pbuf) {
|
||||||
|
LOGE("%s :No memory \n", __func__);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(wrq.ifr_name, pif, sizeof(wrq.ifr_name));
|
||||||
|
wrq.u.data.length = MAX_RESP_LEN;
|
||||||
|
wrq.u.data.pointer = (void *)pbuf;
|
||||||
|
wrq.u.data.flags = 0;
|
||||||
|
|
||||||
|
ret = ioctl(sock, QCSAP_IOCTL_AP_STATS, &wrq);
|
||||||
|
if(ret < 0) {
|
||||||
|
LOGE("%s :ioctl failure \n", __func__);
|
||||||
|
free(pbuf);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(*plen == (recvLen = snprintf(presp, *plen, "%s %s=%s", SUCCESS, cmd_list[eCMD_AP_STATISTICS], pbuf))){
|
||||||
|
presp[recvLen-1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
*plen = recvLen;
|
||||||
|
|
||||||
|
free(pbuf);
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
error:
|
||||||
|
*plen = snprintf(presp, *plen, "%s", ERR_UNKNOWN);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void qsap_read_autoshutoff(s8 *presp, u32 *plen)
|
||||||
|
{
|
||||||
|
u32 tlen, time = 0;
|
||||||
|
s8 *ptime;
|
||||||
|
|
||||||
|
tlen = *plen;
|
||||||
|
|
||||||
|
if(NULL == (ptime = qsap_get_config_value(fIni, qsap_str[STR_AP_AUTOSHUTOFF], presp, &tlen))) {
|
||||||
|
/** unable to read the AP shutoff time */
|
||||||
|
LOGE("%s :Failed to read AP shutoff time\n", __func__);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
time = atoi(ptime);
|
||||||
|
time = time / 60; /** Convert seconds to minutes */
|
||||||
|
}
|
||||||
|
|
||||||
|
*plen = snprintf(presp, *plen, "success %s=%ld", cmd_list[eCMD_AP_AUTOSHUTOFF], time);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* Get the configuration information from the softAP configuration
|
* Get the configuration information from the softAP configuration
|
||||||
@@ -1429,6 +1527,18 @@ static void qsap_get_from_config(esap_cmd_t cNum, s8 *presp, u32 *plen)
|
|||||||
qsap_read_cfg(fIni, qsap_str[STR_COUNTRY_CODE_IN_INI], presp, plen, cmd_list[eCMD_COUNTRY_CODE], GET_ENABLED_ONLY);
|
qsap_read_cfg(fIni, qsap_str[STR_COUNTRY_CODE_IN_INI], presp, plen, cmd_list[eCMD_COUNTRY_CODE], GET_ENABLED_ONLY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case eCMD_AP_STATISTICS:
|
||||||
|
qsap_read_ap_stats(presp, plen);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case eCMD_AP_AUTOSHUTOFF:
|
||||||
|
qsap_read_autoshutoff(presp, plen);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case eCMD_AP_ENERGY_DETECT_TH:
|
||||||
|
qsap_read_cfg(fIni, qsap_str[STR_AP_ENERGY_DETECT_TH], presp, plen, cmd_list[eCMD_AP_ENERGY_DETECT_TH], GET_ENABLED_ONLY);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/** Error case */
|
/** Error case */
|
||||||
*plen = snprintf(presp, *plen, "%s", ERR_INVALID_ARG);
|
*plen = snprintf(presp, *plen, "%s", ERR_INVALID_ARG);
|
||||||
@@ -1576,7 +1686,7 @@ static s16 wifi_qsap_reset_to_default(s8 *pcfgfile, s8 *pdefault)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(MAX_CONF_LINE_LEN == snprintf(buf, MAX_CONF_LINE_LEN, "%s~", pcfgfile)) {
|
if(MAX_CONF_LINE_LEN == snprintf(buf, MAX_CONF_LINE_LEN, "%s~", pcfgfile)) {
|
||||||
buf[MAX_CONF_LINE_LEN] = '\0';
|
buf[MAX_CONF_LINE_LEN-1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
ftmp = fopen(buf, "w+");
|
ftmp = fopen(buf, "w+");
|
||||||
@@ -1594,7 +1704,7 @@ static s16 wifi_qsap_reset_to_default(s8 *pcfgfile, s8 *pdefault)
|
|||||||
fclose(ftmp);
|
fclose(ftmp);
|
||||||
|
|
||||||
if(MAX_CONF_LINE_LEN == snprintf(buf, MAX_CONF_LINE_LEN, "%s~", pcfgfile)) {
|
if(MAX_CONF_LINE_LEN == snprintf(buf, MAX_CONF_LINE_LEN, "%s~", pcfgfile)) {
|
||||||
buf[MAX_CONF_LINE_LEN] = '\0';
|
buf[MAX_CONF_LINE_LEN-1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(eERR_UNKNOWN == rename(buf, pcfgfile))
|
if(eERR_UNKNOWN == rename(buf, pcfgfile))
|
||||||
@@ -1607,6 +1717,39 @@ static s16 wifi_qsap_reset_to_default(s8 *pcfgfile, s8 *pdefault)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define CTRL_IFACE_PATH_LEN (128)
|
#define CTRL_IFACE_PATH_LEN (128)
|
||||||
|
|
||||||
|
void qsap_del_ctrl_iface(void)
|
||||||
|
{
|
||||||
|
u32 len;
|
||||||
|
s8 dst_path[CTRL_IFACE_PATH_LEN], *pcif, *pif;
|
||||||
|
s8 interface[64];
|
||||||
|
s8 path[CTRL_IFACE_PATH_LEN + 64];
|
||||||
|
|
||||||
|
len = CTRL_IFACE_PATH_LEN;
|
||||||
|
|
||||||
|
if(NULL == (pcif = qsap_get_config_value(pconffile, qsap_str[STR_CTRL_INTERFACE], dst_path, &len))) {
|
||||||
|
LOGE("%s :ctrl_iface path error \n", __func__);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = 64;
|
||||||
|
|
||||||
|
if(NULL == (pif = qsap_get_config_value(pconffile, qsap_str[STR_INTERFACE], interface, &len))) {
|
||||||
|
LOGE("%s :interface error \n", __func__);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((int)sizeof(path) <= snprintf(path, sizeof(path)-1, "%s/%s", pcif, pif)) {
|
||||||
|
LOGE("Iface path : error, %s \n", path);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
unlink(path);
|
||||||
|
|
||||||
|
error:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static int qsap_send_cmd_to_hostapd(s8 *pcmd)
|
static int qsap_send_cmd_to_hostapd(s8 *pcmd)
|
||||||
{
|
{
|
||||||
int sock;
|
int sock;
|
||||||
@@ -1895,6 +2038,10 @@ void qsap_disassociate_sta(s8 *pVal, s8 *presp, u32 *plen)
|
|||||||
u32 len = MAX_CONF_LINE_LEN;
|
u32 len = MAX_CONF_LINE_LEN;
|
||||||
s8 *pif;
|
s8 *pif;
|
||||||
|
|
||||||
|
if(ENABLE != is_softap_enabled()) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
if(NULL == (pif = qsap_get_config_value(pconffile, qsap_str[STR_INTERFACE], pbuf, &len))) {
|
if(NULL == (pif = qsap_get_config_value(pconffile, qsap_str[STR_INTERFACE], pbuf, &len))) {
|
||||||
LOGE("%s :interface error \n", __func__);
|
LOGE("%s :interface error \n", __func__);
|
||||||
goto end;
|
goto end;
|
||||||
@@ -2561,6 +2708,26 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen)
|
|||||||
ini = INI_CONF_FILE;
|
ini = INI_CONF_FILE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case eCMD_AP_AUTOSHUTOFF:
|
||||||
|
value = atoi(pVal);
|
||||||
|
if(TRUE != IS_VALID_APSHUTOFFTIME(value))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
snprintf(pVal, MAX_INT_STR, "%ld", value*60);
|
||||||
|
cNum = STR_AP_AUTOSHUTOFF;
|
||||||
|
ini = INI_CONF_FILE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case eCMD_AP_ENERGY_DETECT_TH:
|
||||||
|
value = atoi(pVal);
|
||||||
|
if(TRUE != IS_VALID_ENERGY_DETECT_TH(value))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
snprintf(pVal, MAX_INT_STR, "%ld", value);
|
||||||
|
cNum = STR_AP_ENERGY_DETECT_TH;
|
||||||
|
ini = INI_CONF_FILE;
|
||||||
|
break;
|
||||||
|
|
||||||
default: ;
|
default: ;
|
||||||
/** Do not goto error, in default case */
|
/** Do not goto error, in default case */
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user