From: Joe Perches <joe@perches.com>
To: "John W. Linville" <linville@tuxdriver.com>
Cc: Chen Gang <gang.chen@asianux.com>,
stas.yakovlev@gmail.com, linux-wireless@vger.kernel.org,
netdev@vger.kernel.org
Subject: [RFC PATCH] vsprintf: Add %p*D extension for 80211 SSIDs
Date: Sun, 06 Jan 2013 20:49:55 -0800 [thread overview]
Message-ID: <1357534195.21481.31.camel@joe-AO722> (raw)
In-Reply-To: <1357528746.4940.31.camel@joe-AO722>
On Sun, 2013-01-06 at 19:19 -0800, Joe Perches wrote:
> Maybe these days this should be another vsprintf %p extension
> like %pM when the DECLARE_MAC_BUF/print_mac uses were converted.
>
> (or maybe extend %ph for ssids with %*phs, length, array)
Maybe like this:
lib/vsprintf.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 55 insertions(+), 2 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index fab33a9..98916a0 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -26,6 +26,7 @@
#include <linux/math64.h>
#include <linux/uaccess.h>
#include <linux/ioport.h>
+#include <linux/ieee80211.h>
#include <net/addrconf.h>
#include <asm/page.h> /* for PAGE_SIZE */
@@ -660,10 +661,59 @@ char *resource_string(char *buf, char *end, struct resource *res,
}
static noinline_for_stack
+char *ssid_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
+ const char *fmt)
+{
+ int i, len = 1; /* if we pass %*p, field width remains
+ negative value, fallback to the default */
+
+ if (spec.field_width == 0)
+ /* nothing to print */
+ return buf;
+
+ if (ZERO_OR_NULL_PTR(addr))
+ /* NULL pointer */
+ return string(buf, end, NULL, spec);
+
+ if (spec.field_width > 0)
+ len = min_t(int, spec.field_width, IEEE80211_MAX_SSID_LEN);
+
+ for (i = 0; i < len && buf < end; i++) {
+ if (isprint(addr[i])) {
+ *buf++ = addr[i];
+ continue;
+ }
+ *buf++ = '\\';
+ if (buf >= end)
+ continue;
+ if (addr[i] == '\0')
+ *buf++ = '0';
+ else if (addr[i] == '\n')
+ *buf++ = 'n';
+ else if (addr[i] == '\r')
+ *buf++ = 'r';
+ else if (addr[i] == '\t')
+ *buf++ = 't';
+ else if (addr[i] == '\\')
+ *buf++ = '\\';
+ else {
+ if (buf < end)
+ *buf++ = ((addr[i] >> 6) & 7) + '0';
+ if (buf < end)
+ *buf++ = ((addr[i] >> 3) & 7) + '0';
+ if (buf < end)
+ *buf++ = ((addr[i] >> 0) & 7) + '0';
+ }
+ }
+
+ return buf;
+}
+
+static noinline_for_stack
char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
const char *fmt)
{
- int i, len = 1; /* if we pass '%ph[CDN]', field witdh remains
+ int i, len = 1; /* if we pass '%ph[CDN]', field width remains
negative value, fallback to the default */
char separator;
@@ -695,7 +745,6 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
for (i = 0; i < len && buf < end - 1; i++) {
buf = hex_byte_pack(buf, addr[i]);
-
if (buf < end && separator && i != len - 1)
*buf++ = separator;
}
@@ -1016,6 +1065,8 @@ int kptr_restrict __read_mostly;
* [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15]
* little endian output byte order is:
* [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15]
+ * - 'D' For a 80211 SSID, it prints the SSID escaping any non-printable
+ characters with a leading \ and octal or [0nrt\]
* - 'V' For a struct va_format which contains a format string * and va_list *,
* call vsnprintf(->format, *->va_list).
* Implements a "recursive vsnprintf".
@@ -1088,6 +1139,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
break;
case 'U':
return uuid_string(buf, end, ptr, spec, fmt);
+ case 'D':
+ return ssid_string(buf, end, ptr, spec, fmt);
case 'V':
{
va_list va;
next prev parent reply other threads:[~2013-01-07 4:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-05 13:41 [PATCH] drivers/net/wireless/ipw2x00: use strlcpy instead of strncpy Chen Gang
2013-01-05 14:42 ` Joe Perches
2013-01-07 2:49 ` Chen Gang
[not found] ` <50EA37CE.1090901-bOixZGp5f+dBDgjK7y7TUQ@public.gmane.org>
2013-01-07 2:57 ` Chen Gang F T
2013-01-07 3:19 ` Joe Perches
2013-01-07 3:42 ` Chen Gang F T
2013-01-07 4:49 ` Joe Perches [this message]
2013-01-07 6:07 ` [RFC PATCH] vsprintf: Add %p*D extension for 80211 SSIDs Chen Gang
[not found] ` <50EA6612.6010506-bOixZGp5f+dBDgjK7y7TUQ@public.gmane.org>
2013-01-07 6:37 ` Joe Perches
2013-01-07 6:58 ` Chen Gang
2013-01-07 7:47 ` Johannes Berg
2013-01-07 17:22 ` Joe Perches
2013-01-08 2:57 ` Chen Gang
[not found] ` <50EB8B1A.9000404-bOixZGp5f+dBDgjK7y7TUQ@public.gmane.org>
2013-01-08 3:11 ` Joe Perches
2013-01-08 3:20 ` Chen Gang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1357534195.21481.31.camel@joe-AO722 \
--to=joe@perches.com \
--cc=gang.chen@asianux.com \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=netdev@vger.kernel.org \
--cc=stas.yakovlev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).