aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/ieee1394/csr1212.c123
1 files changed, 46 insertions, 77 deletions
diff --git a/drivers/ieee1394/csr1212.c b/drivers/ieee1394/csr1212.c
index 4887e4895fd7..63bf11eb4d31 100644
--- a/drivers/ieee1394/csr1212.c
+++ b/drivers/ieee1394/csr1212.c
@@ -388,101 +388,70 @@ csr1212_new_descriptor_leaf(u8 dtype, u32 specifier_id,
388 CSR1212_DESCRIPTOR_LEAF_SET_TYPE(kv, dtype); 388 CSR1212_DESCRIPTOR_LEAF_SET_TYPE(kv, dtype);
389 CSR1212_DESCRIPTOR_LEAF_SET_SPECIFIER_ID(kv, specifier_id); 389 CSR1212_DESCRIPTOR_LEAF_SET_SPECIFIER_ID(kv, specifier_id);
390 390
391 if (data) { 391 if (data)
392 memcpy(CSR1212_DESCRIPTOR_LEAF_DATA(kv), data, data_len); 392 memcpy(CSR1212_DESCRIPTOR_LEAF_DATA(kv), data, data_len);
393 }
394
395 return kv;
396}
397
398#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_SET_WIDTH(kv, width) \
399 ((kv)->value.leaf.data[1] = \
400 ((kv)->value.leaf.data[1] & \
401 cpu_to_be32(~(CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_MASK << \
402 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT))) | \
403 cpu_to_be32(((width) & CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_MASK) << \
404 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT))
405
406#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_SET_CHAR_SET(kv, char_set) \
407 ((kv)->value.leaf.data[1] = \
408 ((kv)->value.leaf.data[1] & \
409 cpu_to_be32(~(CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK << \
410 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT))) | \
411 cpu_to_be32(((char_set) & \
412 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK) << \
413 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT))
414
415#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_SET_LANGUAGE(kv, language) \
416 ((kv)->value.leaf.data[1] = \
417 ((kv)->value.leaf.data[1] & \
418 cpu_to_be32(~(CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK))) | \
419 cpu_to_be32(((language) & \
420 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK)))
421
422static struct csr1212_keyval *
423csr1212_new_textual_descriptor_leaf(u8 cwidth, u16 cset, u16 language,
424 const void *data, size_t data_len)
425{
426 struct csr1212_keyval *kv;
427 char *lstr;
428
429 kv = csr1212_new_descriptor_leaf(0, 0, NULL, data_len +
430 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_OVERHEAD);
431 if (!kv)
432 return NULL;
433
434 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_SET_WIDTH(kv, cwidth);
435 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_SET_CHAR_SET(kv, cset);
436 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_SET_LANGUAGE(kv, language);
437
438 lstr = (char*)CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(kv);
439
440 /* make sure last quadlet is zeroed out */
441 *((u32*)&(lstr[(data_len - 1) & ~0x3])) = 0;
442
443 /* don't copy the NUL terminator */
444 memcpy(lstr, data, data_len);
445 393
446 return kv; 394 return kv;
447} 395}
448 396
397/* Check if string conforms to minimal ASCII as per IEEE 1212 clause 7.4 */
449static int csr1212_check_minimal_ascii(const char *s) 398static int csr1212_check_minimal_ascii(const char *s)
450{ 399{
451 static const char minimal_ascii_table[] = { 400 static const char minimal_ascii_table[] = {
452 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 401 /* 1 2 4 8 16 32 64 128 */
453 0x00, 0x00, 0x0a, 0x00, 0x0C, 0x0D, 0x00, 0x00, 402 128, /* --, --, --, --, --, --, --, 07, */
454 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 403 4 + 16 + 32, /* --, --, 0a, --, 0C, 0D, --, --, */
455 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 404 0, /* --, --, --, --, --, --, --, --, */
456 0x20, 0x21, 0x22, 0x00, 0x00, 0x25, 0x26, 0x27, 405 0, /* --, --, --, --, --, --, --, --, */
457 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 406 255 - 8 - 16, /* 20, 21, 22, --, --, 25, 26, 27, */
458 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 407 255, /* 28, 29, 2a, 2b, 2c, 2d, 2e, 2f, */
459 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 408 255, /* 30, 31, 32, 33, 34, 35, 36, 37, */
460 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 409 255, /* 38, 39, 3a, 3b, 3c, 3d, 3e, 3f, */
461 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 410 255, /* 40, 41, 42, 43, 44, 45, 46, 47, */
462 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 411 255, /* 48, 49, 4a, 4b, 4c, 4d, 4e, 4f, */
463 0x58, 0x59, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x5f, 412 255, /* 50, 51, 52, 53, 54, 55, 56, 57, */
464 0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 413 1 + 2 + 4 + 128, /* 58, 59, 5a, --, --, --, --, 5f, */
465 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 414 255 - 1, /* --, 61, 62, 63, 64, 65, 66, 67, */
466 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 415 255, /* 68, 69, 6a, 6b, 6c, 6d, 6e, 6f, */
467 0x78, 0x79, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 416 255, /* 70, 71, 72, 73, 74, 75, 76, 77, */
417 1 + 2 + 4, /* 78, 79, 7a, --, --, --, --, --, */
468 }; 418 };
419 int i, j;
420
469 for (; *s; s++) { 421 for (; *s; s++) {
470 if (minimal_ascii_table[*s & 0x7F] != *s) 422 i = *s >> 3; /* i = *s / 8; */
471 return -1; /* failed */ 423 j = 1 << (*s & 3); /* j = 1 << (*s % 8); */
424
425 if (i >= ARRAY_SIZE(minimal_ascii_table) ||
426 !(minimal_ascii_table[i] & j))
427 return -EINVAL;
472 } 428 }
473 /* String conforms to minimal-ascii, as specified by IEEE 1212,
474 * par. 7.4 */
475 return 0; 429 return 0;
476} 430}
477 431
432/* IEEE 1212 clause 7.5.4.1 textual descriptors (English, minimal ASCII) */
478struct csr1212_keyval *csr1212_new_string_descriptor_leaf(const char *s) 433struct csr1212_keyval *csr1212_new_string_descriptor_leaf(const char *s)
479{ 434{
480 /* Check if string conform to minimal_ascii format */ 435 struct csr1212_keyval *kv;
481 if (csr1212_check_minimal_ascii(s)) 436 u32 *text;
437 size_t str_len, quads;
438
439 if (!s || !*s || csr1212_check_minimal_ascii(s))
440 return NULL;
441
442 str_len = strlen(s);
443 quads = bytes_to_quads(str_len);
444 kv = csr1212_new_descriptor_leaf(0, 0, NULL, quads_to_bytes(quads) +
445 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_OVERHEAD);
446 if (!kv)
482 return NULL; 447 return NULL;
483 448
484 /* IEEE 1212, par. 7.5.4.1 Textual descriptors (minimal ASCII) */ 449 kv->value.leaf.data[1] = 0; /* width, character_set, language */
485 return csr1212_new_textual_descriptor_leaf(0, 0, 0, s, strlen(s)); 450 text = CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(kv);
451 text[quads - 1] = 0; /* padding */
452 memcpy(text, s, str_len);
453
454 return kv;
486} 455}
487 456
488 457