vsprintf: add Bluetooth UUID %pU[rR] format specifier
Subsystems (3)
PATCH 1/1 vsprintf: add Bluetooth UUID %pU[rR] format specifier
The Bluetooth UUID is used in big endian reversed order. Add new modifier to print a UUID in big endian, but where the input byte stream is actually in reversed order.
This is similar to %pMR that allows to print a MAC address in reversed order since that is how the Bluetooth BD_ADDR is actually represented in a byte stream.
--- Documentation/printk-formats.txt | 6 ++++++ lib/vsprintf.c | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-)
Documentation/printk-formats.txt +6 -0
@@ -159,12 +159,18 @@ UUID/GUID addresses: %pUB 00010203-0405-0607-0809-0A0B0C0D0E0F %pUl 03020100-0504-0706-0809-0a0b0c0e0e0f %pUL 03020100-0504-0706-0809-0A0B0C0E0E0F + %pUr 0f0e0d0c-0b0a-0908-0706-050403020100 + %pUR 0F0E0D0C-0B0A-0908-0706-050403020100 For printing 16-byte UUID/GUIDs addresses. The additional 'l', 'L', 'b' and 'B' specifiers are used to specify a little endian order in lower ('l') or upper case ('L') hex characters - and big endian order in lower ('b') or upper case ('B') hex characters. + The additional 'r' and 'R' specifiers are used to specify reversed + big endian order in either lower ('r') or upper case ('R') hex + characters. This is useful for Bluetooth UUID addresses. + Where no additional specifiers are used the default little endian order with lower case hex characters will be printed.
lib/vsprintf.c +17 -3
@@ -1106,6 +1106,7 @@ char *uuid_string(char *buf, char *end, const u8 *addr,static const u8 le[16 ] = {3 ,2 ,1 ,0 ,5 ,4 ,7 ,6 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 };const u8 *index = be;bool uc = false; +bool reversed = false;switch (*(++fmt)) {case 'L' :
@@ -1116,10 +1117,19 @@ char *uuid_string(char *buf, char *end, const u8 *addr,case 'B' : uc = true;break ; +case 'R' : + uc = true;/* fall-through */ +case 'r' : + reversed = true; +break ; }for (i =0 ; i <16 ; i++) { - p =hex_byte_pack (p, addr[index[i]]); +if (reversed) + p =hex_byte_pack (p, addr[index[15 - i]]); +else + p =hex_byte_pack (p, addr[index[i]]); +switch (i) {case 3 :case 5 :
@@ -1199,10 +1209,14 @@ int kptr_restrict __read_mostly;* B big endian UPPER case hex * l little endian lower case hex * L little endian UPPER case hex +* r big endian lower case hex, reverse order (Bluetooth) +* R big endian UPPER case hex, reverse order (Bluetooth) * big endian output byte order is: * [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] +* big endian, reverse order output byte order is: +* [15][14][13][12]-[11][10]-[9][8]-[7][6]-[5][4][3][2][1][0] * - 'V' For a struct va_format which contains a format string * and va_list *, * call vsnprintf(->format, *->va_list). * Implements a "recursive vsnprintf".
@@ -1572,8 +1586,8 @@ qualifier:* %pI6c print an IPv6 address as specified by RFC 5952 * %pIS depending on sa_family of 'struct sockaddr *' print IPv4/IPv6 address * %piS depending on sa_family of 'struct sockaddr *' print IPv4/IPv6 address -* %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper -* case. +* %pU[bBlLrR] print a UUID/GUID in big or little endian or reversed order +* big endian using lower or upper case. * %*ph[CDN] a variable-length hex string with a separator (supports up to 64 * bytes of the input) * %n is ignored
Signature · 1 line
1.8.3.1
Quoted 6 lines · Marcel Holtmann
The Bluetooth UUID is used in big endian reversed order. Add new modifier to print a UUID in big endian, but where the input byte stream is actually in reversed order.
This is similar to %pMR that allows to print a MAC address in reversed order since that is how the BluetoothBD_ADDRis actually represented in a byte stream.
Seems sensible. Other than print_bt_uuid, is
there another place where will it be used?
Are you going to convert print_bt_uuid to use this?
lib/vsprintf.c
Quoted 1 line
lib/vsprintf.c +0
-0
[]
lib/vsprintf.c char *uuid_string(char *buf, char *end, const u8 *addr, · line 1111
Quoted 7 lines
lib/vsprintf.c +1
-0@@ -1106,6 +1106,7 @@ char *uuid_string(char *buf, char *end, const u8 *addr,static const u8 le[16 ] = {3 ,2 ,1 ,0 ,5 ,4 ,7 ,6 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 };const u8 *index = be;bool uc = false; +bool reversed = false;switch (*(++fmt)) {
Could there ever be a little endian reversed UUID?
Might it be useful to change this to:
while (isalpha(*++fmt)) {
switch (*fmt) {etc?
Hi Joe,
Quoted 11 lines
Quoted 6 lines
The Bluetooth UUID is used in big endian reversed order. Add new modifier to print a UUID in big endian, but where the input byte stream is actually in reversed order.
This is similar to %pMR that allows to print a MAC address in reversed order since that is how the BluetoothBD_ADDRis actually represented in a byte stream.Seems sensible. Other than
print_bt_uuid, is
there another place where will it be used?Are you going to convert
print_bt_uuidto use this?
my plan is to convert this one when this modifier gets upstream.
Quoted 11 lines
lib/vsprintf.c
Quoted 1 line
lib/vsprintf.c +0
-0[]
lib/vsprintf.c char *uuid_string(char *buf, char *end, const u8 *addr, · line 1111
Quoted 7 lines
lib/vsprintf.c +1
-0@@ -1106,6 +1106,7 @@ char *uuid_string(char *buf, char *end, const u8 *addr,static const u8 le[16 ] = {3 ,2 ,1 ,0 ,5 ,4 ,7 ,6 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 };const u8 *index = be;bool uc = false; +bool reversed = false;switch (*(++fmt)) {Could there ever be a little endian reversed UUID?
I honestly do not know. I looked at the little endian one and it looked a bit heavy misplaced if we would use a reversed stream of bytes.
Quoted 4 lines
Might it be useful to change this to:
while (isalpha(*++fmt)) { switch (*fmt) {
I didn't do it so the modifier didn't get any longer than it needs to be.
Regards
Marcel
Quoted 1 line · Marcel Holtmann
Hi Joe,
Hi Marcel
Quoted 10 lines
Quoted 1 line
Could there ever be a little endian reversed UUID?
I honestly do not know. I looked at the little endian one and it looked a bit heavy misplaced if we would use a reversed stream of bytes.
Quoted 4 lines
Might it be useful to change this to:
while (isalpha(*++fmt)) { switch (*fmt) {I didn't do it so the modifier didn't get any longer than it needs to be.
Given that %pU is big endian by default, then the modifier doesn't have to get longer. %pUR and %pUr would still be big endian and this would simply allow %pULR if necessary.
cheers, Joe