/** * Create and send a Multimedia-Authentication-Request and returns the parsed Answer structure. * This function retrieves authentication vectors from the HSS. * @param msg - the SIP message to send for * @parma public_identity - the public identity of the user * @param private_identity - the private identity of the user * @param count - how many authentication vectors to ask for * @param algorithm - for which algorithm * @param authorization - the authorization value * @param server_name - local name of the S-CSCF to save on the HSS * @returns the parsed maa struct */ int cxdx_send_mar(struct sip_msg *msg, str public_identity, str private_identity, unsigned int count, str algorithm, str authorization, str server_name, saved_transaction_t* transaction_data) { AAAMessage *mar = 0; AAASession *session = 0; session = cdpb.AAACreateSession(0); mar = cdpb.AAACreateRequest(IMS_Cx, IMS_MAR, Flag_Proxyable, session); if (session) { cdpb.AAADropSession(session); session = 0; } if (!mar) goto error1; if (cxdx_dest_host.len > 0) { if (!cxdx_add_destination_host(mar, cxdx_dest_host)) goto error1; } if (!cxdx_add_destination_realm(mar, cxdx_dest_realm)) goto error1; if (!cxdx_add_vendor_specific_appid(mar, IMS_vendor_id_3GPP, IMS_Cx, 0 /*IMS_Cx*/)) goto error1; if (!cxdx_add_auth_session_state(mar, 1)) goto error1; if (!cxdx_add_public_identity(mar, public_identity)) goto error1; if (!cxdx_add_user_name(mar, private_identity)) goto error1; if (!cxdx_add_sip_number_auth_items(mar, count)) goto error1; if (algorithm.len == auth_scheme_types[AUTH_HTTP_DIGEST_MD5].len && strncasecmp(algorithm.s, auth_scheme_types[AUTH_HTTP_DIGEST_MD5].s, algorithm.len) == 0) { if (!cxdx_add_sip_auth_data_item_request(mar, algorithm, authorization, private_identity, cxdx_dest_realm, msg->first_line.u.request.method, server_name)) goto error1; } else { if (!cxdx_add_sip_auth_data_item_request(mar, algorithm, authorization, private_identity, cxdx_dest_realm, msg->first_line.u.request.method, s_empty)) goto error1; } if (!cxdx_add_server_name(mar, server_name)) goto error1; if (cxdx_forced_peer.len) cdpb.AAASendMessageToPeer(mar, &cxdx_forced_peer, (void*) async_cdp_callback, (void*) transaction_data); else cdpb.AAASendMessage(mar, (void*) async_cdp_callback, (void*) transaction_data); LM_DBG("Successfully sent async diameter\n"); return 0; error1: //Only free MAR IFF is has not been passed to CDP if (mar) cdpb.AAAFreeMessage(&mar); LM_ERR("Error occurred trying to send MAR\n"); return -1; }
/** * Create and send a Server-Assignment-Request and returns the Answer received for it. * This function performs the Server Assignment operation. * @param msg - the SIP message to send for * @parma public_identity - the public identity of the user * @param server_name - local name of the S-CSCF to save on the HSS * @param assignment_type - type of the assignment * @param data_available - if the data is already available * @returns the SAA */ int cxdx_send_sar(struct sip_msg *msg, str public_identity, str private_identity, str server_name, int assignment_type, int data_available, saved_transaction_t* transaction_data) { AAAMessage *sar = 0; AAASession *session = 0; unsigned int hash = 0, label = 0; struct hdr_field *hdr; session = cdpb.AAACreateSession(0); sar = cdpb.AAACreateRequest(IMS_Cx, IMS_SAR, Flag_Proxyable, session); if (session) { cdpb.AAADropSession(session); session = 0; } if (!sar) goto error1; if (send_vs_callid_avp) if (!cxdx_add_call_id(sar, cscf_get_call_id(msg, &hdr))) goto error1; if (!cxdx_add_destination_realm(sar, cxdx_dest_realm)) goto error1; if (!cxdx_add_vendor_specific_appid(sar, IMS_vendor_id_3GPP, IMS_Cx, 0 /*IMS_Cx*/)) goto error1; if (!cxdx_add_auth_session_state(sar, 1)) goto error1; if (!cxdx_add_public_identity(sar, public_identity)) goto error1; if (!cxdx_add_server_name(sar, server_name)) goto error1; if (private_identity.len) if (!cxdx_add_user_name(sar, private_identity)) goto error1; if (!cxdx_add_server_assignment_type(sar, assignment_type)) goto error1; if (!cxdx_add_userdata_available(sar, data_available)) goto error1; if (msg && tmb.t_get_trans_ident(msg, &hash, &label) < 0) { // it's ok cause we can call this async with a message for ul callbacks! LM_DBG("SIP message without transaction... must be a ul callback\n"); //return 0; } if (cxdx_forced_peer.len) cdpb.AAASendMessageToPeer(sar, &cxdx_forced_peer, (void*) async_cdp_callback, (void*) transaction_data); else cdpb.AAASendMessage(sar, (void*) async_cdp_callback, (void*) transaction_data); return 0; error1: //Only free SAR IFF it has not been passed to CDP if (sar) cdpb.AAAFreeMessage(&sar); return -1; }
/** * Sends an UAR and returns the parsed UAA struct. * @param msg - the SIP message * @param private_identity - the username * @param public_identity - the public identity * @param visited_network_id - id of the roaming network * @param authorization_type - if registration or de-registration * @returns the status of sending the async UAR - 0 for success, !0 for failure */ int cxdx_send_uar(struct sip_msg *msg, str private_identity, str public_identity, str visited_network_id, int authorization_type, int sos_reg, saved_uar_transaction_t* transaction_data) { AAAMessage *uar = 0; AAASession *session = 0; session = cdpb.AAACreateSession(0); uar = cdpb.AAACreateRequest(IMS_Cx, IMS_UAR, Flag_Proxyable, session); if (session) { cdpb.AAADropSession(session); session = 0; } if (!uar) goto error1; if (!cxdx_add_destination_realm(uar, cxdx_dest_realm)) goto error1; if (!cxdx_add_vendor_specific_appid(uar, IMS_vendor_id_3GPP, IMS_Cx, 0)) goto error1; if (!cxdx_add_auth_session_state(uar, 1)) goto error1; if (!cxdx_add_user_name(uar, private_identity)) goto error1; if (!cxdx_add_public_identity(uar, public_identity)) goto error1; if (!cxdx_add_visited_network_id(uar, visited_network_id)) goto error1; if (!cxdx_add_UAR_flags(uar, sos_reg)) goto error1; if (authorization_type != AVP_IMS_UAR_REGISTRATION) if (!cxdx_add_authorization_type(uar, authorization_type)) goto error1; if (cxdx_forced_peer.len) cdpb.AAASendMessageToPeer(uar, &cxdx_forced_peer, (void*) async_cdp_uar_callback, (void*) transaction_data); else cdpb.AAASendMessage(uar, (void*) async_cdp_uar_callback, (void*) transaction_data); LM_DBG("Successfully sent async diameter\n"); return 0; error1: //Only free UAR IFF it has not been passed to CDP if (uar) cdpb.AAAFreeMessage(&uar); LM_ERR("Error occurred trying to send UAR\n"); return -1; }
AAAMessage* cxdx_process_rtr(AAAMessage *rtr) { LM_DBG("Processing RTR"); AAAMessage *rta_msg; AAA_AVP* avp; str public_id; impurecord_t* r; int res = 0; udomain_t* udomain; impu_contact_t *impucontact; rta_msg = cdpb.AAACreateResponse(rtr);//session ID? if (!rta_msg) return 0; avp = cxdx_get_next_public_identity(rtr,0,AVP_IMS_Public_Identity,IMS_vendor_id_3GPP,__FUNCTION__); if(avp==0){ LM_WARN("RTR received with only IMPI (username AVP) - currently S-CSCF does not support this kind of RTR\n"); return 0; //TODO add support for receiving RTR with IMPI //get all impus related to this impu //get all contacts related to each impu //set the contact expire for each contact to now }else{ public_id=avp->data; LM_DBG("RTR received with IMPU [%.*s] in public identity AVP - this is supported\n", public_id.len, public_id.s); //TODO this should be a configurable module param if (ul.register_udomain(domain, &udomain) < 0) { LM_ERR("Unable to register usrloc domain....aborting\n"); return 0; } ul.lock_udomain(udomain, &public_id); res = ul.get_impurecord(udomain, &public_id, &r); if (res != 0) { LM_WARN("Strange, '%.*s' Not found in usrloc\n", public_id.len, public_id.s); ul.unlock_udomain(udomain, &public_id); //no point in continuing return 0; } impucontact = r->linked_contacts.head; while (impucontact) { LM_DBG("Deleting contact with AOR [%.*s]\n", impucontact->contact->aor.len, impucontact->contact->aor.s); ul.lock_contact_slot_i(impucontact->contact->sl); impucontact->contact->state = CONTACT_DELETE_PENDING; if (r->shead) { //send NOTIFY to all subscribers of this IMPU. notify_subscribers(r, 0, 0); } impucontact->contact->state = CONTACT_DELETED; ul.unlock_contact_slot_i(impucontact->contact->sl); impucontact = impucontact->next; } ul.unlock_udomain(udomain, &public_id); while(cdpb.AAAGetNextAVP(avp) && (avp=cxdx_get_next_public_identity(rtr,cdpb.AAAGetNextAVP(avp),AVP_IMS_Public_Identity,IMS_vendor_id_3GPP,__FUNCTION__))!=0){ public_id=avp->data; LM_DBG("RTR also has public id [%.*s]\n", public_id.len, public_id.s); ul.lock_udomain(udomain, &public_id); res = ul.get_impurecord(udomain, &public_id, &r); if (res != 0) { LM_WARN("Strange, '%.*s' Not found in usrloc\n", public_id.len, public_id.s); ul.unlock_udomain(udomain, &public_id); //no point in continuing return 0; } impucontact = r->linked_contacts.head; while (impucontact) { LM_DBG("Deleting contact with AOR [%.*s]\n", impucontact->contact->aor.len, impucontact->contact->aor.s); ul.lock_contact_slot_i(impucontact->contact->sl); impucontact->contact->state = CONTACT_DELETE_PENDING; if (r->shead) { //send NOTIFY to all subscribers of this IMPU. notify_subscribers(r, 0, 0); } impucontact->contact->state = CONTACT_DELETED; ul.unlock_contact_slot_i(impucontact->contact->sl); impucontact = impucontact->next; } ul.unlock_udomain(udomain, &public_id); } } cxdx_add_vendor_specific_appid(rta_msg,IMS_vendor_id_3GPP,IMS_Cx,0 /*IMS_Cx*/); cxdx_add_auth_session_state(rta_msg,1); /* send an RTA back to the HSS */ cxdx_add_result_code(rta_msg,DIAMETER_SUCCESS); return rta_msg; }