linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* mac80211: What is get_sequence_counter?
@ 2007-10-05 13:56 Michael Buesch
  2007-10-05 14:03 ` Johannes Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Buesch @ 2007-10-05 13:56 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Michael Wu, linux-wireless

What is the get_sequence_counter callback for?

	/* For devices that have internal sequence counters, allow 802.11
	 * code to access the current value of a counter */
	int (*get_sequence_counter)(struct ieee80211_hw *hw,
				    u8* addr, u8 keyidx, u8 txrx,
				    u32* iv32, u16* iv16);

It doesn't seem to be used in current mac80211 code.
It seems that this is to fetch the current initial values.
Is that correct?
Who is supposed to use this callback? If it's unused, let's remove
it please. The documentation for it sucks anyway. :)

-- 
Greetings Michael.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mac80211: What is get_sequence_counter?
  2007-10-05 13:56 mac80211: What is get_sequence_counter? Michael Buesch
@ 2007-10-05 14:03 ` Johannes Berg
  2007-10-05 14:06   ` Michael Buesch
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2007-10-05 14:03 UTC (permalink / raw)
  To: Michael Buesch; +Cc: Michael Wu, linux-wireless

[-- Attachment #1: Type: text/plain, Size: 954 bytes --]

On Fri, 2007-10-05 at 15:56 +0200, Michael Buesch wrote:
> What is the get_sequence_counter callback for?
> 
> 	/* For devices that have internal sequence counters, allow 802.11
> 	 * code to access the current value of a counter */
> 	int (*get_sequence_counter)(struct ieee80211_hw *hw,
> 				    u8* addr, u8 keyidx, u8 txrx,
> 				    u32* iv32, u16* iv16);
> 
> It doesn't seem to be used in current mac80211 code.
> It seems that this is to fetch the current initial values.
> Is that correct?
> Who is supposed to use this callback? If it's unused, let's remove
> it please. The documentation for it sucks anyway. :)

No, it's actually used in a patch I'm about to post:
http://johannes.sipsolutions.net/patches/kernel/all/2007-09-28-22%3a38/017-mac80211-key-seq-nl80211.patch

Mind you, it could be renamed and described better; it's used for
getting the current sequence number of a hardware TKIP implementation.

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mac80211: What is get_sequence_counter?
  2007-10-05 14:03 ` Johannes Berg
@ 2007-10-05 14:06   ` Michael Buesch
  2007-10-05 14:24     ` Johannes Berg
  2007-10-09  9:12     ` Johannes Berg
  0 siblings, 2 replies; 6+ messages in thread
From: Michael Buesch @ 2007-10-05 14:06 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Michael Wu, linux-wireless

On Friday 05 October 2007 16:03:24 Johannes Berg wrote:
> On Fri, 2007-10-05 at 15:56 +0200, Michael Buesch wrote:
> > What is the get_sequence_counter callback for?
> > 
> > 	/* For devices that have internal sequence counters, allow 802.11
> > 	 * code to access the current value of a counter */
> > 	int (*get_sequence_counter)(struct ieee80211_hw *hw,
> > 				    u8* addr, u8 keyidx, u8 txrx,
> > 				    u32* iv32, u16* iv16);
> > 
> > It doesn't seem to be used in current mac80211 code.
> > It seems that this is to fetch the current initial values.
> > Is that correct?
> > Who is supposed to use this callback? If it's unused, let's remove
> > it please. The documentation for it sucks anyway. :)
> 
> No, it's actually used in a patch I'm about to post:
> http://johannes.sipsolutions.net/patches/kernel/all/2007-09-28-22%3a38/017-mac80211-key-seq-nl80211.patch
> 
> Mind you, it could be renamed and described better; it's used for
> getting the current sequence number of a hardware TKIP implementation.

Ah, ok. It sounded to me like it's supposed to fetch the
seq_ctrl counter (data header), if the device does frame sequence
counting in hw.
Can you please rename that to something like
get_tkip_ivs() or
get_tkip_counters()
or something like that?

-- 
Greetings Michael.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mac80211: What is get_sequence_counter?
  2007-10-05 14:06   ` Michael Buesch
@ 2007-10-05 14:24     ` Johannes Berg
  2007-10-09  9:12     ` Johannes Berg
  1 sibling, 0 replies; 6+ messages in thread
From: Johannes Berg @ 2007-10-05 14:24 UTC (permalink / raw)
  To: Michael Buesch; +Cc: Michael Wu, linux-wireless

[-- Attachment #1: Type: text/plain, Size: 425 bytes --]

On Fri, 2007-10-05 at 16:06 +0200, Michael Buesch wrote:

> Ah, ok. It sounded to me like it's supposed to fetch the
> seq_ctrl counter (data header), if the device does frame sequence
> counting in hw.

Ah ok, yeah, it's badly named.

> Can you please rename that to something like
> get_tkip_ivs() or
> get_tkip_counters()
> or something like that?

Sure, I'll add that to the patch that uses it.

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mac80211: What is get_sequence_counter?
  2007-10-05 14:06   ` Michael Buesch
  2007-10-05 14:24     ` Johannes Berg
@ 2007-10-09  9:12     ` Johannes Berg
  2007-10-09 13:52       ` Michael Buesch
  1 sibling, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2007-10-09  9:12 UTC (permalink / raw)
  To: Michael Buesch; +Cc: Michael Wu, linux-wireless

How's this? (scroll all the way down)

I changed the prototype too to pass the hw_key_idx instead of the key.

Subject: mac80211: implement the new cfg80211 get_key hook

This implements get_key() to replace all the prism2 ioctl
functionality.

Not-signed-off-by: Johannes Berg <johannes@sipsolutions.net>

---
 include/net/mac80211.h |   11 ++----
 net/mac80211/cfg.c     |   85 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 89 insertions(+), 7 deletions(-)

--- wireless-dev.orig/net/mac80211/cfg.c	2007-10-08 12:24:10.595111702 +0200
+++ wireless-dev/net/mac80211/cfg.c	2007-10-08 13:29:54.865107447 +0200
@@ -1,7 +1,7 @@
 /*
  * mac80211 configuration hooks for cfg80211
  *
- * Copyright 2006	Johannes Berg <johannes@sipsolutions.net>
+ * Copyright 2006, 2007	Johannes Berg <johannes@sipsolutions.net>
  *
  * This file is GPLv2 as found in COPYING.
  */
@@ -174,6 +174,88 @@ static int ieee80211_del_key(struct wiph
 	return 0;
 }
 
+static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
+			     u8 key_idx, u8 *mac_addr, void *cookie,
+			     void (*callback)(void *cookie,
+					      struct key_params *params))
+{
+	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+	struct sta_info *sta = NULL;
+	u8 seq[6] = {0};
+	struct key_params params;
+	struct ieee80211_key *key;
+	u32 iv32;
+	u16 iv16;
+	int err = -ENOENT;
+
+	if (mac_addr) {
+		sta = sta_info_get(sdata->local, mac_addr);
+		if (!sta)
+			goto out;
+
+		key = sta->key;
+	} else
+		key = sdata->keys[key_idx];
+
+	if (!key)
+		goto out;
+
+	memset(&params, 0, sizeof(params));
+
+	switch (key->conf.alg) {
+	case ALG_TKIP:
+		params.cipher = WLAN_CIPHER_SUITE_TKIP;
+
+		iv32 = key->u.tkip.iv32;
+		iv16 = key->u.tkip.iv16;
+
+		if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
+		    sdata->local->ops->get_tkip_seq)
+			sdata->local->ops->get_tkip_seq(
+				local_to_hw(sdata->local),
+				key->conf.hw_key_idx,
+				&iv32, &iv16);
+
+		seq[0] = iv16 & 0xff;
+		seq[1] = (iv16 >> 8) & 0xff;
+		seq[2] = iv32 & 0xff;
+		seq[3] = (iv32 >> 8) & 0xff;
+		seq[4] = (iv32 >> 16) & 0xff;
+		seq[5] = (iv32 >> 24) & 0xff;
+		params.seq = seq;
+		params.seq_len = 6;
+		break;
+	case ALG_CCMP:
+		params.cipher = WLAN_CIPHER_SUITE_CCMP;
+		seq[0] = key->u.ccmp.tx_pn[5];
+		seq[1] = key->u.ccmp.tx_pn[4];
+		seq[2] = key->u.ccmp.tx_pn[3];
+		seq[3] = key->u.ccmp.tx_pn[2];
+		seq[4] = key->u.ccmp.tx_pn[1];
+		seq[5] = key->u.ccmp.tx_pn[0];
+		params.seq = seq;
+		params.seq_len = 6;
+		break;
+	case ALG_WEP:
+		if (key->conf.keylen == 5)
+			params.cipher = WLAN_CIPHER_SUITE_WEP40;
+		else
+			params.cipher = WLAN_CIPHER_SUITE_WEP104;
+		break;
+	}
+
+	params.key = key->conf.key;
+	params.key_len = key->conf.keylen;
+
+	callback(cookie, &params);
+	err = 0;
+
+ out:
+	if (sta)
+		sta_info_put(sta);
+	return err;
+}
+
 static int ieee80211_config_default_key(struct wiphy *wiphy,
 					struct net_device *dev,
 					u8 key_idx)
@@ -192,5 +274,6 @@ struct cfg80211_ops mac80211_config_ops 
 	.change_virtual_intf = ieee80211_change_iface,
 	.add_key = ieee80211_add_key,
 	.del_key = ieee80211_del_key,
+	.get_key = ieee80211_get_key,
 	.set_default_key = ieee80211_config_default_key,
 };
--- wireless-dev.orig/include/net/mac80211.h	2007-10-08 13:19:18.845107447 +0200
+++ wireless-dev/include/net/mac80211.h	2007-10-08 13:25:55.595107447 +0200
@@ -957,9 +957,9 @@ enum ieee80211_erp_change_flags {
  *	response or association responses this updates the state of privacy_invoked
  *	returns 0 for success or an error number.
  *
- * @get_sequence_counter: For devices that have internal sequence counters this
- *	callback allows mac80211 to access the current value of a counter.
- *	This callback seems not well-defined, tell us if you need it.
+ * @get_tkip_seq: If your device implements TKIP encryption in hardware this
+ *	callback should be provided to read the TKIP transmit IVs (both IV32
+ *	and IV16) for the given key from hardware.
  *
  * @set_rts_threshold: Configuration of RTS threshold (if device needs it)
  *
@@ -1037,9 +1037,8 @@ struct ieee80211_ops {
 			 struct ieee80211_low_level_stats *stats);
 	int (*set_privacy_invoked)(struct ieee80211_hw *hw,
 				   int privacy_invoked);
-	int (*get_sequence_counter)(struct ieee80211_hw *hw,
-				    u8* addr, u8 keyidx, u8 txrx,
-				    u32* iv32, u16* iv16);
+	void (*get_tkip_seq)(struct ieee80211_hw *hw, u8 hw_key_idx,
+			     u32 *iv32, u16 *iv16);
 	int (*set_rts_threshold)(struct ieee80211_hw *hw, u32 value);
 	int (*set_frag_threshold)(struct ieee80211_hw *hw, u32 value);
 	int (*set_retry_limit)(struct ieee80211_hw *hw,



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mac80211: What is get_sequence_counter?
  2007-10-09  9:12     ` Johannes Berg
@ 2007-10-09 13:52       ` Michael Buesch
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Buesch @ 2007-10-09 13:52 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Michael Wu, linux-wireless

On Tuesday 09 October 2007 11:12:37 Johannes Berg wrote:
> How's this? (scroll all the way down)
> 
> I changed the prototype too to pass the hw_key_idx instead of the key.
> 
> Subject: mac80211: implement the new cfg80211 get_key hook
> 
> This implements get_key() to replace all the prism2 ioctl
> functionality.

Great, I like it.

> Not-signed-off-by: Johannes Berg <johannes@sipsolutions.net>
> 
> ---
>  include/net/mac80211.h |   11 ++----
>  net/mac80211/cfg.c     |   85 ++++++++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 89 insertions(+), 7 deletions(-)
> 
> --- wireless-dev.orig/net/mac80211/cfg.c	2007-10-08 12:24:10.595111702 +0200
> +++ wireless-dev/net/mac80211/cfg.c	2007-10-08 13:29:54.865107447 +0200
> @@ -1,7 +1,7 @@
>  /*
>   * mac80211 configuration hooks for cfg80211
>   *
> - * Copyright 2006	Johannes Berg <johannes@sipsolutions.net>
> + * Copyright 2006, 2007	Johannes Berg <johannes@sipsolutions.net>
>   *
>   * This file is GPLv2 as found in COPYING.
>   */
> @@ -174,6 +174,88 @@ static int ieee80211_del_key(struct wiph
>  	return 0;
>  }
>  
> +static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
> +			     u8 key_idx, u8 *mac_addr, void *cookie,
> +			     void (*callback)(void *cookie,
> +					      struct key_params *params))
> +{
> +	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
> +	struct sta_info *sta = NULL;
> +	u8 seq[6] = {0};
> +	struct key_params params;
> +	struct ieee80211_key *key;
> +	u32 iv32;
> +	u16 iv16;
> +	int err = -ENOENT;
> +
> +	if (mac_addr) {
> +		sta = sta_info_get(sdata->local, mac_addr);
> +		if (!sta)
> +			goto out;
> +
> +		key = sta->key;
> +	} else
> +		key = sdata->keys[key_idx];
> +
> +	if (!key)
> +		goto out;
> +
> +	memset(&params, 0, sizeof(params));
> +
> +	switch (key->conf.alg) {
> +	case ALG_TKIP:
> +		params.cipher = WLAN_CIPHER_SUITE_TKIP;
> +
> +		iv32 = key->u.tkip.iv32;
> +		iv16 = key->u.tkip.iv16;
> +
> +		if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
> +		    sdata->local->ops->get_tkip_seq)
> +			sdata->local->ops->get_tkip_seq(
> +				local_to_hw(sdata->local),
> +				key->conf.hw_key_idx,
> +				&iv32, &iv16);
> +
> +		seq[0] = iv16 & 0xff;
> +		seq[1] = (iv16 >> 8) & 0xff;
> +		seq[2] = iv32 & 0xff;
> +		seq[3] = (iv32 >> 8) & 0xff;
> +		seq[4] = (iv32 >> 16) & 0xff;
> +		seq[5] = (iv32 >> 24) & 0xff;
> +		params.seq = seq;
> +		params.seq_len = 6;
> +		break;
> +	case ALG_CCMP:
> +		params.cipher = WLAN_CIPHER_SUITE_CCMP;
> +		seq[0] = key->u.ccmp.tx_pn[5];
> +		seq[1] = key->u.ccmp.tx_pn[4];
> +		seq[2] = key->u.ccmp.tx_pn[3];
> +		seq[3] = key->u.ccmp.tx_pn[2];
> +		seq[4] = key->u.ccmp.tx_pn[1];
> +		seq[5] = key->u.ccmp.tx_pn[0];
> +		params.seq = seq;
> +		params.seq_len = 6;
> +		break;
> +	case ALG_WEP:
> +		if (key->conf.keylen == 5)
> +			params.cipher = WLAN_CIPHER_SUITE_WEP40;
> +		else
> +			params.cipher = WLAN_CIPHER_SUITE_WEP104;
> +		break;
> +	}
> +
> +	params.key = key->conf.key;
> +	params.key_len = key->conf.keylen;
> +
> +	callback(cookie, &params);
> +	err = 0;
> +
> + out:
> +	if (sta)
> +		sta_info_put(sta);
> +	return err;
> +}
> +
>  static int ieee80211_config_default_key(struct wiphy *wiphy,
>  					struct net_device *dev,
>  					u8 key_idx)
> @@ -192,5 +274,6 @@ struct cfg80211_ops mac80211_config_ops 
>  	.change_virtual_intf = ieee80211_change_iface,
>  	.add_key = ieee80211_add_key,
>  	.del_key = ieee80211_del_key,
> +	.get_key = ieee80211_get_key,
>  	.set_default_key = ieee80211_config_default_key,
>  };
> --- wireless-dev.orig/include/net/mac80211.h	2007-10-08 13:19:18.845107447 +0200
> +++ wireless-dev/include/net/mac80211.h	2007-10-08 13:25:55.595107447 +0200
> @@ -957,9 +957,9 @@ enum ieee80211_erp_change_flags {
>   *	response or association responses this updates the state of privacy_invoked
>   *	returns 0 for success or an error number.
>   *
> - * @get_sequence_counter: For devices that have internal sequence counters this
> - *	callback allows mac80211 to access the current value of a counter.
> - *	This callback seems not well-defined, tell us if you need it.
> + * @get_tkip_seq: If your device implements TKIP encryption in hardware this
> + *	callback should be provided to read the TKIP transmit IVs (both IV32
> + *	and IV16) for the given key from hardware.
>   *
>   * @set_rts_threshold: Configuration of RTS threshold (if device needs it)
>   *
> @@ -1037,9 +1037,8 @@ struct ieee80211_ops {
>  			 struct ieee80211_low_level_stats *stats);
>  	int (*set_privacy_invoked)(struct ieee80211_hw *hw,
>  				   int privacy_invoked);
> -	int (*get_sequence_counter)(struct ieee80211_hw *hw,
> -				    u8* addr, u8 keyidx, u8 txrx,
> -				    u32* iv32, u16* iv16);
> +	void (*get_tkip_seq)(struct ieee80211_hw *hw, u8 hw_key_idx,
> +			     u32 *iv32, u16 *iv16);
>  	int (*set_rts_threshold)(struct ieee80211_hw *hw, u32 value);
>  	int (*set_frag_threshold)(struct ieee80211_hw *hw, u32 value);
>  	int (*set_retry_limit)(struct ieee80211_hw *hw,
> 
> 
> 
> 



-- 
Greetings Michael.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-10-09 13:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-05 13:56 mac80211: What is get_sequence_counter? Michael Buesch
2007-10-05 14:03 ` Johannes Berg
2007-10-05 14:06   ` Michael Buesch
2007-10-05 14:24     ` Johannes Berg
2007-10-09  9:12     ` Johannes Berg
2007-10-09 13:52       ` Michael Buesch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).