|
wpa_supplicant / hostapd 2.0
|
00001 00010 #ifndef WPABUF_H 00011 #define WPABUF_H 00012 00013 /* 00014 * Internal data structure for wpabuf. Please do not touch this directly from 00015 * elsewhere. This is only defined in header file to allow inline functions 00016 * from this file to access data. 00017 */ 00018 struct wpabuf { 00019 size_t size; /* total size of the allocated buffer */ 00020 size_t used; /* length of data in the buffer */ 00021 u8 *ext_data; /* pointer to external data; NULL if data follows 00022 * struct wpabuf */ 00023 /* optionally followed by the allocated buffer */ 00024 }; 00025 00026 00027 int wpabuf_resize(struct wpabuf **buf, size_t add_len); 00028 struct wpabuf * wpabuf_alloc(size_t len); 00029 struct wpabuf * wpabuf_alloc_ext_data(u8 *data, size_t len); 00030 struct wpabuf * wpabuf_alloc_copy(const void *data, size_t len); 00031 struct wpabuf * wpabuf_dup(const struct wpabuf *src); 00032 void wpabuf_free(struct wpabuf *buf); 00033 void * wpabuf_put(struct wpabuf *buf, size_t len); 00034 struct wpabuf * wpabuf_concat(struct wpabuf *a, struct wpabuf *b); 00035 struct wpabuf * wpabuf_zeropad(struct wpabuf *buf, size_t len); 00036 void wpabuf_printf(struct wpabuf *buf, char *fmt, ...) PRINTF_FORMAT(2, 3); 00037 00038 00045 static inline size_t wpabuf_size(const struct wpabuf *buf) 00046 { 00047 return buf->size; 00048 } 00049 00056 static inline size_t wpabuf_len(const struct wpabuf *buf) 00057 { 00058 return buf->used; 00059 } 00060 00067 static inline size_t wpabuf_tailroom(const struct wpabuf *buf) 00068 { 00069 return buf->size - buf->used; 00070 } 00071 00078 static inline const void * wpabuf_head(const struct wpabuf *buf) 00079 { 00080 if (buf->ext_data) 00081 return buf->ext_data; 00082 return buf + 1; 00083 } 00084 00085 static inline const u8 * wpabuf_head_u8(const struct wpabuf *buf) 00086 { 00087 return wpabuf_head(buf); 00088 } 00089 00096 static inline void * wpabuf_mhead(struct wpabuf *buf) 00097 { 00098 if (buf->ext_data) 00099 return buf->ext_data; 00100 return buf + 1; 00101 } 00102 00103 static inline u8 * wpabuf_mhead_u8(struct wpabuf *buf) 00104 { 00105 return wpabuf_mhead(buf); 00106 } 00107 00108 static inline void wpabuf_put_u8(struct wpabuf *buf, u8 data) 00109 { 00110 u8 *pos = wpabuf_put(buf, 1); 00111 *pos = data; 00112 } 00113 00114 static inline void wpabuf_put_le16(struct wpabuf *buf, u16 data) 00115 { 00116 u8 *pos = wpabuf_put(buf, 2); 00117 WPA_PUT_LE16(pos, data); 00118 } 00119 00120 static inline void wpabuf_put_le32(struct wpabuf *buf, u32 data) 00121 { 00122 u8 *pos = wpabuf_put(buf, 4); 00123 WPA_PUT_LE32(pos, data); 00124 } 00125 00126 static inline void wpabuf_put_be16(struct wpabuf *buf, u16 data) 00127 { 00128 u8 *pos = wpabuf_put(buf, 2); 00129 WPA_PUT_BE16(pos, data); 00130 } 00131 00132 static inline void wpabuf_put_be24(struct wpabuf *buf, u32 data) 00133 { 00134 u8 *pos = wpabuf_put(buf, 3); 00135 WPA_PUT_BE24(pos, data); 00136 } 00137 00138 static inline void wpabuf_put_be32(struct wpabuf *buf, u32 data) 00139 { 00140 u8 *pos = wpabuf_put(buf, 4); 00141 WPA_PUT_BE32(pos, data); 00142 } 00143 00144 static inline void wpabuf_put_data(struct wpabuf *buf, const void *data, 00145 size_t len) 00146 { 00147 if (data) 00148 os_memcpy(wpabuf_put(buf, len), data, len); 00149 } 00150 00151 static inline void wpabuf_put_buf(struct wpabuf *dst, 00152 const struct wpabuf *src) 00153 { 00154 wpabuf_put_data(dst, wpabuf_head(src), wpabuf_len(src)); 00155 } 00156 00157 static inline void wpabuf_set(struct wpabuf *buf, const void *data, size_t len) 00158 { 00159 buf->ext_data = (u8 *) data; 00160 buf->size = buf->used = len; 00161 } 00162 00163 static inline void wpabuf_put_str(struct wpabuf *dst, const char *str) 00164 { 00165 wpabuf_put_data(dst, str, os_strlen(str)); 00166 } 00167 00168 #endif /* WPABUF_H */ 00169
1.7.3