android hostap命令,Android O热点hostapd.conf配置文件生成

Android M之前/data/misc/wifi/hostapd.conf文件是在

system/netd/server/SoftapController.cpp里面生成的

/*

* Arguments:

* argv[2] - wlan interface

* argv[3] - SSID

* argv[4] - Broadcast/Hidden

* argv[5] - Channel

* argv[6] - Security

* argv[7] - Key

*/

int SoftapController::setSoftap(int argc, char *argv[]) {

int hidden = 0;

int channel = AP_CHANNEL_DEFAULT;

if (argc < 5) {

ALOGE("Softap set is missing arguments. Please use:");

ALOGE("softap ");

return ResponseCode::CommandSyntaxError;

}

if (!strcasecmp(argv[4], "hidden"))

hidden = 1;

if (argc >= 5) {

channel = atoi(argv[5]);

if (channel <= 0)

channel = AP_CHANNEL_DEFAULT;

}

std::string wbuf(StringPrintf("interface=%s\n"

"driver=nl80211\n"

"ctrl_interface=/data/misc/wifi/hostapd\n"

"ssid=%s\n"

"channel=%d\n"

"ieee80211n=1\n"

"hw_mode=%c\n"

"ignore_broadcast_ssid=%d\n"

"wowlan_triggers=any\n",

argv[2], argv[3], channel, (channel <= 14) ? 'g' : 'a', hidden));

std::string fbuf;

if (argc > 7) {

char psk_str[2*SHA256_DIGEST_LENGTH+1];

if (!strcmp(argv[6], "wpa-psk")) {

generatePsk(argv[3], argv[7], psk_str);

fbuf = StringPrintf("%swpa=3\nwpa_pairwise=TKIP CCMP\nwpa_psk=%s\n", wbuf.c_str(), psk_str);

} else if (!strcmp(argv[6], "wpa2-psk")) {

generatePsk(argv[3], argv[7], psk_str);

fbuf = StringPrintf("%swpa=2\nrsn_pairwise=CCMP\nwpa_psk=%s\n", wbuf.c_str(), psk_str);

} else if (!strcmp(argv[6], "open")) {

fbuf = wbuf;

}

} else if (argc > 6) {

if (!strcmp(argv[6], "open")) {

fbuf = wbuf;

}

} else {

fbuf = wbuf;

}

if (!WriteStringToFile(fbuf, HOSTAPD_CONF_FILE, 0660, AID_SYSTEM, AID_WIFI)) {

ALOGE("Cannot write to \"%s\": %s", HOSTAPD_CONF_FILE, strerror(errno));

return ResponseCode::OperationFailed;

}

return ResponseCode::SoftapStatusResult;

}

Android O(可能是Android N开始)的已经挪到frameworks/opt/net/wifi/libwifi_system/hostapd_manager.cpp

bool HostapdManager::WriteHostapdConfig(const string& config) {

if (!WriteStringToFile(config, kHostapdConfigFilePath,

S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,

AID_WIFI, AID_WIFI)) {

int error = errno;

LOG(ERROR) << "Cannot write hostapd config to \""

<< kHostapdConfigFilePath << "\": " << strerror(error);

struct stat st;

int result = stat(kHostapdConfigFilePath, &st);

if (result == 0) {

LOG(ERROR) << "hostapd config file uid: "<< st.st_uid << ", gid: " << st.st_gid

<< ", mode: " << st.st_mode;

} else {

LOG(ERROR) << "Error calling stat() on hostapd config file: " << strerror(errno);

}

return false;

}

return true;

}

具体流程可以参考以下文章

(九十二) Android O WiFi热点 开启流程梳理续

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值