Lines Matching refs:msg
52 struct radius_hdr * radius_msg_get_hdr(struct radius_msg *msg) in radius_msg_get_hdr() argument
54 return msg->hdr; in radius_msg_get_hdr()
58 struct wpabuf * radius_msg_get_buf(struct radius_msg *msg) in radius_msg_get_buf() argument
60 return msg->buf; in radius_msg_get_buf()
65 radius_get_attr_hdr(struct radius_msg *msg, int idx) in radius_get_attr_hdr() argument
68 (wpabuf_mhead_u8(msg->buf) + msg->attr_pos[idx]); in radius_get_attr_hdr()
72 static void radius_msg_set_hdr(struct radius_msg *msg, u8 code, u8 identifier) in radius_msg_set_hdr() argument
74 msg->hdr->code = code; in radius_msg_set_hdr()
75 msg->hdr->identifier = identifier; in radius_msg_set_hdr()
79 static int radius_msg_initialize(struct radius_msg *msg) in radius_msg_initialize() argument
81 msg->attr_pos = os_calloc(RADIUS_DEFAULT_ATTR_COUNT, in radius_msg_initialize()
82 sizeof(*msg->attr_pos)); in radius_msg_initialize()
83 if (msg->attr_pos == NULL) in radius_msg_initialize()
86 msg->attr_size = RADIUS_DEFAULT_ATTR_COUNT; in radius_msg_initialize()
87 msg->attr_used = 0; in radius_msg_initialize()
104 struct radius_msg *msg; in radius_msg_new() local
106 msg = os_zalloc(sizeof(*msg)); in radius_msg_new()
107 if (msg == NULL) in radius_msg_new()
110 msg->buf = wpabuf_alloc(RADIUS_DEFAULT_MSG_SIZE); in radius_msg_new()
111 if (msg->buf == NULL || radius_msg_initialize(msg)) { in radius_msg_new()
112 radius_msg_free(msg); in radius_msg_new()
115 msg->hdr = wpabuf_put(msg->buf, sizeof(struct radius_hdr)); in radius_msg_new()
117 radius_msg_set_hdr(msg, code, identifier); in radius_msg_new()
119 return msg; in radius_msg_new()
127 void radius_msg_free(struct radius_msg *msg) in radius_msg_free() argument
129 if (msg == NULL) in radius_msg_free()
132 wpabuf_free(msg->buf); in radius_msg_free()
133 os_free(msg->attr_pos); in radius_msg_free()
134 os_free(msg); in radius_msg_free()
350 void radius_msg_dump(struct radius_msg *msg) in radius_msg_dump() argument
355 msg->hdr->code, radius_code_string(msg->hdr->code), in radius_msg_dump()
356 msg->hdr->identifier, be_to_host16(msg->hdr->length)); in radius_msg_dump()
358 for (i = 0; i < msg->attr_used; i++) { in radius_msg_dump()
359 struct radius_attr_hdr *attr = radius_get_attr_hdr(msg, i); in radius_msg_dump()
365 int radius_msg_finish(struct radius_msg *msg, const u8 *secret, in radius_msg_finish() argument
373 attr = radius_msg_add_attr(msg, in radius_msg_finish()
381 msg->hdr->length = host_to_be16(wpabuf_len(msg->buf)); in radius_msg_finish()
382 hmac_md5(secret, secret_len, wpabuf_head(msg->buf), in radius_msg_finish()
383 wpabuf_len(msg->buf), (u8 *) (attr + 1)); in radius_msg_finish()
385 msg->hdr->length = host_to_be16(wpabuf_len(msg->buf)); in radius_msg_finish()
387 if (wpabuf_len(msg->buf) > 0xffff) { in radius_msg_finish()
389 (unsigned long) wpabuf_len(msg->buf)); in radius_msg_finish()
396 int radius_msg_finish_srv(struct radius_msg *msg, const u8 *secret, in radius_msg_finish_srv() argument
405 attr = radius_msg_add_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, in radius_msg_finish_srv()
411 msg->hdr->length = host_to_be16(wpabuf_len(msg->buf)); in radius_msg_finish_srv()
412 os_memcpy(msg->hdr->authenticator, req_authenticator, in radius_msg_finish_srv()
413 sizeof(msg->hdr->authenticator)); in radius_msg_finish_srv()
414 hmac_md5(secret, secret_len, wpabuf_head(msg->buf), in radius_msg_finish_srv()
415 wpabuf_len(msg->buf), (u8 *) (attr + 1)); in radius_msg_finish_srv()
418 addr[0] = (u8 *) msg->hdr; in radius_msg_finish_srv()
422 addr[2] = wpabuf_head_u8(msg->buf) + sizeof(struct radius_hdr); in radius_msg_finish_srv()
423 len[2] = wpabuf_len(msg->buf) - sizeof(struct radius_hdr); in radius_msg_finish_srv()
426 md5_vector(4, addr, len, msg->hdr->authenticator); in radius_msg_finish_srv()
428 if (wpabuf_len(msg->buf) > 0xffff) { in radius_msg_finish_srv()
430 (unsigned long) wpabuf_len(msg->buf)); in radius_msg_finish_srv()
437 int radius_msg_finish_das_resp(struct radius_msg *msg, const u8 *secret, in radius_msg_finish_das_resp() argument
447 attr = radius_msg_add_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, in radius_msg_finish_das_resp()
454 msg->hdr->length = host_to_be16(wpabuf_len(msg->buf)); in radius_msg_finish_das_resp()
455 os_memcpy(msg->hdr->authenticator, req_hdr->authenticator, 16); in radius_msg_finish_das_resp()
456 hmac_md5(secret, secret_len, wpabuf_head(msg->buf), in radius_msg_finish_das_resp()
457 wpabuf_len(msg->buf), (u8 *) (attr + 1)); in radius_msg_finish_das_resp()
460 addr[0] = wpabuf_head_u8(msg->buf); in radius_msg_finish_das_resp()
461 len[0] = wpabuf_len(msg->buf); in radius_msg_finish_das_resp()
464 if (md5_vector(2, addr, len, msg->hdr->authenticator) < 0) in radius_msg_finish_das_resp()
467 if (wpabuf_len(msg->buf) > 0xffff) { in radius_msg_finish_das_resp()
469 (unsigned long) wpabuf_len(msg->buf)); in radius_msg_finish_das_resp()
476 void radius_msg_finish_acct(struct radius_msg *msg, const u8 *secret, in radius_msg_finish_acct() argument
482 msg->hdr->length = host_to_be16(wpabuf_len(msg->buf)); in radius_msg_finish_acct()
483 os_memset(msg->hdr->authenticator, 0, MD5_MAC_LEN); in radius_msg_finish_acct()
484 addr[0] = wpabuf_head(msg->buf); in radius_msg_finish_acct()
485 len[0] = wpabuf_len(msg->buf); in radius_msg_finish_acct()
488 md5_vector(2, addr, len, msg->hdr->authenticator); in radius_msg_finish_acct()
490 if (wpabuf_len(msg->buf) > 0xffff) { in radius_msg_finish_acct()
492 (unsigned long) wpabuf_len(msg->buf)); in radius_msg_finish_acct()
497 void radius_msg_finish_acct_resp(struct radius_msg *msg, const u8 *secret, in radius_msg_finish_acct_resp() argument
503 msg->hdr->length = host_to_be16(wpabuf_len(msg->buf)); in radius_msg_finish_acct_resp()
504 os_memcpy(msg->hdr->authenticator, req_authenticator, MD5_MAC_LEN); in radius_msg_finish_acct_resp()
505 addr[0] = wpabuf_head(msg->buf); in radius_msg_finish_acct_resp()
506 len[0] = wpabuf_len(msg->buf); in radius_msg_finish_acct_resp()
509 md5_vector(2, addr, len, msg->hdr->authenticator); in radius_msg_finish_acct_resp()
511 if (wpabuf_len(msg->buf) > 0xffff) { in radius_msg_finish_acct_resp()
513 (unsigned long) wpabuf_len(msg->buf)); in radius_msg_finish_acct_resp()
518 int radius_msg_verify_acct_req(struct radius_msg *msg, const u8 *secret, in radius_msg_verify_acct_req() argument
527 addr[0] = (u8 *) msg->hdr; in radius_msg_verify_acct_req()
531 addr[2] = (u8 *) (msg->hdr + 1); in radius_msg_verify_acct_req()
532 len[2] = wpabuf_len(msg->buf) - sizeof(struct radius_hdr); in radius_msg_verify_acct_req()
536 return os_memcmp_const(msg->hdr->authenticator, hash, MD5_MAC_LEN) != 0; in radius_msg_verify_acct_req()
540 int radius_msg_verify_das_req(struct radius_msg *msg, const u8 *secret, in radius_msg_verify_das_req() argument
555 addr[0] = (u8 *) msg->hdr; in radius_msg_verify_das_req()
559 addr[2] = (u8 *) (msg->hdr + 1); in radius_msg_verify_das_req()
560 len[2] = wpabuf_len(msg->buf) - sizeof(struct radius_hdr); in radius_msg_verify_das_req()
564 if (os_memcmp_const(msg->hdr->authenticator, hash, MD5_MAC_LEN) != 0) in radius_msg_verify_das_req()
567 for (i = 0; i < msg->attr_used; i++) { in radius_msg_verify_das_req()
568 tmp = radius_get_attr_hdr(msg, i); in radius_msg_verify_das_req()
591 os_memcpy(orig_authenticator, msg->hdr->authenticator, in radius_msg_verify_das_req()
593 os_memset(msg->hdr->authenticator, 0, in radius_msg_verify_das_req()
594 sizeof(msg->hdr->authenticator)); in radius_msg_verify_das_req()
595 hmac_md5(secret, secret_len, wpabuf_head(msg->buf), in radius_msg_verify_das_req()
596 wpabuf_len(msg->buf), auth); in radius_msg_verify_das_req()
598 os_memcpy(msg->hdr->authenticator, orig_authenticator, in radius_msg_verify_das_req()
605 static int radius_msg_add_attr_to_array(struct radius_msg *msg, in radius_msg_add_attr_to_array() argument
608 if (msg->attr_used >= msg->attr_size) { in radius_msg_add_attr_to_array()
610 int nlen = msg->attr_size * 2; in radius_msg_add_attr_to_array()
612 nattr_pos = os_realloc_array(msg->attr_pos, nlen, in radius_msg_add_attr_to_array()
613 sizeof(*msg->attr_pos)); in radius_msg_add_attr_to_array()
617 msg->attr_pos = nattr_pos; in radius_msg_add_attr_to_array()
618 msg->attr_size = nlen; in radius_msg_add_attr_to_array()
621 msg->attr_pos[msg->attr_used++] = in radius_msg_add_attr_to_array()
622 (unsigned char *) attr - wpabuf_head_u8(msg->buf); in radius_msg_add_attr_to_array()
628 struct radius_attr_hdr *radius_msg_add_attr(struct radius_msg *msg, u8 type, in radius_msg_add_attr() argument
642 if (wpabuf_tailroom(msg->buf) < buf_needed) { in radius_msg_add_attr()
644 if (wpabuf_resize(&msg->buf, buf_needed) < 0) in radius_msg_add_attr()
646 msg->hdr = wpabuf_mhead(msg->buf); in radius_msg_add_attr()
649 attr = wpabuf_put(msg->buf, sizeof(struct radius_attr_hdr)); in radius_msg_add_attr()
652 wpabuf_put_data(msg->buf, data, data_len); in radius_msg_add_attr()
654 if (radius_msg_add_attr_to_array(msg, attr)) in radius_msg_add_attr()
672 struct radius_msg *msg; in radius_msg_parse() local
694 msg = os_zalloc(sizeof(*msg)); in radius_msg_parse()
695 if (msg == NULL) in radius_msg_parse()
698 msg->buf = wpabuf_alloc_copy(data, msg_len); in radius_msg_parse()
699 if (msg->buf == NULL || radius_msg_initialize(msg)) { in radius_msg_parse()
700 radius_msg_free(msg); in radius_msg_parse()
703 msg->hdr = wpabuf_mhead(msg->buf); in radius_msg_parse()
706 pos = wpabuf_mhead_u8(msg->buf) + sizeof(struct radius_hdr); in radius_msg_parse()
707 end = wpabuf_mhead_u8(msg->buf) + wpabuf_len(msg->buf); in radius_msg_parse()
719 if (radius_msg_add_attr_to_array(msg, attr)) in radius_msg_parse()
725 return msg; in radius_msg_parse()
728 radius_msg_free(msg); in radius_msg_parse()
733 int radius_msg_add_eap(struct radius_msg *msg, const u8 *data, size_t data_len) in radius_msg_add_eap() argument
745 if (!radius_msg_add_attr(msg, RADIUS_ATTR_EAP_MESSAGE, in radius_msg_add_eap()
757 struct wpabuf * radius_msg_get_eap(struct radius_msg *msg) in radius_msg_get_eap() argument
763 if (msg == NULL) in radius_msg_get_eap()
767 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_eap()
768 attr = radius_get_attr_hdr(msg, i); in radius_msg_get_eap()
781 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_eap()
782 attr = radius_get_attr_hdr(msg, i); in radius_msg_get_eap()
794 int radius_msg_verify_msg_auth(struct radius_msg *msg, const u8 *secret, in radius_msg_verify_msg_auth() argument
802 for (i = 0; i < msg->attr_used; i++) { in radius_msg_verify_msg_auth()
803 tmp = radius_get_attr_hdr(msg, i); in radius_msg_verify_msg_auth()
821 os_memcpy(orig_authenticator, msg->hdr->authenticator, in radius_msg_verify_msg_auth()
823 os_memcpy(msg->hdr->authenticator, req_auth, in radius_msg_verify_msg_auth()
824 sizeof(msg->hdr->authenticator)); in radius_msg_verify_msg_auth()
826 if (hmac_md5(secret, secret_len, wpabuf_head(msg->buf), in radius_msg_verify_msg_auth()
827 wpabuf_len(msg->buf), auth) < 0) in radius_msg_verify_msg_auth()
831 os_memcpy(msg->hdr->authenticator, orig_authenticator, in radius_msg_verify_msg_auth()
844 int radius_msg_verify(struct radius_msg *msg, const u8 *secret, in radius_msg_verify() argument
857 radius_msg_verify_msg_auth(msg, secret, secret_len, in radius_msg_verify()
863 addr[0] = (u8 *) msg->hdr; in radius_msg_verify()
867 addr[2] = wpabuf_head_u8(msg->buf) + sizeof(struct radius_hdr); in radius_msg_verify()
868 len[2] = wpabuf_len(msg->buf) - sizeof(struct radius_hdr); in radius_msg_verify()
872 os_memcmp_const(hash, msg->hdr->authenticator, MD5_MAC_LEN) != 0) { in radius_msg_verify()
905 int radius_msg_make_authenticator(struct radius_msg *msg) in radius_msg_make_authenticator() argument
907 return os_get_random((u8 *) &msg->hdr->authenticator, in radius_msg_make_authenticator()
908 sizeof(msg->hdr->authenticator)); in radius_msg_make_authenticator()
918 static u8 *radius_msg_get_vendor_attr(struct radius_msg *msg, u32 vendor, in radius_msg_get_vendor_attr() argument
924 if (msg == NULL) in radius_msg_get_vendor_attr()
927 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_vendor_attr()
928 struct radius_attr_hdr *attr = radius_get_attr_hdr(msg, i); in radius_msg_get_vendor_attr()
1105 radius_msg_get_ms_keys(struct radius_msg *msg, struct radius_msg *sent_msg, in radius_msg_get_ms_keys() argument
1112 if (msg == NULL || sent_msg == NULL) in radius_msg_get_ms_keys()
1119 key = radius_msg_get_vendor_attr(msg, RADIUS_VENDOR_ID_MICROSOFT, in radius_msg_get_ms_keys()
1134 key = radius_msg_get_vendor_attr(msg, RADIUS_VENDOR_ID_MICROSOFT, in radius_msg_get_ms_keys()
1154 radius_msg_get_cisco_keys(struct radius_msg *msg, struct radius_msg *sent_msg, in radius_msg_get_cisco_keys() argument
1161 if (msg == NULL || sent_msg == NULL) in radius_msg_get_cisco_keys()
1168 key = radius_msg_get_vendor_attr(msg, RADIUS_VENDOR_ID_CISCO, in radius_msg_get_cisco_keys()
1183 int radius_msg_add_mppe_keys(struct radius_msg *msg, in radius_msg_add_mppe_keys() argument
1222 attr = radius_msg_add_attr(msg, RADIUS_ATTR_VENDOR_SPECIFIC, in radius_msg_add_mppe_keys()
1247 attr = radius_msg_add_attr(msg, RADIUS_ATTR_VENDOR_SPECIFIC, in radius_msg_add_mppe_keys()
1258 int radius_msg_add_wfa(struct radius_msg *msg, u8 subtype, const u8 *data, in radius_msg_add_wfa() argument
1275 attr = radius_msg_add_attr(msg, RADIUS_ATTR_VENDOR_SPECIFIC, in radius_msg_add_wfa()
1285 int radius_user_password_hide(struct radius_msg *msg, in radius_user_password_hide() argument
1311 addr[1] = msg->hdr->authenticator; in radius_user_password_hide()
1339 radius_msg_add_attr_user_password(struct radius_msg *msg, in radius_msg_add_attr_user_password() argument
1346 res = radius_user_password_hide(msg, data, data_len, in radius_msg_add_attr_user_password()
1351 return radius_msg_add_attr(msg, RADIUS_ATTR_USER_PASSWORD, in radius_msg_add_attr_user_password()
1356 int radius_msg_get_attr(struct radius_msg *msg, u8 type, u8 *buf, size_t len) in radius_msg_get_attr() argument
1361 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_attr()
1362 tmp = radius_get_attr_hdr(msg, i); in radius_msg_get_attr()
1379 int radius_msg_get_attr_ptr(struct radius_msg *msg, u8 type, u8 **buf, in radius_msg_get_attr_ptr() argument
1385 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_attr_ptr()
1386 tmp = radius_get_attr_hdr(msg, i); in radius_msg_get_attr_ptr()
1403 int radius_msg_count_attr(struct radius_msg *msg, u8 type, int min_len) in radius_msg_count_attr() argument
1408 for (count = 0, i = 0; i < msg->attr_used; i++) { in radius_msg_count_attr()
1409 struct radius_attr_hdr *attr = radius_get_attr_hdr(msg, i); in radius_msg_count_attr()
1449 int radius_msg_get_vlanid(struct radius_msg *msg, int *untagged, int numtagged, in radius_msg_get_vlanid() argument
1465 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_vlanid()
1466 attr = radius_get_attr_hdr(msg, i); in radius_msg_get_vlanid()
1552 char * radius_msg_get_tunnel_password(struct radius_msg *msg, int *keylen, in radius_msg_get_tunnel_password() argument
1573 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_tunnel_password()
1574 attr = radius_get_attr_hdr(msg, i); in radius_msg_get_tunnel_password()
1700 u8 radius_msg_find_unlisted_attr(struct radius_msg *msg, u8 *attrs) in radius_msg_find_unlisted_attr() argument
1705 for (i = 0; i < msg->attr_used; i++) { in radius_msg_find_unlisted_attr()
1706 attr = radius_get_attr_hdr(msg, i); in radius_msg_find_unlisted_attr()