tbfcp_attr.h 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (C) 2014 Mamadou DIOP.
  2. *
  3. * This file is part of Open Source Doubango Framework.
  4. *
  5. * DOUBANGO is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * DOUBANGO is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with DOUBANGO.
  17. *
  18. */
  19. #ifndef TBFCP_ATTR_H
  20. #define TBFCP_ATTR_H
  21. #include "tinybfcp_config.h"
  22. #include "tinybfcp/tbfcp_types.h"
  23. #include "tsk_object.h"
  24. #include "tsk_list.h"
  25. TBFCP_BEGIN_DECLS
  26. #if !defined(TBFCP_ATTR_HDR_SIZE_IN_OCTETS)
  27. # define TBFCP_ATTR_HDR_SIZE_IN_OCTETS 2 /* 2 Octets: Type(7bits),M(1bit),Length(8bits) */
  28. #endif /* TBFCP_ATTR_HDR_SIZE_IN_OCTETS */
  29. // RFC4582 - 5.2. Attribute Format
  30. typedef struct tbfcp_attr_hdr_xs {
  31. enum tbfcp_attribute_type_e type; // 7bits
  32. unsigned M:1; // Mandatory // 1bit
  33. uint8_t length; // 8bits excluding any padding defined for specific attributes
  34. } tbfcp_attr_hdr_xt;
  35. typedef struct tbfcp_attr_s {
  36. TSK_DECLARE_OBJECT;
  37. struct tbfcp_attr_s* pc_base;
  38. struct tbfcp_attr_hdr_xs hdr;
  39. enum tbfcp_attribute_format_e format;
  40. } tbfcp_attr_t;
  41. #define TBFCP_DECLARE_ATTR struct tbfcp_attr_s __base__
  42. #define TBFCP_ATTR(p_self) ((struct tbfcp_attr_s*)(p_self))
  43. typedef tsk_list_t tbfcp_attrs_L_t;
  44. TINYBFCP_API int tbfcp_attr_get_size_in_octetunits_without_padding(const struct tbfcp_attr_s* pc_self, tsk_size_t* p_size);
  45. TINYBFCP_API int tbfcp_attr_get_size_in_octetunits_with_padding(const struct tbfcp_attr_s* pc_self, tsk_size_t* p_size);
  46. TINYBFCP_API int tbfcp_attr_write_without_padding(const struct tbfcp_attr_s* pc_self, uint8_t* p_buff_ptr, tsk_size_t n_buff_size, tsk_size_t *p_written);
  47. TINYBFCP_API int tbfcp_attr_write_with_padding(const struct tbfcp_attr_s* pc_self, uint8_t* p_buff_ptr, tsk_size_t n_buff_size, tsk_size_t *p_written);
  48. TINYBFCP_API int tbfcp_attr_read(const uint8_t* pc_buff_ptr, tsk_size_t n_buff_size, tsk_size_t *p_consumed_octets, struct tbfcp_attr_s** pp_attr);
  49. typedef struct tbfcp_attr_unsigned16_s {
  50. TBFCP_DECLARE_ATTR;
  51. uint16_t Unsigned16;
  52. } tbfcp_attr_unsigned16_t;
  53. #define TBFCP_ATTR_UNSIGNED16(p_self) ((struct tbfcp_attr_unsigned16_s*)(p_self))
  54. TINYBFCP_API int tbfcp_attr_unsigned16_create(enum tbfcp_attribute_type_e type, unsigned M, uint16_t Unsigned16, struct tbfcp_attr_unsigned16_s** pp_self);
  55. typedef struct tbfcp_attr_octetstring16_s {
  56. TBFCP_DECLARE_ATTR;
  57. uint8_t OctetString16[2];
  58. } tbfcp_attr_octetstring16_t;
  59. #define TBFCP_ATTR_OCTETSTRING16(p_self) ((struct tbfcp_attr_octetstring16_s*)(p_self))
  60. TINYBFCP_API int tbfcp_attr_octetstring16_create(enum tbfcp_attribute_type_e type, unsigned M, uint8_t OctetString16[2], struct tbfcp_attr_octetstring16_s** pp_self);
  61. typedef struct tbfcp_attr_octetstring_s {
  62. TBFCP_DECLARE_ATTR;
  63. uint8_t *OctetString;
  64. uint8_t OctetStringLength; // Length in octet excluding any paddding
  65. } tbfcp_attr_octetstring_t;
  66. #define TBFCP_ATTR_OCTETSTRING(p_self) ((struct tbfcp_attr_octetstring_s*)(p_self))
  67. TINYBFCP_API int tbfcp_attr_octetstring_create(enum tbfcp_attribute_type_e type, unsigned M, const uint8_t *OctetString, uint8_t OctetStringLength, struct tbfcp_attr_octetstring_s** pp_self);
  68. typedef struct tbfcp_attr_grouped_s {
  69. TBFCP_DECLARE_ATTR;
  70. union {
  71. uint16_t BeneficiaryID; // 5.2.14. BENEFICIARY-INFORMATION
  72. uint16_t FloorRequestID; // 5.2.15. FLOOR-REQUEST-INFORMATION && 5.2.18. OVERALL-REQUEST-STATUS
  73. uint16_t RequestedbyID; // 5.2.16. REQUESTED-BY-INFORMATION
  74. uint16_t FloorID; // 5.2.17. FLOOR-REQUEST-STATUS
  75. } extra_hdr;
  76. uint8_t extra_hdr_size_in_octets;
  77. tbfcp_attrs_L_t *p_list_attrs;
  78. } tbfcp_attr_grouped_t;
  79. #define TBFCP_ATTR_GROUPED(p_self) ((struct tbfcp_attr_grouped_s*)(p_self))
  80. TINYBFCP_API int tbfcp_attr_grouped_create(enum tbfcp_attribute_type_e type, unsigned M, struct tbfcp_attr_grouped_s** pp_self);
  81. TINYBFCP_API int tbfcp_attr_grouped_create_u16(enum tbfcp_attribute_type_e type, unsigned M, uint16_t extra_hdr_u16_val, struct tbfcp_attr_grouped_s** pp_self);
  82. TINYBFCP_API int tbfcp_attr_grouped_add_attr(struct tbfcp_attr_grouped_s* p_self, struct tbfcp_attr_s** p_attr);
  83. TINYBFCP_API int tbfcp_attr_grouped_find_at(const struct tbfcp_attr_grouped_s* pc_self, enum tbfcp_attribute_format_e e_format, tsk_size_t u_index, const struct tbfcp_attr_s** ppc_attr);
  84. TBFCP_END_DECLS
  85. #endif /* TBFCP_ATTR_H */