Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Sep 2008 12:16:00 -0700
From:      Sam Leffler <sam@freebsd.org>
To:        John Hay <jhay@meraka.org.za>
Cc:        freebsd-mobile@freebsd.org
Subject:   Re: setting bssid in adhoc mode
Message-ID:  <48DE8670.60606@freebsd.org>
In-Reply-To: <20080927071046.GA94774@zibbi.meraka.csir.co.za>
References:  <20080922132500.GA25677@zibbi.meraka.csir.co.za>	<3a142e750809250741j7b9003e4q539618d1c9407def@mail.gmail.com>	<20080925161338.GA69284@zibbi.meraka.csir.co.za>	<3a142e750809251159p3f5f3bam11243b3f144859c2@mail.gmail.com>	<20080926055522.GA13842@zibbi.meraka.csir.co.za>	<48DD210E.6050300@freebsd.org> <20080927071046.GA94774@zibbi.meraka.csir.co.za>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------020202030001020600070906
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

John Hay wrote:
>>>>>>> I'm trying out the new ath/wlan stuff in current. Should one still be
>>>>>>> able to set the bssid in adhoc mode? We normally lock the bssid in
>>>>>>> an adhoc network because of problems that the network split and does
>>>>>>> not merge, if you do not do it.
>>>>>>>
>>>>>>> What I have done is this:
>>>>>>>
>>>>>>> # ifconfig wlan0 create wlandev ath0 wlanmode adhoc
>>>>>>> # ifconfig wlan0 ssid ptamesh up
>>>>>>>
>>>>>>> Up to here works well. It will scan and if it finds another node with
>>>>>>> the
>>>>>>> same ssid, it will "lock" on that channel and use the correct bssid.
>>>>>>>
>>>>>>> If it does not find another node with the same ssid, it will start it
>>>>>>> own thing on channel 10. But it looks like one cannot set the bssid.
>>>>>>>
>>>>>>> # ifconfig wlan0 bssid 02:07:ca:fe:ba:be
>>>>>>> ifconfig: 02:07:ca:fe:ba:be: bad value
>>>>>>>          
>>>>>>>               
>>>>>> I had similar experience with STA mode, instead I use ap (ap is alias
>>>>>> for bssid, at least it works in STA mode)
>>>>>> I never bothered is this bug in manual page, ifconfig or in something 
>>>>>> else
>>>>>> ...
>>>>>>        
>>>>>>             
>>>>> Ah, thanks yes, "ifconfig wlan0 ap 02:07:ca:fe:ba:be" works just fine.
>>>>> Just do not try to unset it with "ifconfig wlan0 ap -". That is an
>>>>> alias for "panic now" :-)
>>>>>      
>>>>>           
>>>> Well, on my system it doesnt panic here.
>>>> So more info to debug "your" panic is required ...
>>>>    
>>>>         
>>> I'll have to see if I can reproduce it.
>>>
>>>  
>>>       
>>>>> So it looks like ifconfig is getting confused with the many different
>>>>> uses of the keyword bssid.
>>>>>
>>>>> I must say I still do not understand what the other use for bssid is.
>>>>> Close to the end of ifconfig/ifieee80211.c there are these:
>>>>>
>>>>> DEF_CMD_ARG("bssid",            set80211bssid),
>>>>> DEF_CMD_ARG("ap",               set80211bssid),
>>>>> ...
>>>>> DEF_CLONE_CMD("bssid",  1,      set80211clone_bssid),
>>>>> DEF_CLONE_CMD("-bssid", 0,      set80211clone_bssid),
>>>>>
>>>>> So my guess is that I was hitting the clone version when in fact I
>>>>> needed the other version. Luckily ap does not have a clone version.
>>>>> So when should the clone version be used? And how does ifconfig
>>>>> decide which one to use?
>>>>>      
>>>>>           
>>> I looked into the ifconfig code a bit more. I think that with the
>>> current code in the ifconfig() and cmd_lookup() functions, it is
>>> imposssible to have two different keywords that share the same
>>> keyword. cmd_lookup() will always search until it finds the first
>>> instance in the list and return that. The first instance in this
>>> case being the last one added.
>>>  
>>>       
>> Correct.
>>
>>     
>>> So either the code must change or one of the bssid keywords have
>>> to change. My suggestion would be to keep the bssid for which ap
>>> is an alias and change the other one. Anybody have a suggestion
>>> of what to change it to?
>>>
>>>  
>>>       
>> I prefer to change the code to handle this ambiguity within 
>> ifieee80211.c.  You cannot use both together or at least they are 
>> redundant.  I'll look at it when I've got time; but don't let me 
>> distract you.
>>     
>
> So what should the behaviour be? How should ifconfig know which bssid
> function to use? Should the clone variant be used when it is used on
> the same line as create? And the other if there is not a create on the
> line? Or some other way? And should the other DEF_CLONE... keywords
> also be handled the same way?
>
> John
>   
Try the attached change.  It looked easier to fix this for all possible 
usage instead of complicating the 802.11 stuff.  The change forces all 
keywords marked "DEF_CLONE" to come first on the command line followed 
by keywords that are marked !DEF_CLONE.  At some point it's likely we'll 
need to stick a real parser in ifconfig but I think this change is small 
enough to just do it this way (it also slightly cleans up the hack for 
pushing the clone operation out before parsing/handling subsequent cmd 
line args).

    Sam


--------------020202030001020600070906
Content-Type: text/plain;
 name="ifconfig.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ifconfig.patch"

Index: ifconfig.c
===================================================================
--- ifconfig.c	(revision 183416)
+++ ifconfig.c	(working copy)
@@ -392,14 +392,21 @@
 }
 
 static const struct cmd *
-cmd_lookup(const char *name)
+cmd_lookup(const char *name, int iscreate)
 {
 #define	N(a)	(sizeof(a)/sizeof(a[0]))
 	const struct cmd *p;
 
 	for (p = cmds; p != NULL; p = p->c_next)
-		if (strcmp(name, p->c_name) == 0)
-			return p;
+		if (strcmp(name, p->c_name) == 0) {
+			if (iscreate) {
+				if (p->c_iscloneop)
+					return p;
+			} else {
+				if (!p->c_iscloneop)
+					return p;
+			}
+		}
 	return NULL;
 #undef N
 }
@@ -437,6 +444,7 @@
 ifconfig(int argc, char *const *argv, int iscreate, const struct afswtch *afp)
 {
 	const struct afswtch *nafp;
+	const struct cmd *p;
 	struct callback *cb;
 	int s;
 
@@ -452,9 +460,38 @@
 		err(1, "socket(family %u,SOCK_DGRAM", ifr.ifr_addr.sa_family);
 
 	while (argc > 0) {
-		const struct cmd *p;
-
-		p = cmd_lookup(*argv);
+		p = cmd_lookup(*argv, iscreate);
+		if (iscreate && p == NULL) {
+			/*
+			 * Push the clone create callback so the new
+			 * device is created and can be used for any
+			 * remaining arguments.
+			 */
+			cb = callbacks;
+			if (cb == NULL)
+				errx(1, "internal error, no callback");
+			callbacks = cb->cb_next;
+			cb->cb_func(s, cb->cb_arg);
+			iscreate = 0;
+			/*
+			 * Handle any address family spec that
+			 * immediately follows and potentially
+			 * recreate the socket.
+			 */
+			nafp = af_getbyname(*argv);
+			if (nafp != NULL) {
+				argc--, argv++;
+				if (nafp != afp) {
+					close(s);
+					afp = nafp;
+					goto top;
+				}
+			}
+			/*
+			 * Look for a normal parameter.
+			 */
+			continue;
+		}
 		if (p == NULL) {
 			/*
 			 * Not a recognized command, choose between setting
@@ -463,33 +500,6 @@
 			p = (setaddr ? &setifdstaddr_cmd : &setifaddr_cmd);
 		}
 		if (p->c_u.c_func || p->c_u.c_func2) {
-			if (iscreate && !p->c_iscloneop) { 
-				/*
-				 * Push the clone create callback so the new
-				 * device is created and can be used for any
-				 * remaining arguments.
-				 */
-				cb = callbacks;
-				if (cb == NULL)
-					errx(1, "internal error, no callback");
-				callbacks = cb->cb_next;
-				cb->cb_func(s, cb->cb_arg);
-				iscreate = 0;
-				/*
-				 * Handle any address family spec that
-				 * immediately follows and potentially
-				 * recreate the socket.
-				 */
-				nafp = af_getbyname(*argv);
-				if (nafp != NULL) {
-					argc--, argv++;
-					if (nafp != afp) {
-						close(s);
-						afp = nafp;
-						goto top;
-					}
-				}
-			}
 			if (p->c_parameter == NEXTARG) {
 				if (argv[1] == NULL)
 					errx(1, "'%s' requires argument",

--------------020202030001020600070906--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?48DE8670.60606>