aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/staging/csr/Makefile1
-rw-r--r--drivers/staging/csr/csr_msgconv.h1
-rw-r--r--drivers/staging/csr/csr_serialize_primitive_types.c28
-rw-r--r--drivers/staging/csr/csr_unicode.h87
-rw-r--r--drivers/staging/csr/csr_utf16.c1055
-rw-r--r--drivers/staging/csr/csr_wifi_msgconv.h1
-rw-r--r--drivers/staging/csr/csr_wifi_nme_ap_serialize.c1
-rw-r--r--drivers/staging/csr/csr_wifi_router_ctrl_serialize.c3
-rw-r--r--drivers/staging/csr/csr_wifi_router_serialize.c3
-rw-r--r--drivers/staging/csr/csr_wifi_sme_serialize.c3
10 files changed, 28 insertions, 1155 deletions
diff --git a/drivers/staging/csr/Makefile b/drivers/staging/csr/Makefile
index 814f57a539db..afda44b0a925 100644
--- a/drivers/staging/csr/Makefile
+++ b/drivers/staging/csr/Makefile
@@ -71,6 +71,5 @@ csr_helper-y := csr_time.o \
71 csr_framework_ext.o \ 71 csr_framework_ext.o \
72 csr_wifi_serialize_primitive_types.o \ 72 csr_wifi_serialize_primitive_types.o \
73 csr_serialize_primitive_types.o \ 73 csr_serialize_primitive_types.o \
74 csr_utf16.o \
75 csr_msgconv.o \ 74 csr_msgconv.o \
76 csr_panic.o 75 csr_panic.o
diff --git a/drivers/staging/csr/csr_msgconv.h b/drivers/staging/csr/csr_msgconv.h
index 2e1aad8a3895..08497096fdfe 100644
--- a/drivers/staging/csr/csr_msgconv.h
+++ b/drivers/staging/csr/csr_msgconv.h
@@ -14,7 +14,6 @@
14#include <linux/types.h> 14#include <linux/types.h>
15#include "csr_prim_defs.h" 15#include "csr_prim_defs.h"
16#include "csr_sched.h" 16#include "csr_sched.h"
17#include "csr_unicode.h"
18 17
19#ifdef __cplusplus 18#ifdef __cplusplus
20extern "C" { 19extern "C" {
diff --git a/drivers/staging/csr/csr_serialize_primitive_types.c b/drivers/staging/csr/csr_serialize_primitive_types.c
index 39406fd1f1a1..a6f29ea36d20 100644
--- a/drivers/staging/csr/csr_serialize_primitive_types.c
+++ b/drivers/staging/csr/csr_serialize_primitive_types.c
@@ -15,6 +15,34 @@
15#include "csr_macro.h" 15#include "csr_macro.h"
16#include "csr_lib.h" 16#include "csr_lib.h"
17 17
18/********************************************************************************
19*
20* Name: CsrUtf16StrLen
21*
22* Description: The function returns the number of 16 bit elements present
23* in the 0-terminated string.
24*
25* Input: 0-terminated string of 16 bit unicoded characters.
26*
27* Output: The number of 16 bit elements in the string.
28*
29*********************************************************************************/
30static u32 CsrUtf16StrLen(const u16 *unicodeString)
31{
32 u32 length;
33
34 length = 0;
35 if (unicodeString != NULL)
36 {
37 while (*unicodeString)
38 {
39 length++;
40 unicodeString++;
41 }
42 }
43 return length;
44}
45
18void CsrUint8Des(u8 *value, u8 *buffer, size_t *offset) 46void CsrUint8Des(u8 *value, u8 *buffer, size_t *offset)
19{ 47{
20 *value = buffer[*offset]; 48 *value = buffer[*offset];
diff --git a/drivers/staging/csr/csr_unicode.h b/drivers/staging/csr/csr_unicode.h
deleted file mode 100644
index 2105e7110c65..000000000000
--- a/drivers/staging/csr/csr_unicode.h
+++ /dev/null
@@ -1,87 +0,0 @@
1#ifndef CSR_UNICODE_H__
2#define CSR_UNICODE_H__
3/*****************************************************************************
4
5 (c) Cambridge Silicon Radio Limited 2010
6 All rights reserved and confidential information of CSR
7
8 Refer to LICENSE.txt included with this source for details
9 on the license terms.
10
11*****************************************************************************/
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17u16 *CsrUint32ToUtf16String(u32 number);
18
19u32 CsrUtf16StringToUint32(const u16 *unicodeString);
20u32 CsrUtf16StrLen(const u16 *unicodeString);
21
22u8 *CsrUtf16String2Utf8(const u16 *source);
23
24u16 *CsrUtf82Utf16String(const u8 *utf8String);
25
26u16 *CsrUtf16StrCpy(u16 *target, const u16 *source);
27u16 *CsrUtf16StringDuplicate(const u16 *source);
28
29u16 CsrUtf16StrICmp(const u16 *string1, const u16 *string2);
30u16 CsrUtf16StrNICmp(const u16 *string1, const u16 *string2, u32 count);
31
32u16 *CsrUtf16MemCpy(u16 *dest, const u16 *src, u32 count);
33u16 *CsrUtf16ConcatenateTexts(const u16 *inputText1, const u16 *inputText2,
34 const u16 *inputText3, const u16 *inputText4);
35
36u16 *CsrUtf16String2XML(u16 *str);
37u16 *CsrXML2Utf16String(u16 *str);
38
39u32 CsrUtf8StringLengthInBytes(const u8 *string);
40
41/*******************************************************************************
42
43 NAME
44 CsrUtf8StrTruncate
45
46 DESCRIPTION
47 In-place truncate a string on a UTF-8 character boundary by writing a
48 null character somewhere in the range target[count - 3]:target[count].
49
50 Please note that memory passed must be at least of length count + 1, to
51 ensure space for a full length string that is terminated at
52 target[count], in the event that target[count - 1] is the final byte of
53 a UTF-8 character.
54
55 PARAMETERS
56 target - Target string to truncate.
57 count - The desired length, in bytes, of the resulting string. Depending
58 on the contents, the resulting string length will be between
59 count - 3 and count.
60
61 RETURNS
62 Returns target
63
64*******************************************************************************/
65u8 *CsrUtf8StrTruncate(u8 *target, size_t count);
66
67/*
68 * UCS2
69 *
70 * D-13157
71 */
72typedef u8 CsrUcs2String;
73
74size_t CsrUcs2ByteStrLen(const CsrUcs2String *ucs2String);
75size_t CsrConverterUcs2ByteStrLen(const CsrUcs2String *str);
76
77u8 *CsrUcs2ByteString2Utf8(const CsrUcs2String *ucs2String);
78CsrUcs2String *CsrUtf82Ucs2ByteString(const u8 *utf8String);
79
80u8 *CsrUtf16String2Ucs2ByteString(const u16 *source);
81u16 *CsrUcs2ByteString2Utf16String(const u8 *source);
82
83#ifdef __cplusplus
84}
85#endif
86
87#endif
diff --git a/drivers/staging/csr/csr_utf16.c b/drivers/staging/csr/csr_utf16.c
deleted file mode 100644
index 4854f85aa92a..000000000000
--- a/drivers/staging/csr/csr_utf16.c
+++ /dev/null
@@ -1,1055 +0,0 @@
1/*****************************************************************************
2
3 (c) Cambridge Silicon Radio Limited 2010
4 All rights reserved and confidential information of CSR
5
6 Refer to LICENSE.txt included with this source for details
7 on the license terms.
8
9*****************************************************************************/
10#include <linux/module.h>
11#include <linux/slab.h>
12#include "csr_unicode.h"
13#include "csr_macro.h"
14
15#define UNI_SUR_HIGH_START ((u32) 0xD800)
16#define UNI_SUR_HIGH_END ((u32) 0xDBFF)
17#define UNI_SUR_LOW_START ((u32) 0xDC00)
18#define UNI_SUR_LOW_END ((u32) 0xDFFF)
19#define UNI_REPLACEMENT_CHAR ((u32) 0xFFFD)
20#define UNI_HALF_SHIFT ((u8) 10) /* used for shifting by 10 bits */
21#define UNI_HALF_BASE ((u32) 0x00010000)
22#define UNI_BYTEMASK ((u32) 0xBF)
23#define UNI_BYTEMARK ((u32) 0x80)
24
25#define CAPITAL(x) ((x >= 'a') && (x <= 'z') ? ((x) & 0x00DF) : (x))
26
27/*
28* Index into the table with the first byte to get the number of trailing bytes in a utf-8 character.
29* -1 if the byte has an invalid value.
30*
31* Legal sequences are:
32*
33* byte 1st 2nd 3rd 4th
34*
35* 00-7F
36* C2-DF 80-BF
37* E0 A0-BF 80-BF
38* E1-EC 80-BF 80-BF
39* ED 80-9F 80-BF
40* EE-EF 80-BF 80-BF
41* F0 90-BF 80-BF 80-BF
42* F1-F3 80-BF 80-BF 80-BF
43* F4 80-8F 80-BF 80-BF
44*/
45static const s8 trailingBytesForUtf8[256] =
46{
47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 - 0x1F */
48 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 - 0x3F */
49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 - 0x5F */
50 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x7F */
51 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80 - 0x9F */
52 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xA0 - 0xBF */
53 -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xC0 - 0xDF */
54 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xE0 - 0xFF */
55};
56
57/* Values to be substracted from a u32 when converting from UTF8 to UTF16 */
58static const u32 offsetsFromUtf8[4] =
59{
60 0x00000000, 0x00003080, 0x000E2080, 0x03C82080
61};
62
63/********************************************************************************
64*
65* Name: CsrUint32ToUtf16String
66*
67* Description: The function converts an 32 bit number to an UTF-16 string
68* that is allocated and 0-terminated.
69*
70* Input: 32 bit number.
71*
72* Output: A string of UTF-16 characters.
73*
74*********************************************************************************/
75u16 *CsrUint32ToUtf16String(u32 number)
76{
77 u16 count, noOfDigits;
78 u16 *output;
79 u32 tempNumber;
80
81 /* calculate the number of digits in the output */
82 tempNumber = number;
83 noOfDigits = 1;
84 while (tempNumber >= 10)
85 {
86 tempNumber = tempNumber / 10;
87 noOfDigits++;
88 }
89
90 output = kmalloc(sizeof(u16) * (noOfDigits + 1), GFP_KERNEL); /*add space for 0-termination*/
91
92 tempNumber = number;
93 for (count = noOfDigits; count > 0; count--)
94 {
95 output[count - 1] = (u16) ((tempNumber % 10) + '0');
96 tempNumber = tempNumber / 10;
97 }
98 output[noOfDigits] = '\0';
99
100 return output;
101}
102
103/********************************************************************************
104*
105* Name: CsrUtf16StringToUint32
106*
107* Description: The function converts an UTF-16 string that is
108* 0-terminated into a 32 bit number.
109*
110* Input: A string of UTF-16 characters containig a number.
111*
112* Output: 32 bit number.
113*
114*********************************************************************************/
115u32 CsrUtf16StringToUint32(const u16 *unicodeString)
116{
117 u16 numLen, count;
118 u32 newNumber = 0;
119
120 numLen = (u16) CsrUtf16StrLen(unicodeString);
121
122 if ((numLen > 10) || (numLen == 0) || (unicodeString == NULL)) /*CSRMAX number is 4.294.967.295 */
123 {
124 return 0;
125 }
126
127 for (count = 0; count < numLen; count++)
128 {
129 u16 input = unicodeString[count];
130 if ((input < 0x30) || (input > 0x39) || ((newNumber == 0x19999999) && (input > 0x35)) || (newNumber > 0x19999999)) /* chars are present or number is too large now causing number to get to large when *10 */
131 {
132 return 0;
133 }
134
135 newNumber = (newNumber * 10) + (input - 0x30);
136 }
137 return newNumber;
138}
139
140/********************************************************************************
141*
142* Name: CsrUtf16MemCpy
143*
144* Description: The function copies count number of 16 bit data elements
145* from srv to dest.
146*
147* Input: A pointer to an unicoded string.
148*
149* Output: A pointer to an unicoded string.
150*
151*********************************************************************************/
152u16 *CsrUtf16MemCpy(u16 *dest, const u16 *src, u32 count)
153{
154 return memcpy((u8 *) dest, (u8 *) src, count * sizeof(u16));
155}
156
157/********************************************************************************
158*
159* Name: CsrUtf16ConcatenateTexts
160*
161* Description: The function merge the contents of 4 unicoded input pointers
162* into a new string.
163*
164* Input: 4 unicoded input strings (UTF-16).
165*
166* Output: A new unicoded string (UTF-16) containing the combined strings.
167*
168*********************************************************************************/
169u16 *CsrUtf16ConcatenateTexts(const u16 *inputText1, const u16 *inputText2,
170 const u16 *inputText3, const u16 *inputText4)
171{
172 u16 *outputText;
173 u32 textLen, textLen1, textLen2, textLen3, textLen4;
174
175 textLen1 = CsrUtf16StrLen(inputText1);
176 textLen2 = CsrUtf16StrLen(inputText2);
177 textLen3 = CsrUtf16StrLen(inputText3);
178 textLen4 = CsrUtf16StrLen(inputText4);
179
180 textLen = textLen1 + textLen2 + textLen3 + textLen4;
181
182 if (textLen == 0) /*stop here is all lengths are 0*/
183 {
184 return NULL;
185 }
186
187 outputText = kmalloc((textLen + 1) * sizeof(u16), GFP_KERNEL); /* add space for 0-termination*/
188
189
190 if (inputText1 != NULL)
191 {
192 CsrUtf16MemCpy(outputText, inputText1, textLen1);
193 }
194
195 if (inputText2 != NULL)
196 {
197 CsrUtf16MemCpy(&(outputText[textLen1]), inputText2, textLen2);
198 }
199
200 if (inputText3 != NULL)
201 {
202 CsrUtf16MemCpy(&(outputText[textLen1 + textLen2]), inputText3, textLen3);
203 }
204
205 if (inputText4 != NULL)
206 {
207 CsrUtf16MemCpy(&(outputText[textLen1 + textLen2 + textLen3]), inputText4, textLen4);
208 }
209
210 outputText[textLen] = '\0';
211
212 return outputText;
213}
214
215/********************************************************************************
216*
217* Name: CsrUtf16StrLen
218*
219* Description: The function returns the number of 16 bit elements present
220* in the 0-terminated string.
221*
222* Input: 0-terminated string of 16 bit unicoded characters.
223*
224* Output: The number of 16 bit elements in the string.
225*
226*********************************************************************************/
227u32 CsrUtf16StrLen(const u16 *unicodeString)
228{
229 u32 length;
230
231 length = 0;
232 if (unicodeString != NULL)
233 {
234 while (*unicodeString)
235 {
236 length++;
237 unicodeString++;
238 }
239 }
240 return length;
241}
242
243/********************************************************************************
244*
245* Name: CsrUtf16String2Utf8
246*
247* Description: The function decodes an UTF-16 string into an UTF8 byte
248* oriented string.
249*
250* Input: 0-terminated UTF-16 string characters.
251*
252* Output: 0-terminated string of byte oriented UTF8 coded characters.
253*
254*********************************************************************************/
255u8 *CsrUtf16String2Utf8(const u16 *source)
256{
257 u8 *dest, *destStart = NULL;
258 u32 i;
259 u32 ch;
260 u32 length;
261 u32 sourceLength;
262 u8 bytes;
263 u8 appendNull = FALSE;
264
265 u8 firstByteMark[5] = {0x00, 0x00, 0xC0, 0xE0, 0xF0};
266
267 if (!source)
268 {
269 return NULL;
270 }
271
272 length = 0;
273 sourceLength = CsrUtf16StrLen(source) + 1;
274
275 for (i = 0; i < sourceLength; i++)
276 {
277 ch = source[i];
278 if ((ch >= UNI_SUR_HIGH_START) && (ch <= UNI_SUR_HIGH_END)) /* This is a high surrogate */
279 {
280 if (i + 1 < sourceLength) /* The low surrogate is in the source */
281 {
282 u32 ch2 = source[++i];
283 if ((ch2 >= UNI_SUR_LOW_START) && (ch2 <= UNI_SUR_LOW_END)) /* And it is a legal low surrogate */
284 {
285 length += 4;
286 }
287 else /* It is not a low surrogate, instead put a Unicode
288 'REPLACEMENT CHARACTER' (U+FFFD) */
289 {
290 length += 3;
291 i--; /* Substract 1 again as the conversion must continue after the ill-formed code unit */
292 }
293 }
294 else /* The low surrogate does not exist, instead put a Unicode
295 'REPLACEMENT CHARACTER' (U+FFFD), and the null terminated character */
296 {
297 length += 4;
298 }
299 }
300 else if ((ch >= UNI_SUR_LOW_START) && (ch <= UNI_SUR_LOW_END)) /* The value of UTF-16 is not allowed to be in this range, instead put
301 a Unicode 'REPLACEMENT CHARACTER' (U+FFFD) */
302 {
303 length += 3;
304 }
305 else /* Figure out how many bytes that are required */
306 {
307 if (ch < 0x0080)
308 {
309 length++;
310 }
311 else if (ch < 0x0800)
312 {
313 length += 2;
314 }
315 else
316 {
317 length += 3;
318 }
319 }
320 }
321
322 dest = kmalloc(length, GFP_KERNEL);
323 destStart = dest;
324
325 for (i = 0; i < sourceLength; i++)
326 {
327 ch = source[i];
328 if ((ch >= UNI_SUR_HIGH_START) && (ch <= UNI_SUR_HIGH_END)) /* This is a high surrogate */
329 {
330 if (i + 1 < sourceLength) /* The low surrogate is in the source */
331 {
332 u32 ch2 = source[++i];
333 if ((ch2 >= UNI_SUR_LOW_START) && (ch2 <= UNI_SUR_LOW_END)) /* And it is a legal low surrogate, convert to UTF-32 */
334 {
335 ch = ((ch - UNI_SUR_HIGH_START) << UNI_HALF_SHIFT) + (ch2 - UNI_SUR_LOW_START) + UNI_HALF_BASE;
336 }
337 else /* It is not a low surrogate, instead put a Unicode
338 'REPLACEMENT CHARACTER' (U+FFFD) */
339 {
340 ch = UNI_REPLACEMENT_CHAR;
341 i--; /* Substract 1 again as the conversion must continue after the ill-formed code unit */
342 }
343 }
344 else /* The low surrogate does not exist, instead put a Unicode
345 'REPLACEMENT CHARACTER' (U+FFFD), and the null terminated character */
346 {
347 ch = UNI_REPLACEMENT_CHAR;
348 appendNull = TRUE;
349 }
350 }
351 else if ((ch >= UNI_SUR_LOW_START) && (ch <= UNI_SUR_LOW_END)) /* The value of UTF-16 is not allowed to be in this range, instead put
352 a Unicode 'REPLACEMENT CHARACTER' (U+FFFD) */
353 {
354 ch = UNI_REPLACEMENT_CHAR;
355 }
356
357 /* Figure out how many bytes that are required */
358 if (ch < (u32) 0x80)
359 {
360 bytes = 1;
361 }
362 else if (ch < (u32) 0x800)
363 {
364 bytes = 2;
365 }
366 else if (ch < (u32) 0x10000)
367 {
368 bytes = 3;
369 }
370 else if (ch < (u32) 0x110000)
371 {
372 bytes = 4;
373 }
374 else
375 {
376 bytes = 3;
377 ch = UNI_REPLACEMENT_CHAR;
378 }
379
380 dest += bytes;
381
382 switch (bytes) /* Convert character to UTF-8. Note: everything falls through. */
383 {
384 case 4:
385 {
386 *--dest = (u8) ((ch | UNI_BYTEMARK) & UNI_BYTEMASK);
387 ch >>= 6;
388 }
389 /* FALLTHROUGH */
390 case 3:
391 {
392 *--dest = (u8) ((ch | UNI_BYTEMARK) & UNI_BYTEMASK);
393 ch >>= 6;
394 }
395 /* FALLTHROUGH */
396 case 2:
397 {
398 *--dest = (u8) ((ch | UNI_BYTEMARK) & UNI_BYTEMASK);
399 ch >>= 6;
400 }
401 /* FALLTHROUGH */
402 case 1:
403 {
404 *--dest = (u8) (ch | firstByteMark[bytes]);
405 }
406 /* FALLTHROUGH */
407 default:
408 {
409 break;
410 }
411 }
412
413 dest += bytes;
414 }
415
416 if (appendNull) /* Append the \0 character */
417 {
418 *dest = '\0';
419 }
420
421 return destStart;
422}
423
424/*****************************************************************************
425
426 NAME
427 isLegalUtf8
428
429 DESCRIPTION
430 Returns TRUE if the given UFT-8 code unit is legal as defined by the
431 Unicode standard (see Chapter 3: Conformance, Section 3.9: Unicode
432 Encoding Forms, UTF-8).
433
434 This function assumes that the length parameter is unconditionally
435 correct and that the first byte is already validated by looking it up
436 in the trailingBytesForUtf8 array, which also reveals the number of
437 trailing bytes.
438
439 Legal code units are composed of one of the following byte sequences:
440
441 1st 2nd 3rd 4th
442 --------------------------------
443 00-7F
444 C2-DF 80-BF
445 E0 A0-BF 80-BF
446 E1-EC 80-BF 80-BF
447 ED 80-9F 80-BF
448 EE-EF 80-BF 80-BF
449 F0 90-BF 80-BF 80-BF
450 F1-F3 80-BF 80-BF 80-BF
451 F4 80-8F 80-BF 80-BF
452
453 Please note that this function only checks whether the 2nd, 3rd and
454 4th bytes fall into the valid ranges.
455
456 PARAMETERS
457 codeUnit - pointer to the first byte of the byte sequence composing
458 the code unit to test.
459 length - the number of bytes in the code unit. Valid range is 1 to 4.
460
461 RETURNS
462 TRUE if the given code unit is legal.
463
464*****************************************************************************/
465static u8 isLegalUtf8(const u8 *codeUnit, u32 length)
466{
467 const u8 *srcPtr = codeUnit + length;
468 u8 byte;
469
470 switch (length) /* Everything falls through except case 1 */
471 {
472 case 4:
473 {
474 byte = *--srcPtr;
475 if ((byte < 0x80) || (byte > 0xBF))
476 {
477 return FALSE;
478 }
479 }
480 /* Fallthrough */
481 case 3:
482 {
483 byte = *--srcPtr;
484 if ((byte < 0x80) || (byte > 0xBF))
485 {
486 return FALSE;
487 }
488 }
489 /* Fallthrough */
490 case 2:
491 {
492 byte = *--srcPtr;
493 if (byte > 0xBF)
494 {
495 return FALSE;
496 }
497
498 switch (*codeUnit) /* No fallthrough */
499 {
500 case 0xE0:
501 {
502 if (byte < 0xA0)
503 {
504 return FALSE;
505 }
506 break;
507 }
508 case 0xED:
509 {
510 if ((byte < 0x80) || (byte > 0x9F))
511 {
512 return FALSE;
513 }
514 break;
515 }
516 case 0xF0:
517 {
518 if (byte < 0x90)
519 {
520 return FALSE;
521 }
522 break;
523 }
524 case 0xF4:
525 {
526 if ((byte < 0x80) || (byte > 0x8F))
527 {
528 return FALSE;
529 }
530 break;
531 }
532 default:
533 {
534 if (byte < 0x80)
535 {
536 return FALSE;
537 }
538 break;
539 }
540 }
541 }
542 /* Fallthrough */
543 case 1:
544 default:
545 /* The 1st byte and length are assumed correct */
546 break;
547 }
548
549 return TRUE;
550}
551
552/********************************************************************************
553*
554* Name: CsrUtf82Utf16String
555*
556* Description: The function decodes an UTF8 byte oriented string into a
557* UTF-16string.
558*
559* Input: 0-terminated string of byte oriented UTF8 coded characters.
560*
561* Output: 0-terminated string of UTF-16 characters.
562*
563*********************************************************************************/
564u16 *CsrUtf82Utf16String(const u8 *utf8String)
565{
566 size_t i, length = 0;
567 size_t sourceLength;
568 u16 *dest = NULL;
569 u16 *destStart = NULL;
570 s8 extraBytes2Read;
571
572 if (!utf8String)
573 {
574 return NULL;
575 }
576 sourceLength = strlen((char *)utf8String);
577
578 for (i = 0; i < sourceLength; i++)
579 {
580 extraBytes2Read = trailingBytesForUtf8[utf8String[i]];
581
582 if (extraBytes2Read == -1) /* Illegal byte value, instead put a Unicode 'REPLACEMENT CHARACTER' (U+FFFD) */
583 {
584 length += 1;
585 }
586 else if (i + extraBytes2Read > sourceLength) /* The extra bytes does not exist, instead put a Unicode 'REPLACEMENT
587 CHARACTER' (U+FFFD), and the null terminated character */
588 {
589 length += 2;
590 break;
591 }
592 else if (isLegalUtf8(&utf8String[i], extraBytes2Read + 1) == FALSE) /* It is not a legal utf-8 character, instead put a Unicode 'REPLACEMENT
593 CHARACTER' (U+FFFD) */
594 {
595 length += 1;
596 }
597 else
598 {
599 if (utf8String[i] > 0xEF) /* Needs a high and a low surrogate */
600 {
601 length += 2;
602 }
603 else
604 {
605 length += 1;
606 }
607 i += extraBytes2Read;
608 }
609 }
610
611 /* Create space for the null terminated character */
612 dest = kmalloc((1 + length) * sizeof(u16), GFP_KERNEL);
613 destStart = dest;
614
615 for (i = 0; i < sourceLength; i++)
616 {
617 extraBytes2Read = trailingBytesForUtf8[utf8String[i]];
618
619 if (extraBytes2Read == -1) /* Illegal byte value, instead put a Unicode 'REPLACEMENT CHARACTER' (U+FFFD) */
620 {
621 *dest++ = UNI_REPLACEMENT_CHAR;
622 }
623 else if (i + extraBytes2Read > sourceLength) /* The extra bytes does not exist, instead put a Unicode 'REPLACEMENT
624 CHARACTER' (U+FFFD), and the null terminated character */
625 {
626 *dest++ = UNI_REPLACEMENT_CHAR;
627 *dest++ = '\0';
628 break;
629 }
630 else if (isLegalUtf8(&utf8String[i], extraBytes2Read + 1) == FALSE) /* It is not a legal utf-8 character, instead put a Unicode 'REPLACEMENT
631 CHARACTER' (U+FFFD) */
632 {
633 *dest++ = UNI_REPLACEMENT_CHAR;
634 }
635 else /* It is legal, convert the character to an u32 */
636 {
637 u32 ch = 0;
638
639 switch (extraBytes2Read) /* Everything falls through */
640 {
641 case 3:
642 {
643 ch += utf8String[i];
644 ch <<= 6;
645 i++;
646 }
647 /* FALLTHROUGH */
648 case 2:
649 {
650 ch += utf8String[i];
651 ch <<= 6;
652 i++;
653 }
654 /* FALLTHROUGH */
655 case 1:
656 {
657 ch += utf8String[i];
658 ch <<= 6;
659 i++;
660 }
661 /* FALLTHROUGH */
662 case 0:
663 {
664 ch += utf8String[i];
665 }
666 /* FALLTHROUGH */
667 default:
668 {
669 break;
670 }
671 }
672
673 ch -= offsetsFromUtf8[extraBytes2Read];
674
675 if (ch <= 0xFFFF) /* Character can be encoded in one u16 */
676 {
677 *dest++ = (u16) ch;
678 }
679 else /* The character needs two u16 */
680 {
681 ch -= UNI_HALF_BASE;
682 *dest++ = (u16) ((ch >> UNI_HALF_SHIFT) | UNI_SUR_HIGH_START);
683 *dest++ = (u16) ((ch & 0x03FF) | UNI_SUR_LOW_START);
684 }
685 }
686 }
687
688 destStart[length] = 0x00;
689
690 return destStart;
691}
692
693/********************************************************************************
694*
695* Name: CsrUtf16StrCpy
696*
697* Description: The function copies the contents from one UTF-16 string
698* to another UTF-16 string.
699*
700* Input: 0-terminated UTF-16 string.
701*
702* Output: 0-terminated UTF-16 string.
703*
704*********************************************************************************/
705u16 *CsrUtf16StrCpy(u16 *target, const u16 *source)
706{
707 if (source) /* if source is not NULL*/
708 {
709 memcpy(target, source, (CsrUtf16StrLen(source) + 1) * sizeof(u16));
710 return target;
711 }
712 else
713 {
714 return NULL;
715 }
716}
717
718/********************************************************************************
719*
720* Name: CsrUtf16StringDuplicate
721*
722* Description: The function allocates a new pointer and copies the input to
723* the new pointer.
724*
725* Input: 0-terminated UTF-16 string.
726*
727* Output: Allocated variable0-terminated UTF-16 string.
728*
729*********************************************************************************/
730u16 *CsrUtf16StringDuplicate(const u16 *source)
731{
732 u16 *target = NULL;
733 u32 length;
734
735 if (source) /* if source is not NULL*/
736 {
737 length = (CsrUtf16StrLen(source) + 1) * sizeof(u16);
738 target = kmalloc(length, GFP_KERNEL);
739 memcpy(target, source, length);
740 }
741 return target;
742}
743
744/********************************************************************************
745*
746* Name: CsrUtf16StrICmp
747*
748* Description: The function compares two UTF-16 strings.
749*
750* Input: Two 0-terminated UTF-16 string.
751*
752* Output: 0: if the strings are identical.
753*
754*********************************************************************************/
755u16 CsrUtf16StrICmp(const u16 *string1, const u16 *string2)
756{
757 while (*string1 || *string2)
758 {
759 if (CAPITAL(*string1) != CAPITAL(*string2))
760 {
761 return *string1 - *string2;
762 }
763 string1++;
764 string2++;
765 }
766
767 return 0;
768}
769
770/********************************************************************************
771*
772* Name: CsrUtf16StrNICmp
773*
774* Description: The function compares upto count number of elements in the
775* two UTF-16 string.
776*
777* Input: Two 0-terminated UTF-16 string and a maximum
778* number of elements to check.
779*
780* Output: 0: if the strings are identical.
781*
782*********************************************************************************/
783u16 CsrUtf16StrNICmp(const u16 *string1, const u16 *string2, u32 count)
784{
785 while ((*string1 || *string2) && count--)
786 {
787 if (CAPITAL(*string1) != CAPITAL(*string2))
788 {
789 return *string1 - *string2;
790 }
791 string1++;
792 string2++;
793 }
794
795 return 0;
796}
797
798/********************************************************************************
799*
800* Name: CsrUtf16String2XML
801*
802* Description: The function converts an unicoded string (UTF-16) into an unicoded XML
803* string where some special characters are encoded according to
804* the XML spec.
805*
806* Input: A unicoded string (UTF-16) which is freed.
807*
808* Output: A new unicoded string (UTF-16) containing the converted output.
809*
810*********************************************************************************/
811u16 *CsrUtf16String2XML(u16 *str)
812{
813 u16 *scanString;
814 u16 *outputString = NULL;
815 u16 *resultString = str;
816 u32 stringLength = 0;
817 u8 encodeChars = FALSE;
818
819 scanString = str;
820 if (scanString)
821 {
822 while (*scanString)
823 {
824 if (*scanString == L'&')
825 {
826 stringLength += 5;
827 encodeChars = TRUE;
828 }
829 else if ((*scanString == L'<') || (*scanString == L'>'))
830 {
831 stringLength += 4;
832 encodeChars = TRUE;
833 }
834 else
835 {
836 stringLength++;
837 }
838
839 scanString++;
840 }
841
842 stringLength++;
843
844 if (encodeChars)
845 {
846 resultString = outputString = kmalloc(stringLength * sizeof(u16), GFP_KERNEL);
847
848 scanString = str;
849
850 while (*scanString)
851 {
852 if (*scanString == L'&')
853 {
854 *outputString++ = '&';
855 *outputString++ = 'a';
856 *outputString++ = 'm';
857 *outputString++ = 'p';
858 *outputString++ = ';';
859 }
860 else if (*scanString == L'<')
861 {
862 *outputString++ = '&';
863 *outputString++ = 'l';
864 *outputString++ = 't';
865 *outputString++ = ';';
866 }
867 else if (*scanString == L'>')
868 {
869 *outputString++ = '&';
870 *outputString++ = 'g';
871 *outputString++ = 't';
872 *outputString++ = ';';
873 }
874 else
875 {
876 *outputString++ = *scanString;
877 }
878
879 scanString++;
880 }
881
882 *outputString++ = 0;
883
884 kfree(str);
885 }
886 }
887
888 return resultString;
889}
890
891/********************************************************************************
892*
893* Name: CsrXML2Utf16String
894*
895* Description: The function converts an unicoded XML string into an unicoded
896* string (UTF-16) where some special XML characters are decoded according to
897* the XML spec.
898*
899* Input: A unicoded XML string which is freed.
900*
901* Output: A new unicoded pointer containing the decoded output.
902*
903*********************************************************************************/
904u16 *CsrXML2Utf16String(u16 *str)
905{
906 u16 *scanString;
907 u16 *outputString = NULL;
908 u16 *resultString = str;
909 u32 stringLength = 0;
910 u8 encodeChars = FALSE;
911
912 scanString = str;
913 if (scanString)
914 {
915 while (*scanString)
916 {
917 if (*scanString == (u16) L'&')
918 {
919 scanString++;
920
921 if (!CsrUtf16StrNICmp(scanString, (u16 *) L"AMP;", 4))
922 {
923 scanString += 3;
924 encodeChars = TRUE;
925 }
926 else if (!CsrUtf16StrNICmp(scanString, (u16 *) L"LT;", 3))
927 {
928 scanString += 2;
929 encodeChars = TRUE;
930 }
931 else if (!CsrUtf16StrNICmp(scanString, (u16 *) L"GT;", 3))
932 {
933 scanString += 2;
934 encodeChars = TRUE;
935 }
936 if (!CsrUtf16StrNICmp(scanString, (u16 *) L"APOS;", 5))
937 {
938 scanString += 4;
939 encodeChars = TRUE;
940 }
941 if (!CsrUtf16StrNICmp(scanString, (u16 *) L"QUOT;", 5))
942 {
943 scanString += 4;
944 encodeChars = TRUE;
945 }
946 else
947 {
948 scanString--;
949 }
950 }
951
952 stringLength++;
953 scanString++;
954 }
955
956 stringLength++;
957
958 if (encodeChars)
959 {
960 resultString = outputString = kmalloc(stringLength * sizeof(u16), GFP_KERNEL);
961
962 scanString = str;
963
964 while (*scanString)
965 {
966 if (*scanString == L'&')
967 {
968 scanString++;
969
970 if (!CsrUtf16StrNICmp(scanString, (u16 *) L"AMP;", 4))
971 {
972 *outputString++ = L'&';
973 scanString += 3;
974 }
975 else if (!CsrUtf16StrNICmp(scanString, (u16 *) L"LT;", 3))
976 {
977 *outputString++ = L'<';
978 scanString += 2;
979 }
980 else if (!CsrUtf16StrNICmp(scanString, (u16 *) L"GT;", 3))
981 {
982 *outputString++ = L'>';
983 scanString += 2;
984 }
985 else if (!CsrUtf16StrNICmp(scanString, (u16 *) L"APOS;", 5))
986 {
987 *outputString++ = L'\'';
988 scanString += 4;
989 }
990 else if (!CsrUtf16StrNICmp(scanString, (u16 *) L"QUOT;", 5))
991 {
992 *outputString++ = L'\"';
993 scanString += 4;
994 }
995 else
996 {
997 *outputString++ = L'&';
998 scanString--;
999 }
1000 }
1001 else
1002 {
1003 *outputString++ = *scanString;
1004 }
1005
1006 scanString++;
1007 }
1008
1009 *outputString++ = 0;
1010
1011 kfree(str);
1012 }
1013 }
1014
1015 return resultString;
1016}
1017
1018u32 CsrUtf8StringLengthInBytes(const u8 *string)
1019{
1020 size_t length = 0;
1021 if (string)
1022 {
1023 length = strlen((const char *)string);
1024 }
1025 return (u32) length;
1026}
1027
1028u8 *CsrUtf8StrTruncate(u8 *target, size_t count)
1029{
1030 size_t lastByte = count - 1;
1031
1032 target[count] = '\0';
1033
1034 if (count && (target[lastByte] & 0x80))
1035 {
1036 /* the last byte contains non-ascii char */
1037 if (target[lastByte] & 0x40)
1038 {
1039 /* multi-byte char starting just before truncation */
1040 target[lastByte] = '\0';
1041 }
1042 else if ((target[lastByte - 1] & 0xE0) == 0xE0)
1043 {
1044 /* 3-byte char starting 2 bytes before truncation */
1045 target[lastByte - 1] = '\0';
1046 }
1047 else if ((target[lastByte - 2] & 0xF0) == 0xF0)
1048 {
1049 /* 4-byte char starting 3 bytes before truncation */
1050 target[lastByte - 2] = '\0';
1051 }
1052 }
1053
1054 return target;
1055}
diff --git a/drivers/staging/csr/csr_wifi_msgconv.h b/drivers/staging/csr/csr_wifi_msgconv.h
index 06314109098a..7ec35d70e14a 100644
--- a/drivers/staging/csr/csr_wifi_msgconv.h
+++ b/drivers/staging/csr/csr_wifi_msgconv.h
@@ -13,7 +13,6 @@
13 13
14#include "csr_prim_defs.h" 14#include "csr_prim_defs.h"
15#include "csr_sched.h" 15#include "csr_sched.h"
16#include "csr_unicode.h"
17 16
18#ifdef __cplusplus 17#ifdef __cplusplus
19extern "C" { 18extern "C" {
diff --git a/drivers/staging/csr/csr_wifi_nme_ap_serialize.c b/drivers/staging/csr/csr_wifi_nme_ap_serialize.c
index 493e33e95e24..1a901a70d195 100644
--- a/drivers/staging/csr/csr_wifi_nme_ap_serialize.c
+++ b/drivers/staging/csr/csr_wifi_nme_ap_serialize.c
@@ -12,7 +12,6 @@
12#include <linux/string.h> 12#include <linux/string.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include "csr_msgconv.h" 14#include "csr_msgconv.h"
15#include "csr_unicode.h"
16 15
17#ifdef CSR_WIFI_NME_ENABLE 16#ifdef CSR_WIFI_NME_ENABLE
18#ifdef CSR_WIFI_AP_ENABLE 17#ifdef CSR_WIFI_AP_ENABLE
diff --git a/drivers/staging/csr/csr_wifi_router_ctrl_serialize.c b/drivers/staging/csr/csr_wifi_router_ctrl_serialize.c
index b9f9adb5ad5d..3eda1b66b336 100644
--- a/drivers/staging/csr/csr_wifi_router_ctrl_serialize.c
+++ b/drivers/staging/csr/csr_wifi_router_ctrl_serialize.c
@@ -12,9 +12,6 @@
12#include <linux/string.h> 12#include <linux/string.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include "csr_msgconv.h" 14#include "csr_msgconv.h"
15#include "csr_unicode.h"
16
17
18#include "csr_wifi_router_ctrl_prim.h" 15#include "csr_wifi_router_ctrl_prim.h"
19#include "csr_wifi_router_ctrl_serialize.h" 16#include "csr_wifi_router_ctrl_serialize.h"
20 17
diff --git a/drivers/staging/csr/csr_wifi_router_serialize.c b/drivers/staging/csr/csr_wifi_router_serialize.c
index 5717ebc05b0b..4eccf5d6c289 100644
--- a/drivers/staging/csr/csr_wifi_router_serialize.c
+++ b/drivers/staging/csr/csr_wifi_router_serialize.c
@@ -11,9 +11,6 @@
11/* Note: this is an auto-generated file. */ 11/* Note: this is an auto-generated file. */
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include "csr_msgconv.h" 13#include "csr_msgconv.h"
14#include "csr_unicode.h"
15
16
17#include "csr_wifi_router_prim.h" 14#include "csr_wifi_router_prim.h"
18#include "csr_wifi_router_serialize.h" 15#include "csr_wifi_router_serialize.h"
19 16
diff --git a/drivers/staging/csr/csr_wifi_sme_serialize.c b/drivers/staging/csr/csr_wifi_sme_serialize.c
index d55e3ee6921a..7d7e1d8b5ed3 100644
--- a/drivers/staging/csr/csr_wifi_sme_serialize.c
+++ b/drivers/staging/csr/csr_wifi_sme_serialize.c
@@ -12,9 +12,6 @@
12#include <linux/string.h> 12#include <linux/string.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include "csr_msgconv.h" 14#include "csr_msgconv.h"
15#include "csr_unicode.h"
16
17
18#include "csr_wifi_sme_prim.h" 15#include "csr_wifi_sme_prim.h"
19#include "csr_wifi_sme_serialize.h" 16#include "csr_wifi_sme_serialize.h"
20 17