ref: 4040ea7a5eda976098131794e8df3b162cafa8f4
parent: b29e414bc64537c9af8d5ebd8f73775bceaa5fa2
author: cinap_lenrek <[email protected]>
date: Fri Oct 9 01:10:47 EDT 2015
wifi: quote value of parsed ether options introduce wificfg() function to convert ether->opt[] strings to wifictl messages, which needs quoting for the value. so etherX=type=iwl essid='something with spaces' works.
--- a/sys/src/9/pc/etheriwl.c
+++ b/sys/src/9/pc/etheriwl.c
@@ -2101,27 +2101,12 @@
static void
setoptions(Ether *edev)
{
- char buf[64], *p;
Ctlr *ctlr;
int i;
ctlr = edev->ctlr;
- for(i = 0; i < edev->nopt; i++){
- snprint(buf, sizeof(buf), "%s", edev->opt[i]);
- p = strchr(buf, '=');
- if(p != nil)
- *p = 0;
- if(strcmp(buf, "debug") == 0
- || strcmp(buf, "essid") == 0
- || strcmp(buf, "bssid") == 0){
- if(p != nil)
- *p = ' ';
- if(!waserror()){
- wifictl(ctlr->wifi, buf, strlen(buf));
- poperror();
- }
- }
- }
+ for(i = 0; i < edev->nopt; i++)
+ wificfg(ctlr->wifi, edev->opt[i]);
}
static void
--- a/sys/src/9/pc/etherrt2860.c
+++ b/sys/src/9/pc/etherrt2860.c
@@ -1306,19 +1306,11 @@
setoptions(Ether *edev)
{
Ctlr *ctlr;
- char buf[64];
int i;
ctlr = edev->ctlr;
- for(i = 0; i < edev->nopt; i++){
- if(strncmp(edev->opt[i], "essid=", 6) == 0){
- snprint(buf, sizeof(buf), "essid %s", edev->opt[i]+6);
- if(!waserror()){
- wifictl(ctlr->wifi, buf, strlen(buf));
- poperror();
- }
- }
- }
+ for(i = 0; i < edev->nopt; i++)
+ wificfg(ctlr->wifi, edev->opt[i]);
}
static void
--- a/sys/src/9/pc/etherwpi.c
+++ b/sys/src/9/pc/etherwpi.c
@@ -1491,27 +1491,12 @@
static void
setoptions(Ether *edev)
{
- char buf[64], *p;
Ctlr *ctlr;
int i;
ctlr = edev->ctlr;
- for(i = 0; i < edev->nopt; i++){
- snprint(buf, sizeof(buf), "%s", edev->opt[i]);
- p = strchr(buf, '=');
- if(p != nil)
- *p = 0;
- if(strcmp(buf, "debug") == 0
- || strcmp(buf, "essid") == 0
- || strcmp(buf, "bssid") == 0){
- if(p != nil)
- *p = ' ';
- if(!waserror()){
- wifictl(ctlr->wifi, buf, strlen(buf));
- poperror();
- }
- }
- }
+ for(i = 0; i < edev->nopt; i++)
+ wificfg(ctlr->wifi, edev->opt[i]);
}
static void
--- a/sys/src/9/pc/wifi.c
+++ b/sys/src/9/pc/wifi.c
@@ -814,6 +814,25 @@
return 0;
}
+void
+wificfg(Wifi *wifi, char *opt)
+{
+ char *p, buf[64];
+ int n;
+
+ if(strncmp(opt, "debug=", 6))
+ if(strncmp(opt, "essid=", 6))
+ if(strncmp(opt, "bssid=", 6))
+ return;
+ if((p = strchr(opt, '=')) == nil)
+ return;
+ if(waserror())
+ return;
+ n = snprint(buf, sizeof(buf), "%.*s %q", (int)(p - opt), opt, p+1);
+ wifictl(wifi, buf, n);
+ poperror();
+}
+
enum {
CMdebug,
CMessid,
--- a/sys/src/9/pc/wifi.h
+++ b/sys/src/9/pc/wifi.h
@@ -95,3 +95,4 @@
long wifistat(Wifi*, void*, long, ulong);
long wifictl(Wifi*, void*, long);
+void wificfg(Wifi*, char*);