[PATCH] Introduce current interface mode.

Max Filippov jcmvbkbc at gmail.com
Fri Jan 9 18:25:41 EET 2009


Introduce current interface mode.
Start interface in promiscuous mode by default.
Configure interface in IBSS mode on request.

Signed-off-by: Max Filippov <jcmvbkbc at gmail.com>
---
 stlc45xx.c |   48 ++++++++++++++++++++++++++++++++++++++++++++----
 stlc45xx.h |    2 +-
 2 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/stlc45xx.c b/stlc45xx.c
index f24ca84..48da0de 100644
--- a/stlc45xx.c
+++ b/stlc45xx.c
@@ -1692,7 +1692,7 @@ static void stlc45xx_tx_edcf(struct stlc45xx *stlc)
 	kfree(control);
 }
 
-static void stlc45xx_tx_setup(struct stlc45xx *stlc)
+static void stlc45xx_setup_mac(struct stlc45xx *stlc,u16 mode,const u8 *bssid)
 {
 	struct s_lm_control *control;
 	struct s_lmo_setup *setup;
@@ -1709,7 +1709,7 @@ static void stlc45xx_tx_setup(struct stlc45xx *stlc)
 	control->length = setup_len;
 	control->oid = LM_OID_SETUP;
 
-	setup->flags = LM_SETUP_INFRA;
+	setup->flags = mode;
 	setup->antenna = 2;
 	setup->rx_align = 0;
 	setup->rx_buffer = FIRMWARE_RXBUFFER_START;
@@ -1723,13 +1723,30 @@ static void stlc45xx_tx_setup(struct stlc45xx *stlc)
 	setup->osc_start_delay = 65535;
 
 	memcpy(setup->macaddr, stlc->mac_addr, ETH_ALEN);
-	memcpy(setup->bssid, stlc->bssid, ETH_ALEN);
+	if (bssid)
+		memcpy(setup->bssid, bssid, ETH_ALEN);
+	else
+		memset(setup->bssid, ~0, ETH_ALEN);
 
 	stlc45xx_tx_frame(stlc, FIRMWARE_CONFIG_START, control, len);
 
 	kfree(control);
 }
 
+static void stlc45xx_tx_setup(struct stlc45xx *stlc)
+{
+	u16 mode = LM_SETUP_PROMISCUOUS;
+	switch (stlc->mode) {
+	case NL80211_IFTYPE_STATION:
+		mode = LM_SETUP_INFRA;
+		break;
+	case NL80211_IFTYPE_ADHOC:
+		mode = LM_SETUP_IBSS;
+		break;
+	}
+	stlc45xx_setup_mac(stlc,mode,stlc->bssid);
+}
+
 static void stlc45xx_tx_scan(struct stlc45xx *stlc)
 {
 	struct s_lm_control *control;
@@ -2175,6 +2192,9 @@ static int stlc45xx_op_start(struct ieee80211_hw *hw)
 
 	WARN_ON(stlc->fw_state != FW_STATE_READY);
 
+	stlc->mode = NL80211_IFTYPE_MONITOR;
+	stlc45xx_setup_mac(stlc,LM_SETUP_PROMISCUOUS,NULL);
+
 out_unlock:
 	mutex_unlock(&stlc->mutex);
 
@@ -2201,6 +2221,7 @@ static void stlc45xx_op_stop(struct ieee80211_hw *hw)
 	spin_unlock_bh(&stlc->tx_lock);
 
 	stlc->fw_state = FW_STATE_OFF;
+	stlc->mode = NL80211_IFTYPE_UNSPECIFIED;
 
 	mutex_unlock(&stlc->mutex);
 }
@@ -2210,10 +2231,12 @@ static int stlc45xx_op_add_interface(struct ieee80211_hw *hw,
 {
 	struct stlc45xx *stlc = hw->priv;
 
-	stlc45xx_debug(DEBUG_FUNC, "%s", __func__);
+	stlc45xx_debug(DEBUG_FUNC, "%s conf->type: %d", __func__,conf->type);
 
 	switch (conf->type) {
 	case NL80211_IFTYPE_STATION:
+	case NL80211_IFTYPE_ADHOC:
+		stlc->mode = conf->type;
 		break;
 	default:
 		return -EOPNOTSUPP;
@@ -2221,13 +2244,29 @@ static int stlc45xx_op_add_interface(struct ieee80211_hw *hw,
 
 	memcpy(stlc->mac_addr, conf->mac_addr, ETH_ALEN);
 
+	switch (conf->type) {
+	case NL80211_IFTYPE_STATION:
+		stlc45xx_setup_mac(stlc,LM_SETUP_INFRA,NULL);
+		break;
+	case NL80211_IFTYPE_ADHOC:
+		stlc45xx_setup_mac(stlc,LM_SETUP_IBSS,NULL);
+		break;
+	default:
+		BUG();
+	}
+
 	return 0;
 }
 
 static void stlc45xx_op_remove_interface(struct ieee80211_hw *hw,
 					 struct ieee80211_if_init_conf *conf)
 {
+	struct stlc45xx *stlc = hw->priv;
+
 	stlc45xx_debug(DEBUG_FUNC, "%s", __func__);
+
+	stlc->mode = NL80211_IFTYPE_MONITOR;
+	stlc45xx_setup_mac(stlc,LM_SETUP_PROMISCUOUS,NULL);
 }
 
 static int stlc45xx_op_config_interface(struct ieee80211_hw *hw,
@@ -2413,6 +2452,7 @@ static int __devinit stlc45xx_probe(struct spi_device *spi)
 	/* mac80211 clears hw->priv */
 	stlc = hw->priv;
 
+	stlc->mode = NL80211_IFTYPE_UNSPECIFIED;
 	stlc->hw = hw;
 	dev_set_drvdata(&spi->dev, stlc);
 	stlc->spi = spi;
diff --git a/stlc45xx.h b/stlc45xx.h
index 517df6e..acc0558 100644
--- a/stlc45xx.h
+++ b/stlc45xx.h
@@ -247,7 +247,7 @@ struct stlc45xx {
 	struct mutex mutex;
 	struct completion fw_comp;
 
-
+	int mode;
 	u8 bssid[ETH_ALEN];
 	u8 mac_addr[ETH_ALEN];
 	int channel;
-- 
1.5.4.3


More information about the stlc45xx-devel mailing list