Beispiel #1
0
/**
 *	Get public identity from Request-URI for terminating.
 * returns in uri the freshly pkg allocated uri - don't forget to free
 * @param msg - the SIP message
 * @param uri - uri to fill into
 * @returns #IMS_USER_REGISTERED if found, else #IMS_USER_NOT_REGISTERED 
 */
int isc_get_terminating_user( struct sip_msg * msg, str *uri )
{
	*uri = cscf_get_public_identity_from_requri(msg);
	if (!uri->len) return IMS_USER_NOT_REGISTERED;
	/*if ( isc_get_terminating_type( uri ) == IFC_TERMINATING_UNREGISTERED )
		DBG("DBG:"M_NAME":isc_get_terminating_type: To UNREGISTERED %.*s\n", uri->len,uri->s);
	else
		DBG("DBG:"M_NAME":isc_get_terminating_type: To REGISTERED %.*s\n", uri->len,uri->s);	*/
	return IMS_USER_REGISTERED;
}
Beispiel #2
0
/**
 * Perform an LIR
 * @param msg - sip message
 * @returns 1 on success or 0 on failure
 */
int I_perform_location_information_request(struct sip_msg* msg, char* route, char* str1, char* str2) {
    str public_identity = {0, 0};
    int orig = 0;
    
    tm_cell_t *t = 0;
    saved_lir_transaction_t* saved_t;
    
    str route_name;
    
     cfg_action_t* cfg_action;

     if (fixup_get_svalue(msg, (gparam_t*) route, &route_name) != 0) {
        LM_ERR("no async route block for assign_server_unreg\n");
        return -1;
    }
    
    LM_DBG("Looking for route block [%.*s]\n", route_name.len, route_name.s);
    int ri = route_get(&main_rt, route_name.s);
    if (ri < 0) {
        LM_ERR("unable to find route block [%.*s]\n", route_name.len, route_name.s);
        return -1;
    }
    cfg_action = main_rt.rlist[ri];
    if (cfg_action == NULL) {
        LM_ERR("empty action lists in route block [%.*s]\n", route_name.len, route_name.s);
        return -1;
    }
    
    LM_DBG("DBG:I_LIR: Starting ...\n");
    /* check if we received what we should */
    if (msg->first_line.type != SIP_REQUEST) {
        LM_ERR("ERR:I_LIR: The message is not a request\n");
        return CSCF_RETURN_BREAK;
    }

    /* check orig uri parameter in topmost Route */
    if (cscf_has_originating(msg, str1, str2) == CSCF_RETURN_TRUE) {
        orig = 1;
        LM_DBG("DBG:I_LIR: orig\n");
    }

    /* extract data from message */
    if (orig) {
        public_identity = cscf_get_asserted_identity(msg, 0);
    } else {
        public_identity = cscf_get_public_identity_from_requri(msg);
    }
    if (!public_identity.len) {
        LM_ERR("ERR:I_LIR: Public Identity not found, responding with 400\n");
        if (orig)
            cscf_reply_transactional(msg, 400, MSG_400_NO_PUBLIC_FROM);
        else
            cscf_reply_transactional(msg, 400, MSG_400_NO_PUBLIC);
        return CSCF_RETURN_BREAK;
    }
    
    
    //before we send lets suspend the transaction
    t = tmb.t_gett();
    if (t == NULL || t == T_UNDEFINED) {
        if (tmb.t_newtran(msg) < 0) {
            LM_ERR("cannot create the transaction for UAR async\n");
            cscf_reply_transactional(msg, 480, MSG_480_DIAMETER_ERROR);
            return CSCF_RETURN_BREAK;
        }
        t = tmb.t_gett();
        if (t == NULL || t == T_UNDEFINED) {
            LM_ERR("cannot lookup the transaction\n");
            cscf_reply_transactional(msg, 480, MSG_480_DIAMETER_ERROR);
            return CSCF_RETURN_BREAK;
        }
    }

    saved_t = shm_malloc(sizeof (saved_lir_transaction_t));
    if (!saved_t) {
        LM_ERR("no more memory trying to save transaction state\n");
        return CSCF_RETURN_ERROR;

    }
    memset(saved_t, 0, sizeof (saved_lir_transaction_t));
    saved_t->act = cfg_action;
    
    saved_t->orig = orig;
    
    LM_DBG("Setting default AVP return code used for async callbacks to default as ERROR \n");
    create_lia_return_code(CSCF_RETURN_ERROR);
    
    LM_DBG("Suspending SIP TM transaction\n");
    if (tmb.t_suspend(msg, &saved_t->tindex, &saved_t->tlabel) < 0) {
        LM_ERR("failed to suspend the TM processing\n");
        free_saved_lir_transaction_data(saved_t);

        cscf_reply_transactional(msg, 480, MSG_480_DIAMETER_ERROR);
        return CSCF_RETURN_BREAK;
    }
    
    if (cxdx_send_lir(msg, public_identity, saved_t) != 0) {
        LM_ERR("ERR:I_LIR: Error sending LIR or LIR time-out\n");
        tmb.t_cancel_suspend(saved_t->tindex, saved_t->tlabel);
        free_saved_lir_transaction_data(saved_t);
        cscf_reply_transactional(msg, 480, MSG_480_DIAMETER_ERROR);
        
        if (public_identity.s && !orig)
        shm_free(public_identity.s); // shm_malloc in cscf_get_public_identity_from_requri		
        return CSCF_RETURN_BREAK;

    }
    if (public_identity.s && !orig)
        shm_free(public_identity.s); // shm_malloc in cscf_get_public_identity_from_requri		
    
    //we use async replies therefore we send break and not true when successful
    return CSCF_RETURN_BREAK;
}
Beispiel #3
0
/**
 *	Get public identity from Request-URI for terminating.
 * returns in uri the freshly pkg allocated uri - don't forget to free
 * @param msg - the SIP message
 * @param uri - uri to fill into
 * @returns 1 if found, else 0 
 */
int cscf_get_terminating_user( struct sip_msg * msg, str *uri )
{
	*uri = cscf_get_public_identity_from_requri(msg);
	if (!uri->len) return 0;
	return 1;
}
/**
 * Send a CCR to the OCS based on the SIP message (INVITE ONLY)
 * @param msg - SIP message
 * @param direction - orig|term
 * @param reservation_units - units to try to reserve
 * @param reservation_units - config route to call when receiving a CCA
 * @param tindex - transaction index
 * @param tindex - transaction label
 *
 * @returns #CSCF_RETURN_BREAK if OK, #CSCF_RETURN_ERROR on error
 */
int Ro_Send_CCR(struct sip_msg *msg, struct dlg_cell *dlg, int dir, int reservation_units, str* incoming_trunk_id, str* outgoing_trunk_id,
        str* pani, cfg_action_t* action, unsigned int tindex, unsigned int tlabel) {
    str session_id = {0, 0},
    called_asserted_identity = {0, 0},
    subscription_id = {0, 0},
    asserted_identity = {0, 0};
    int subscription_id_type = AVP_EPC_Subscription_Id_Type_End_User_SIP_URI;
    AAASession* cc_acc_session = NULL;
    Ro_CCR_t * ro_ccr_data = 0;
    AAAMessage * ccr = 0;
    struct ro_session *new_session = 0;
    struct session_setup_data *ssd;
    int ret = 0;
    struct hdr_field *h = 0;
    char *p;

    int cc_event_number = 0; //According to IOT tests this should start at 0
    int cc_event_type = RO_CC_START;
    int free_called_asserted_identity = 0;

    sdp_session_cell_t* msg_sdp_session;
    sdp_stream_cell_t* msg_sdp_stream;

    int active_service_identifier;
    int active_rating_group;

    int sdp_stream_num = 0;

    LM_DBG("Sending initial CCR request (%c) for reservation_units [%d] incoming_trunk_id [%.*s] outgoing_trunk_id [%.*s]\n",
	dir==RO_ORIG_DIRECTION?'O':'T',
			reservation_units,
            incoming_trunk_id->len, incoming_trunk_id->s,
            outgoing_trunk_id->len, outgoing_trunk_id->s);

    ssd = shm_malloc(sizeof (struct session_setup_data)); // lookup structure used to load session info from cdp callback on CCA
    if (!ssd) {
        LM_ERR("no more shm mem\n");
        goto error;
    }

    //getting asserted identity
    if ((asserted_identity = cscf_get_asserted_identity(msg, 0)).len == 0) {
        LM_DBG("No P-Asserted-Identity hdr found. Using From hdr for asserted_identity");
        asserted_identity = dlg->from_uri;
        if (asserted_identity.len > 0 && asserted_identity.s) {
            p=(char*)memchr(asserted_identity.s, ';',asserted_identity.len);
            if (p) 
                asserted_identity.len = (p-asserted_identity.s);
        }
    }

    //getting called asserted identity
    if ((called_asserted_identity = cscf_get_public_identity_from_called_party_id(msg, &h)).len == 0) {
        LM_DBG("No P-Called-Identity hdr found. Using request URI for called_asserted_identity");
        called_asserted_identity = cscf_get_public_identity_from_requri(msg);
        free_called_asserted_identity = 1;
    }

    if (dir == RO_ORIG_DIRECTION) {
        subscription_id.s = asserted_identity.s;
        subscription_id.len = asserted_identity.len;

    } else if (dir == RO_TERM_DIRECTION) {
        subscription_id.s = called_asserted_identity.s;
        subscription_id.len = called_asserted_identity.len;
    } else {
        LM_CRIT("don't know what to do in unknown mode - should we even get here\n");
        goto error;
    }

    //getting subscription id type
    if (strncasecmp(subscription_id.s, "tel:", 4) == 0) {
        subscription_id_type = Subscription_Type_MSISDN;
    } else {
        subscription_id_type = Subscription_Type_IMPU; //default is END_USER_SIP_URI
    }

    str mac = {0, 0};
    if (get_mac_avp_value(msg, &mac) != 0)
        LM_DBG(RO_MAC_AVP_NAME" was not set. Using default.");

    //by default we use voice service id and rate group
    //then we check SDP - if we find video then we use video service id and rate group
    LM_DBG("Setting default SID to %d and RG to %d for voice",
            voice_service_identifier, voice_rating_group);
    active_service_identifier = voice_service_identifier;
    active_rating_group = voice_rating_group;

    //check SDP - if there is video then set default to video, if not set it to audio
    if (parse_sdp(msg) < 0) {
        LM_ERR("Unable to parse req SDP\n");
        goto error;
    }

    msg_sdp_session = get_sdp_session(msg, 0);
    if (!msg_sdp_session) {
        LM_ERR("Missing SDP session information from rpl\n");
    } else {
        for (;;) {
            msg_sdp_stream = get_sdp_stream(msg, 0, sdp_stream_num);
            if (!msg_sdp_stream) {
                //LM_ERR("Missing SDP stream information\n");
                break;
            }

            int intportA = atoi(msg_sdp_stream->port.s);
            if (intportA != 0 && strncasecmp(msg_sdp_stream->media.s, "video", 5) == 0) {
                LM_DBG("This SDP has a video component and src ports not equal to 0 - so we set default SID to %d and RG to %d for video",
                        video_service_identifier, video_rating_group);
                active_service_identifier = video_service_identifier;
                active_rating_group = video_rating_group;
                break;
            }

            sdp_stream_num++;
        }
    }

    free_sdp((sdp_info_t**) (void*) &msg->body);

    //create a session object without auth and diameter session id - we will add this later.
    new_session = build_new_ro_session(dir, 0, 0, &session_id, &dlg->callid,
            &asserted_identity, &called_asserted_identity, &mac, dlg->h_entry, dlg->h_id,
            reservation_units, 0, active_rating_group, active_service_identifier, incoming_trunk_id, outgoing_trunk_id, pani);

    if (!new_session) {
        LM_ERR("Couldn't create new Ro Session - this is BAD!\n");
        goto error;
    }

    ssd->action = action;
    ssd->tindex = tindex;
    ssd->tlabel = tlabel;
    ssd->ro_session = new_session;

    if (!sip_create_ro_ccr_data(msg, dir, &ro_ccr_data, &cc_acc_session, asserted_identity, called_asserted_identity, subscription_id, subscription_id_type, incoming_trunk_id, outgoing_trunk_id, pani))
        goto error;

    if (!ro_ccr_data)
        goto error;

    if (!cc_acc_session)
        goto error;

    if (!(ccr = Ro_new_ccr(cc_acc_session, ro_ccr_data)))
        goto error;

    if (!Ro_add_vendor_specific_appid(ccr, IMS_vendor_id_3GPP, IMS_Ro, 0)) {
        LM_ERR("Problem adding Vendor specific ID\n");
        goto error;
    }

    if (!Ro_add_cc_request(ccr, cc_event_type, cc_event_number)) {
        LM_ERR("Problem adding CC-Request data\n");
        goto error;
    }

    if (!Ro_add_event_timestamp(ccr, time(NULL))) {
        LM_ERR("Problem adding Event-Timestamp data\n");
        goto error;
    }

    if (!Ro_add_user_equipment_info(ccr, AVP_EPC_User_Equipment_Info_Type_MAC, mac)) {
        LM_ERR("Problem adding User-Equipment data\n");
        goto error;
    }

    if (!Ro_add_subscription_id(ccr, subscription_id_type, &subscription_id)) {
        LM_ERR("Problem adding Subscription ID data\n");
        goto error;
    }
    if (!Ro_add_multiple_service_credit_Control(ccr, reservation_units, -1, active_rating_group, active_service_identifier)) {
        LM_ERR("Problem adding Multiple Service Credit Control data\n");
        goto error;
    }

    /* before we send, update our session object with CC App session ID and data */
    new_session->auth_appid = cc_acc_session->application_id;
    new_session->auth_session_type = cc_acc_session->type;
    new_session->ro_session_id.s = (char*) shm_malloc(cc_acc_session->id.len);
    if (!new_session->ro_session_id.s) {
        LM_ERR("no more shm mem\n");
        goto error;
    }

    new_session->ro_session_id.len = cc_acc_session->id.len;
    memcpy(new_session->ro_session_id.s, cc_acc_session->id.s, cc_acc_session->id.len);

    LM_DBG("new CC Ro Session ID: [%.*s] stored in shared memory address [%p]\n", cc_acc_session->id.len, cc_acc_session->id.s, new_session);

    LM_DBG("Sending CCR Diameter message.\n");
//    new_session->ccr_sent = 1;      //assume we will send successfully
    cdpb.AAASessionsUnlock(cc_acc_session->hash);

    if (ro_forced_peer.len > 0) {
        LM_DBG("Sending message with Peer\n");
        ret = cdpb.AAASendMessageToPeer(ccr, &ro_forced_peer, resume_on_initial_ccr, (void *) ssd);
    } else {
        LM_DBG("Sending message without Peer and realm is [%.*s]\n", ccr->dest_realm->data.len, ccr->dest_realm->data.s);
        ret = cdpb.AAASendMessage(ccr, resume_on_initial_ccr, (void *) ssd);
    }

    if (ret != 1) {
        LM_ERR("Failed to send Diameter CCR\n");
//        new_session->ccr_sent = 0;
        goto error;
    }

    Ro_free_CCR(ro_ccr_data);

    LM_DBG("Registering for callbacks on Dialog [%p] and charging session [%p]\n", dlg, new_session);

    //TODO: if the following fail, we should clean up the Ro session.......
    if (dlgb.register_dlgcb(dlg, DLGCB_TERMINATED | DLGCB_FAILED | DLGCB_EXPIRED | DLGCB_CONFIRMED, dlg_callback_received, (void*) new_session, NULL) != 0) {
        LM_CRIT("cannot register callback for dialog confirmation\n");
        goto error;
    }

    counter_inc(ims_charging_cnts_h.initial_ccrs);
    counter_inc(ims_charging_cnts_h.active_ro_sessions);

    if (free_called_asserted_identity) shm_free(called_asserted_identity.s); // shm_malloc in cscf_get_public_identity_from_requri	
    return RO_RETURN_BREAK;

error:
    LM_DBG("Trying to reserve credit on initial INVITE failed.\n");

    if (free_called_asserted_identity) shm_free(called_asserted_identity.s); // shm_malloc in cscf_get_public_identity_from_requri	
    Ro_free_CCR(ro_ccr_data);
    if (cc_acc_session) {
        cdpb.AAASessionsUnlock(cc_acc_session->hash);
        cdpb.AAADropSession(cc_acc_session);
    }

    if (ssd)
        shm_free(ssd);

	    return RO_RETURN_ERROR;
}