Subject: Re: kern/31295: iwi(4) does not associate with AP
To: None <skrll@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: Nick Hudson <nick.hudson@dsl.pipex.com>
List: netbsd-bugs
Date: 09/12/2005 21:37:02
The following reply was made to PR kern/31295; it has been noted by GNATS.

From: Nick Hudson <nick.hudson@dsl.pipex.com>
To: gnats-bugs@netbsd.org
Cc: gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: kern/31295: iwi(4) does not associate with AP
Date: Mon, 12 Sep 2005 22:36:14 +0000

 --Boundary-00=_fLgJDRQRaF2lOAo
 Content-Type: text/plain;
   charset="iso-8859-1"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 On Sunday 11 September 2005 19:29, scw@netbsd.org wrote:
 > >Synopsis:       iwi(4) does not associate with AP
 [...]
 
 I think this patch fixes it. Could you please test?
 
 Thanks,
 Nick
 
 --Boundary-00=_fLgJDRQRaF2lOAo
 Content-Type: text/x-diff;
   charset="iso-8859-1";
   name="iwi.31295.diffs"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
 	filename="iwi.31295.diffs"
 
 Index: dev/pci/if_iwi.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/pci/if_iwi.c,v
 retrieving revision 1.22
 diff -u -r1.22 if_iwi.c
 --- dev/pci/if_iwi.c	12 Sep 2005 21:15:04 -0000	1.22
 +++ dev/pci/if_iwi.c	12 Sep 2005 21:34:47 -0000
 @@ -2110,21 +2110,44 @@
  iwi_scan(struct iwi_softc *sc)
  {
  	struct ieee80211com *ic = &sc->sc_ic;
 -	struct iwi_scan scan;
 +	struct iwi_scan_v2 scan;
 +	u_int32_t type;
  	u_int8_t *p;
  	int i, count;
  
  	(void)memset(&scan, 0, sizeof scan);
 -	scan.type = IWI_SCAN_TYPE_BROADCAST;
 -	scan.dwelltime = htole16(sc->dwelltime);
  
 -	p = scan.channels;
 +	scan.dwelltime[IWI_SCAN_TYPE_ACTIVE_BROADCAST] =
 +	    htole16(sc->dwelltime);
 +	scan.dwelltime[IWI_SCAN_TYPE_ACTIVE_BDIRECT] =
 +	    htole16(sc->dwelltime);
 +
 +	/* tell the firmware about the desired essid */
 +	if (ic->ic_des_esslen) {
 +		int error;
 +
 +		DPRINTF(("%s: Setting adapter desired ESSID to %s\n",
 +		    __func__, ic->ic_des_essid));
 +
 +		error = iwi_cmd(sc, IWI_CMD_SET_ESSID,
 +		    ic->ic_des_essid, ic->ic_des_esslen, 1);
 +		if (error)
 +			return error;
 +
 +		type = IWI_SCAN_TYPE_ACTIVE_BDIRECT;
 +	} else {
 +		type = IWI_SCAN_TYPE_ACTIVE_BROADCAST;
 +	}
 +
 +	p = &scan.channels[0];
  	count = 0;
 +
  	for (i = 0; i <= IEEE80211_CHAN_MAX; i++) {
  		if (IEEE80211_IS_CHAN_5GHZ(&ic->ic_channels[i]) &&
  		    isset(ic->ic_chan_active, i)) {
  			*++p = i;
  			count++;
 +			iwi_scan_type_set(scan, i, type);
  		}
  	}
  	*(p - count) = IWI_CHAN_5GHZ | count;
 @@ -2135,12 +2158,13 @@
  		    isset(ic->ic_chan_active, i)) {
  			*++p = i;
  			count++;
 +			iwi_scan_type_set(scan, i, type);
  		}
  	}
  	*(p - count) = IWI_CHAN_2GHZ | count;
  
  	DPRINTF(("Start scanning\n"));
 -	return iwi_cmd(sc, IWI_CMD_SCAN, &scan, sizeof scan, 1);
 +	return iwi_cmd(sc, IWI_CMD_SCAN_V2, &scan, sizeof scan, 1);
  }
  
  static int
 Index: dev/pci/if_iwireg.h
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/pci/if_iwireg.h,v
 retrieving revision 1.6
 diff -u -r1.6 if_iwireg.h
 --- dev/pci/if_iwireg.h	12 Sep 2005 21:15:04 -0000	1.6
 +++ dev/pci/if_iwireg.h	12 Sep 2005 21:34:47 -0000
 @@ -249,6 +249,7 @@
  #define IWI_CMD_ASSOCIATE			21
  #define IWI_CMD_SET_RATES			22
  #define IWI_CMD_ABORT_SCAN			23
 +#define IWI_CMD_SCAN_V2				26
  #define IWI_CMD_SET_OPTIE			31
  #define IWI_CMD_DISABLE				33
  #define IWI_CMD_SET_IV				34
 @@ -316,11 +317,16 @@
  
  #define IWI_SCAN_CHANNELS	54
  
 +#define IWI_SCAN_TYPE_FIRST_BEACON	0
 +#define IWI_SCAN_TYPE_PASSIVE		1
 +#define IWI_SCAN_TYPE_ACTIVE_DIRECT	2
 +#define IWI_SCAN_TYPE_ACTIVE_BROADCAST	3
 +#define IWI_SCAN_TYPE_ACTIVE_BDIRECT	4
 +#define IWI_SCAN_TYPES			5
 +
  /* structure for command IWI_CMD_SCAN */
  struct iwi_scan {
  	u_int8_t	type;
 -#define IWI_SCAN_TYPE_PASSIVE		1
 -#define IWI_SCAN_TYPE_BROADCAST		3
  
  	u_int16_t	dwelltime;
  	u_int8_t	channels[IWI_SCAN_CHANNELS];
 @@ -330,6 +336,27 @@
  	u_int8_t	reserved[3];
  } __attribute__((__packed__));
  
 +#define iwi_scan_type_set(s, i, t) 			\
 +	do { 						\
 +		if ((i) % 2 == 0)			\
 +			(s).type[(i) / 2].lsn = (t);	\
 +		else					\
 +			(s).type[(i) / 2].msn = (t);	\
 +	} while(0)
 +
 +/* structure for command IWI_CMD_SCAN_V2 */
 +struct iwi_scan_v2 {
 +	u_int32_t	fsidx;
 +	u_int8_t	channels[IWI_SCAN_CHANNELS];
 +	struct {
 +		u_int8_t lsn:4;
 +		u_int8_t msn:4;
 +	} __attribute__ ((__packed__)) type[IWI_SCAN_CHANNELS / 2];
 +	u_int8_t	reserved1;
 +	u_int16_t	dwelltime[IWI_SCAN_TYPES];
 +
 +} __attribute__ ((__packed__));
 +
  /* structure for command IWI_CMD_SET_CONFIGURATION */
  struct iwi_configuration {
  	u_int8_t	bluetooth_coexistence;
 
 --Boundary-00=_fLgJDRQRaF2lOAo--