Share logic between encodeext and encode, so that we can handlesubtle differences between them (implied set_tx), and clear theappropriate keys if you attempt to switch straight from WPA toWEP and vice versa.

Also reinstate the TX buffer flush, and ensure the key index iswritten to the card little endian.

/*- * Check the key index here; if 0, load as Pairwise Key, otherwise,- * load as a group key. Note that for the Hermes, the RIDs for- * group/pariwise keys are different from each other and different- * than the default WEP keys as well.- */- switch (alg)- {- case IW_ENCODE_ALG_TKIP:- DBG_TRACE( DbgInfo, "IW_ENCODE_ALG_TKIP: key(%d)\n", key_idx);-#if 0- /*- * Make sure that there is no data queued up in the firmware- * before setting the TKIP keys. If this check is not- * performed, some data may be sent out with incorrect MIC- * and cause synchronizarion errors with the AP- */- /* Check every 1ms for 100ms */- for( count = 0; count < 100; count++ )- {- usleep( 1000 );+ * Make sure that there is no data queued up in the firmware+ * before setting the TKIP keys. If this check is not+ * performed, some data may be sent out with incorrect MIC+ * and cause synchronizarion errors with the AP+ */+ /* Check every 1ms for 100ms */+ for (count = 0; count < 100; count++) {+ udelay(1000);++ ltv.len = 2;+ ltv.typ = 0xFD91; /* This RID not defined in HCF yet!!! */+ ltv.u.u16[0] = 0;++ hcf_get_info(&(lp->hcfCtx), (LTVP)&ltv);++ if (ltv.u.u16[0] == 0)+ break;+ }