ncm.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * USB CDC NCM auxiliary definitions
  3. */
  4. #ifndef __LINUX_USB_NCM_H
  5. #define __LINUX_USB_NCM_H
  6. #include <linux/types.h>
  7. #include <linux/usb/cdc.h>
  8. #include <asm/unaligned.h>
  9. #define NCM_NTB_MIN_IN_SIZE 2048
  10. #define NCM_NTB_MIN_OUT_SIZE 2048
  11. #define NCM_CONTROL_TIMEOUT (5 * 1000)
  12. /* bmNetworkCapabilities */
  13. #define NCM_NCAP_ETH_FILTER (1 << 0)
  14. #define NCM_NCAP_NET_ADDRESS (1 << 1)
  15. #define NCM_NCAP_ENCAP_COMM (1 << 2)
  16. #define NCM_NCAP_MAX_DGRAM (1 << 3)
  17. #define NCM_NCAP_CRC_MODE (1 << 4)
  18. /*
  19. * Here are options for NCM Datagram Pointer table (NDP) parser.
  20. * There are 2 different formats: NDP16 and NDP32 in the spec (ch. 3),
  21. * in NDP16 offsets and sizes fields are 1 16bit word wide,
  22. * in NDP32 -- 2 16bit words wide. Also signatures are different.
  23. * To make the parser code the same, put the differences in the structure,
  24. * and switch pointers to the structures when the format is changed.
  25. */
  26. struct ndp_parser_opts {
  27. u32 nth_sign;
  28. u32 ndp_sign;
  29. unsigned nth_size;
  30. unsigned ndp_size;
  31. unsigned ndplen_align;
  32. /* sizes in u16 units */
  33. unsigned dgram_item_len; /* index or length */
  34. unsigned block_length;
  35. unsigned fp_index;
  36. unsigned reserved1;
  37. unsigned reserved2;
  38. unsigned next_fp_index;
  39. };
  40. #define INIT_NDP16_OPTS { \
  41. .nth_sign = NCM_NTH16_SIGN, \
  42. .ndp_sign = NCM_NDP16_NOCRC_SIGN, \
  43. .nth_size = sizeof(struct usb_cdc_ncm_nth16), \
  44. .ndp_size = sizeof(struct usb_cdc_ncm_ndp16), \
  45. .ndplen_align = 4, \
  46. .dgram_item_len = 1, \
  47. .block_length = 1, \
  48. .fp_index = 1, \
  49. .reserved1 = 0, \
  50. .reserved2 = 0, \
  51. .next_fp_index = 1, \
  52. }
  53. #define INIT_NDP32_OPTS { \
  54. .nth_sign = NCM_NTH32_SIGN, \
  55. .ndp_sign = NCM_NDP32_NOCRC_SIGN, \
  56. .nth_size = sizeof(struct usb_cdc_ncm_nth32), \
  57. .ndp_size = sizeof(struct usb_cdc_ncm_ndp32), \
  58. .ndplen_align = 8, \
  59. .dgram_item_len = 2, \
  60. .block_length = 2, \
  61. .fp_index = 2, \
  62. .reserved1 = 1, \
  63. .reserved2 = 2, \
  64. .next_fp_index = 2, \
  65. }
  66. static inline void put_ncm(__le16 **p, unsigned size, unsigned val)
  67. {
  68. switch (size) {
  69. case 1:
  70. put_unaligned_le16((u16)val, *p);
  71. break;
  72. case 2:
  73. put_unaligned_le32((u32)val, *p);
  74. break;
  75. default:
  76. BUG();
  77. }
  78. *p += size;
  79. }
  80. static inline unsigned get_ncm(__le16 **p, unsigned size)
  81. {
  82. unsigned tmp;
  83. switch (size) {
  84. case 1:
  85. tmp = get_unaligned_le16(*p);
  86. break;
  87. case 2:
  88. tmp = get_unaligned_le32(*p);
  89. break;
  90. default:
  91. BUG();
  92. }
  93. *p += size;
  94. return tmp;
  95. }
  96. #endif /* __LINUX_USB_NCM_H */