nl80211: add packet offset information for wowlan pattern
PATCH v2 1/1 nl80211: add packet offset information for wowlan pattern
From: Amitkumar Karwar <[email protected]>
If user knows the location of a wowlan pattern to be matched in Rx packet, he can provide an offset with the pattern. This will help drivers to ignore initial bytes and match the pattern efficiently.
---
v2: a) Driver can advertise supported max_pkt_offset during
initialization (Johannes Berg)
b) Set request will be rejected if packet offset from user exceeds supported max_pkt_offset (Johannes Berg)
c) Updated documentation in nl80211.h with packet offset info (Johannes Berg)
include/net/cfg80211.h | 4 ++++ include/uapi/linux/nl80211.h | 12 +++++++++--- net/wireless/nl80211.c | 20 +++++++++++++++++--- 3 files changed, 30 insertions(+), 6 deletions(-)
include/net/cfg80211.h +4 -0
@@ -1576,6 +1576,7 @@ struct cfg80211_pmksa {* one bit per byte, in same format as nl80211 * @pattern: bytes to match where bitmask is 1 * @pattern_len: length of pattern (in bytes) +* @pkt_offset: packet offset (in bytes) * * Internal note: @mask and @pattern are allocated in one chunk of * memory, free @mask only!
@@ -1583,6 +1584,7 @@ struct cfg80211_pmksa {struct cfg80211_wowlan_trig_pkt_pattern {u8 *mask, *pattern;int pattern_len; +int pkt_offset; };/**
@@ -2290,12 +2292,14 @@ enum wiphy_wowlan_support_flags {* (see nl80211.h for the pattern definition) * @pattern_max_len: maximum length of each pattern * @pattern_min_len: minimum length of each pattern +* @max_pkt_offset: maximum Rx packet offset */ struct wiphy_wowlan_support {u32 flags;int n_patterns;int pattern_max_len;int pattern_min_len; +int max_pkt_offset; };/**
include/uapi/linux/nl80211.h +9 -3
@@ -2910,6 +2910,8 @@ enum nl80211_tx_power_setting {* Note that the pattern matching is done as though frames were not * 802.11 frames but 802.3 frames, i.e. the frame is fully unpacked * first (including SNAP header unpacking) and then matched. +* @NL80211_WOWLAN_PKTPAT_OFFSET: packet offset, pattern is matched after +* these fixed number of bytes of received packet * @NUM_NL80211_WOWLAN_PKTPAT: number of attributes * @MAX_NL80211_WOWLAN_PKTPAT: max attribute number */
@@ -2917,6 +2919,7 @@ enum nl80211_wowlan_packet_pattern_attr { __NL80211_WOWLAN_PKTPAT_INVALID,NL80211_WOWLAN_PKTPAT_MASK ,NL80211_WOWLAN_PKTPAT_PATTERN , +NL80211_WOWLAN_PKTPAT_OFFSET ,NUM_NL80211_WOWLAN_PKTPAT , MAX_NL80211_WOWLAN_PKTPAT = NUM_NL80211_WOWLAN_PKTPAT - 1,
@@ -2927,6 +2930,7 @@ enum nl80211_wowlan_packet_pattern_attr {* @max_patterns: maximum number of patterns supported * @min_pattern_len: minimum length of each pattern * @max_pattern_len: maximum length of each pattern +* @max_pkt_offset: maximum Rx packet offset * * This struct is carried in %NL80211_WOWLAN_TRIG_PKT_PATTERN when * that is part of %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED in the
@@ -2936,6 +2940,7 @@ struct nl80211_wowlan_pattern_support {__u32 max_patterns;__u32 min_pattern_len;__u32 max_pattern_len; +__u32 max_pkt_offset; } __attribute__((packed));/**
@@ -2951,9 +2956,10 @@ struct nl80211_wowlan_pattern_support {* @NL80211_WOWLAN_TRIG_PKT_PATTERN: wake up on the specified packet patterns * which are passed in an array of nested attributes, each nested attribute * defining a with attributes from &struct nl80211_wowlan_trig_pkt_pattern. -* Each pattern defines a wakeup packet. The matching is done on the MSDU, -* i.e. as though the packet was an 802.3 packet, so the pattern matching -* is done after the packet is converted to the MSDU. +* Each pattern defines a wakeup packet. Packet offset is associated with +* each pattern which is used while matching the pattern. The matching is +* done on the MSDU, i.e. as though the packet was an 802.3 packet, so the +* pattern matching is done after the packet is converted to the MSDU. * * In %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED, it is a binary attribute * carrying a &struct nl80211_wowlan_pattern_support.
net/wireless/nl80211.c +17 -3
@@ -1238,6 +1238,8 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flag dev->wiphy.wowlan.pattern_min_len, .max_pattern_len = dev->wiphy.wowlan.pattern_max_len, + .max_pkt_offset = + dev->wiphy.wowlan.max_pkt_offset, };if (nla_put (msg,NL80211_WOWLAN_TRIG_PKT_PATTERN ,sizeof (pat), &pat))
@@ -6953,8 +6955,11 @@ static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) DIV_ROUND_UP(pat_len, 8), rdev->wowlan->patterns[i].mask) || nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, - pat_len, - rdev->wowlan->patterns[i].pattern)) + pat_len, + rdev->wowlan->patterns[i].pattern) || + nla_put_u32(msg, + NL80211_WOWLAN_PKTPAT_OFFSET, + rdev->wowlan->patterns[i].pkt_offset)) goto nla_put_failure;nla_nest_end (msg, nl_pat); }
@@ -7046,7 +7051,7 @@ static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN ]) {struct nlattr *pat;int n_patterns =0 ; -int rem, pat_len, mask_len; +int rem, pat_len, mask_len, pkt_offset;struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT ]; nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
@@ -7081,6 +7086,15 @@ static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) pat_len < wowlan->pattern_min_len) goto error; +if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET ]) + pkt_offset =0 ; +else + pkt_offset =nla_get_u32 ( + pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET ]); +if (pkt_offset > wowlan->max_pkt_offset) + goto error; + new_triggers.patterns[i].pkt_offset = pkt_offset; + new_triggers.patterns[i].mask =kmalloc (mask_len + pat_len,GFP_KERNEL );if (!new_triggers.patterns[i].mask) {
Signature · 1 line
1.8.0
PATCH v2 1/1 iw: add packet offset information for wowlan pattern
From: Amitkumar Karwar <[email protected]>
Now user can provide packet offset along with the pattern in "iw wowlan" command. Default offset will be 0 when it is not provided.
A trailing ':' should be used for single byte pattern to distinguish it from an offset.
Ex. "iw phy phy# wowlan patterns 18 43:" means wakeup on offset 18 pattern 0x43.
---
v2: display maximum permissible packet offset as well for
WOWLAN patterns
info.c | 5 +++-- util.c | 2 ++ wowlan.c | 30 +++++++++++++++++++++++------- 3 files changed, 28 insertions(+), 9 deletions(-)
info.c +3 -2
@@ -382,8 +382,9 @@ broken_combination:printf ("\t\t * wake up on magic packet\n" );if (tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN ]) { pat =nla_data (tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN ]); -printf ("\t\t * wake up on pattern match, up to %u patterns of %u-%u bytes\n" , - pat->max_patterns, pat->min_pattern_len, pat->max_pattern_len); +printf ("\t\t * wake up on pattern match, up to %u patterns of %u-%u bytes,\n" +"\t\t maximum packet offset %u bytes\n" , + pat->max_patterns, pat->min_pattern_len, pat->max_pattern_len, pat->max_pkt_offset); }if (tb_wowlan[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED ])printf ("\t\t * can do GTK rekeying\n" );
util.c +2 -0
@@ -75,6 +75,8 @@ int parse_hex_mask(char *hexmask, unsigned char **result, size_t *result_len,if (cp) { *cp =0 ; cp++; + }else if (!strlen (hexmask)) { +break ; } if (result_mask && (strcmp(hexmask, "-") == 0 ||
wowlan.c +23 -7
@@ -26,7 +26,8 @@ static int handle_wowlan_enable(struct nl80211_state *state, struct nl_cb *cb,int err = -ENOBUFS ;unsigned char *pat, *mask;size_t patlen; -int patnum =0 ; +int patnum =0 , pkt_offset; +char *eptr; wowlan =nla_nest_start (msg,NL80211_ATTR_WOWLAN_TRIGGERS );if (!wowlan)
@@ -62,7 +63,16 @@ static int handle_wowlan_enable(struct nl80211_state *state, struct nl_cb *cb, }break ;case PS_PAT : -if (parse_hex_mask (argv[0 ], &pat, &patlen, &mask)) { + pkt_offset =strtoul (argv[0 ], &eptr,10 ); +if (eptr != argv[0 ] +strlen (argv[0 ])) { +/* packet offset is not provided, set default value to 0 */ + pkt_offset =0 ; + }else { + argv++; + argc--; + } + +if (!argc ||parse_hex_mask (argv[0 ], &pat, &patlen, &mask)) { err =1 ; goto nla_put_failure; }
@@ -71,6 +81,7 @@ static int handle_wowlan_enable(struct nl80211_state *state, struct nl_cb *cb, DIV_ROUND_UP(patlen, 8), mask);NLA_PUT (patterns,NL80211_WOWLAN_PKTPAT_PATTERN , patlen, pat); +NLA_PUT_U32 (patterns,NL80211_WOWLAN_PKTPAT_OFFSET , pkt_offset);nla_nest_end (patterns, pattern);free (mask);free (pat);
@@ -91,12 +102,14 @@ static int handle_wowlan_enable(struct nl80211_state *state, struct nl_cb *cb,return err; }COMMAND (wowlan, enable,"[any] [disconnect] [magic-packet] [gtk-rekey-failure] [eap-identity-request]" -" [4way-handshake] [rfkill-release] [patterns <pattern>*]" , +" [4way-handshake] [rfkill-release] [patterns [offset1] <pattern1> ...]" ,NL80211_CMD_SET_WOWLAN ,0 ,CIB_PHY , handle_wowlan_enable,"Enable WoWLAN with the given triggers.\n" "Each pattern is given as a bytestring with '-' in places where any byte\n" "may be present, e.g. 00:11:22:-:44 will match 00:11:22:33:44 and\n" -"00:11:22:33:ff:44 etc." ); +"00:11:22:33:ff:44 etc.\n" +"Use ':' for single byte pattern as well, e.g. 18 43: will match '43' " +"after 18 bytes of offset in Rx packet." ); static int handle_wowlan_disable(struct nl80211_state *state, struct nl_cb *cb,
@@ -152,23 +165,26 @@ static int print_wowlan_handler(struct nl_msg *msg, void *arg) trig[NL80211_WOWLAN_TRIG_PKT_PATTERN], rem_pattern) {struct nlattr *patattr[NUM_NL80211_WOWLAN_PKTPAT ]; -int i, patlen, masklen; +int i, patlen, masklen, pkt_offset;uint8_t *mask, *pat;nla_parse (patattr,MAX_NL80211_WOWLAN_PKTPAT ,nla_data (pattern),nla_len (pattern),NULL );if (!patattr[NL80211_WOWLAN_PKTPAT_MASK ] || - !patattr[NL80211_WOWLAN_PKTPAT_PATTERN ]) { + !patattr[NL80211_WOWLAN_PKTPAT_PATTERN ] || + !patattr[NL80211_WOWLAN_PKTPAT_OFFSET ]) {printf (" * (invalid pattern specification)\n" );continue ; } masklen =nla_len (patattr[NL80211_WOWLAN_PKTPAT_MASK ]); patlen =nla_len (patattr[NL80211_WOWLAN_PKTPAT_PATTERN ]); + pkt_offset =nla_get_u32 (patattr[NL80211_WOWLAN_PKTPAT_OFFSET ]);if (DIV_ROUND_UP (patlen,8 ) != masklen) {printf (" * (invalid pattern specification)\n" );continue ; } -printf (" * wake up on pattern: " ); +printf (" * wake up on packet offset: %d" , pkt_offset); +printf (" pattern: " ); pat =nla_data (patattr[NL80211_WOWLAN_PKTPAT_PATTERN ]); mask =nla_data (patattr[NL80211_WOWLAN_PKTPAT_MASK ]);for (i =0 ; i < patlen; i++) {
Signature · 1 line
1.8.0
Johannes Berg
maintainerRe: [PATCH v2] iw: add packet offset information for wowlan pattern
Quoted 11 lines · Bing Zhao
From: Amitkumar Karwar <[email protected]>
Now user can provide packet offset along with the pattern in "iw wowlan" command. Default offset will be 0 when it is not provided.
A trailing ':' should be used for single byte pattern to distinguish it from an offset.
Ex. "iw phy phy# wowlan patterns 18 43:" means wakeup on offset 18 pattern0x43.
info.c broken_combination: · line 387
Quoted 7 lines
info.c +3
-2if (tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN ]) { pat =nla_data (tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN ]); -printf ("\t\t * wake up on pattern match, up to %u patterns of %u-%u bytes\n" , - pat->max_patterns, pat->min_pattern_len, pat->max_pattern_len); +printf ("\t\t * wake up on pattern match, up to %u patterns of %u-%u bytes,\n" +"\t\t maximum packet offset %u bytes\n" , + pat->max_patterns, pat->min_pattern_len, pat->max_pattern_len, pat->max_pkt_offset);
This will in the best case print something random on old kernels, and in the absolute worst case crash, so please fix that by detecting the size of the struct.
johannes
Johannes Berg
maintainerRe: [PATCH v2] iw: add packet offset information for wowlan pattern
In reply to Bing ZhaoAlso...
wowlan.c static int handle_wowlan_enable(struct nl80211_state *state, struct nl_cb *cb, · line 112
Quoted 11 lines
COMMAND(wowlan, enable, "[any] [disconnect] [magic-packet] [gtk-rekey-failure] [eap-identity-request]"
wowlan.c +4
-2-" [4way-handshake] [rfkill-release] [patterns <pattern>*]" , +" [4way-handshake] [rfkill-release] [patterns [offset1] <pattern1> ...]" ,NL80211_CMD_SET_WOWLAN ,0 ,CIB_PHY , handle_wowlan_enable,"Enable WoWLAN with the given triggers.\n" "Each pattern is given as a bytestring with '-' in places where any byte\n" "may be present, e.g. 00:11:22:-:44 will match 00:11:22:33:44 and\n" - "00:11:22:33:ff:44 etc."); +"00:11:22:33:ff:44 etc.\n" +"Use ':' for single byte pattern as well, e.g. 18 43: will match '43' " + "after 18 bytes of offset in Rx packet.");
Is there maybe a slightly more intuitive syntax? I'm not really worried about the break of pattern being just a single byte, but it seems to me something like <offset>+<pattern> or so would be easier to understand?
iw wowlan enable disconnect patterns 14+88:8E
It would also be more obviously wrong to an old iw version -- it would reject this, while it would accept "14 88:8E" as two patterns.
johannes
RE: [PATCH v2] iw: add packet offset information for wowlan pattern
SGkgSm9oYW5uZXMsDQoNCj4gQWxzby4uLg0KPiANCj4gPiAgQ09NTUFORCh3b3dsYW4sIGVuYWJs ZSwgIlthbnldIFtkaXNjb25uZWN0XSBbbWFnaWMtcGFja2V0XSBbZ3RrLXJla2V5LWZhaWx1cmVd IFtlYXAtaWRlbnRpdHktDQo+IHJlcXVlc3RdIg0KPiA+IC0JIiBbNHdheS1oYW5kc2hha2VdIFty ZmtpbGwtcmVsZWFzZV0gW3BhdHRlcm5zIDxwYXR0ZXJuPipdIiwNCj4gPiArCSIgWzR3YXktaGFu ZHNoYWtlXSBbcmZraWxsLXJlbGVhc2VdIFtwYXR0ZXJucyBbb2Zmc2V0MV0gPHBhdHRlcm4xPiAu Li5dIiwNCj4gPiAgCU5MODAyMTFfQ01EX1NFVF9XT1dMQU4sIDAsIENJQl9QSFksIGhhbmRsZV93 b3dsYW5fZW5hYmxlLA0KPiA+ICAJIkVuYWJsZSBXb1dMQU4gd2l0aCB0aGUgZ2l2ZW4gdHJpZ2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dHdvIHBhdHRlcm5zLg0KDQpUaGFua3Mg Zm9yIHlvdXIgY29tbWVudHMuDQoNClYzIHRha2VzIGNhcmUgb2YgdGhpcyBhcyB3ZWxsIGFzIHRo ZSBvbGQga2VybmVscy4gUGxlYXNlIGNoZWNrLg0KDQpUaGFua3MsDQpCaW5nDQoNCj4gDQo+IGpv aGFubmVzDQoNCg==
Quoted 6 lines · Bing Zhao
From: Amitkumar Karwar <[email protected]>
If user knows the location of a wowlan pattern to be matched in Rx packet, he can provide an offset with the pattern. This will help drivers to ignore initial bytes and match the pattern efficiently.
Applied, thanks. I refactored the pattern sending a bit to make it less indented.
johannes