70 pdu = gw_malloc(
sizeof(*pdu));
75 #define PDU(name, docstring, fields, is_valid) \ 77 struct name *p; p = &pdu->u.name; \ 80 #define UINT(field, docstring, bits) p->field = 0; 81 #define UINTVAR(field, docstring) p->field = 0; 82 #define OCTSTR(field, docstring, lengthfield) p->field = NULL; 83 #define REST(field, docstring) p->field = NULL; 84 #define TYPE(bits, value) 85 #define RESERVED(bits) 97 warning(0,
"Cannot create unknown WTP PDU type %d", pdu->
type);
109 #define PDU(name, docstring, fields, is_valid) \ 111 struct name *p; p = &pdu->u.name; \ 114 #define UINT(field, docstring, bits) 115 #define UINTVAR(field, docstring) 116 #define OCTSTR(field, docstring, lengthfield) octstr_destroy(p->field); 117 #define REST(field, docstring) octstr_destroy(p->field); 118 #define TYPE(bits, value) 119 #define RESERVED(bits) 120 #define TPI(confield) 131 warning(0,
"Cannot destroy unknown WTP PDU type %d", pdu->
type);
156 tpi = gw_malloc(
sizeof(*tpi));
184 bitpos += 8 * length;
198 for (i = 0; i < num_tpis; i++) {
216 bitpos += 8 * length;
231 for (i = 0; i < num_tpis; i++) {
233 debug(
"wap.wtp", 0,
"%*s TPI type %u:", level,
"", tpi->
type);
243 long lastnumbits = -1;
253 #define PDU(name, docstring, fields, is_valid) \ 257 #define UINT(field, docstring, bits) bitpos += (bits); 258 #define UINTVAR(field, docstring) 259 #define OCTSTR(field, docstring, lengthfield) 260 #define REST(field, docstring) 261 #define TYPE(bits, value) \ 262 if ((bits) != lastnumbits || bitpos != lastpos) { \ 263 lastval = octstr_get_bits(data, bitpos, (bits)); \ 265 if (lastval == (value)) \ 267 lastnumbits = (bits); \ 269 #define RESERVED(bits) bitpos += (bits); 270 #define TPI(confield) 290 pdu = gw_malloc(
sizeof(*pdu));
296 #define PDU(name, docstring, fields, is_valid) \ 298 struct name *p = &pdu->u.name; \ 300 gw_assert(bitpos % 8 == 0); \ 301 if (bitpos / 8 != octstr_len(data)) { \ 302 warning(0, "Bad length for " #name " PDU, " \ 303 "expected %ld", bitpos / 8); \ 306 warning(0, #name " PDU failed %s", #is_valid); \ 310 #define UINT(field, docstring, bits) \ 311 p->field = octstr_get_bits(data, bitpos, (bits)); \ 313 #define UINTVAR(field, docstring) \ 314 gw_assert(bitpos % 8 == 0); \ 315 p->field = octstr_get_bits(data, bitpos + 1, 7); \ 316 while (octstr_get_bits(data, bitpos, 1)) { \ 319 p->field |= octstr_get_bits(data, bitpos + 1, 7); \ 322 #define OCTSTR(field, docstring, lengthfield) \ 323 gw_assert(bitpos % 8 == 0); \ 324 p->field = octstr_copy(data, bitpos / 8, p->lengthfield); \ 325 bitpos += 8 * p->lengthfield; 326 #define REST(field, docstring) \ 327 gw_assert(bitpos % 8 == 0); \ 328 if (bitpos / 8 <= octstr_len(data)) { \ 329 p->field = octstr_copy(data, bitpos / 8, \ 330 octstr_len(data) - bitpos / 8); \ 331 bitpos = octstr_len(data) * 8; \ 333 p->field = octstr_create(""); \ 335 #define TYPE(bits, value) bitpos += (bits); 336 #define RESERVED(bits) bitpos += (bits); 337 #define TPI(confield) \ 339 pdu->options = gwlist_create(); \ 340 bitpos = unpack_tpis(data, bitpos, pdu); \ 352 warning(0,
"WTP PDU with unknown type %d", pdu->
type);
362 #define PDU(name, docstring, fields, is_valid) \ 364 struct name *p = &pdu->u.name; \ 367 #define UINT(field, docstring, bits) 368 #define UINTVAR(field, docstring) 369 #define OCTSTR(field, docstring, lengthfield) \ 370 p->lengthfield = octstr_len(p->field); 371 #define REST(field, docstring) 372 #define TYPE(bits, value) 373 #define RESERVED(bits) 374 #define TPI(confield) \ 375 p->confield = pdu->options != NULL && gwlist_len(pdu->options) > 0; 399 #define PDU(name, docstring, fields, is_valid) \ 401 struct name *p = &pdu->u.name; \ 403 gw_assert(bitpos % 8 == 0); \ 405 #define UINT(field, docstring, bits) \ 406 octstr_set_bits(data, bitpos, (bits), p->field); \ 408 #define UINTVAR(field, docstring) \ 409 gw_assert(bitpos % 8 == 0); \ 410 octstr_append_uintvar(data, p->field); \ 411 bitpos = 8 * octstr_len(data); 412 #define OCTSTR(field, docstring, lengthfield) \ 413 gw_assert(bitpos % 8 == 0); \ 414 if (p->field != NULL) \ 415 octstr_append(data, p->field); \ 416 bitpos += 8 * octstr_len(p->field); 417 #define REST(field, docstring) \ 418 gw_assert(bitpos % 8 == 0); \ 419 if (p->field != NULL) \ 420 octstr_append(data, p->field); \ 421 bitpos += 8 * octstr_len(p->field); 422 #define TYPE(bits, value) \ 423 octstr_set_bits(data, bitpos, (bits), (value)); \ 425 #define RESERVED(bits) bitpos += (bits); 426 #define TPI(confield) \ 428 bitpos = pack_tpis(data, bitpos, pdu->options); \ 440 panic(0,
"Packing unknown WTP PDU type %ld", (
long) pdu->
type);
447 char *dbg =
"wap.wtp";
450 #define PDU(name, docstring, fields, is_valid) \ 452 struct name *p = &pdu->u.name; \ 453 debug(dbg, 0, "%*sWTP %s PDU at %p:", \ 454 level, "", #name, (void *)pdu); \ 457 #define UINT(field, docstring, bits) \ 458 debug(dbg, 0, "%*s %s: %lu", level, "", docstring, p->field); 459 #define UINTVAR(field, docstring) \ 460 debug(dbg, 0, "%*s %s: %lu", level, "", docstring, p->field); 461 #define OCTSTR(field, docstring, lengthfield) \ 462 debug(dbg, 0, "%*s %s:", level, "", docstring); \ 463 octstr_dump(p->field, level + 1); 464 #define REST(field, docstring) \ 465 debug(dbg, 0, "%*s %s:", level, "", docstring); \ 466 octstr_dump(p->field, level + 1); 467 #define TYPE(bits, value) 468 #define RESERVED(bits) 469 #define TPI(confield) dump_tpis(pdu->options, level); 480 debug(dbg, 0,
"%*sWTP PDU at %p:", level,
"", (
void *)pdu);
481 debug(dbg, 0,
"%*s unknown type %u", level,
"", pdu->type);
WTP_PDU * wtp_pdu_create(int type)
void wtp_pdu_append_tpi(WTP_PDU *pdu, int type, Octstr *data)
gw_assert(wtls_machine->packet_to_send !=NULL)
void gwlist_append(List *list, void *item)
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
void wtp_tpi_destroy(WTP_TPI *p)
long gwlist_len(List *list)
void * gwlist_get(List *list, long pos)
void octstr_set_bits(Octstr *ostr, long bitpos, int numbits, unsigned long value)
void wtp_pdu_dump(WTP_PDU *pdu, int level)
#define octstr_copy(ostr, from, len)
static void dump_tpis(List *tpis, int level)
static int wtp_pdu_type(Octstr *data)
long octstr_get_bits(Octstr *ostr, long bitpos, int numbits)
static long unpack_tpis(Octstr *data, long bitpos, WTP_PDU *pdu)
static long pack_tpis(Octstr *data, long bitpos, List *tpis)
static void fixup_length_fields(WTP_PDU *pdu)
#define octstr_dump(ostr, level,...)
WTP_PDU * wtp_pdu_unpack(Octstr *data)
void warning(int err, const char *fmt,...)
void octstr_destroy(Octstr *ostr)
#define octstr_create(cstr)
long octstr_len(const Octstr *ostr)
void * gwlist_consume(List *list)
void debug(const char *place, int err, const char *fmt,...)
Octstr * wtp_pdu_pack(WTP_PDU *pdu)
void wtp_pdu_destroy(WTP_PDU *pdu)
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)