/***********************************************
  *         PassThrough Timer
 ***********************************************
  ** sip_platform_pass_through_timer_start
  *  Starts a timer when all registrations fail.
  *
  *  @param  sec Value of the timer to be started
  *
  *  @return SIP_OK if timer could be started; else  SIP_ERROR
  *
  */
int
sip_platform_pass_through_timer_start (uint32_t sec)
{
	static const char fname[] = "sip_platform_pass_through_timer_start";
	
	if (sip_platform_pass_through_timer_stop() == SIP_ERROR) {
		return SIP_ERROR;
	}	
	if (cprStartTimer(sipPassThroughTimer, sec*1000, NULL) == CPR_FAILURE) {
		CCSIP_DEBUG_STATE(get_debug_string(DEBUG_SIP_FUNCTIONCALL_FAILED),
				 		  0, 0, fname, "cprStartTimer");
		return SIP_ERROR;
	}
	
	CCSIP_DEBUG_REG_STATE("%s: Regmgr Pass Through Timer started for %lu secs\n", fname, sec);
	return SIP_OK;
}
int
sip_platform_notify_timer_start (uint32_t msec)
{
    static const char fname[] = "sip_platform_notify_timer_start";

    if (sip_platform_notify_timer_stop() == SIP_ERROR) {
        return SIP_ERROR;
    }

    if (cprStartTimer(sipPlatformNotifyTimer, msec, NULL) == CPR_FAILURE) {
        CCSIP_DEBUG_STATE(get_debug_string(DEBUG_SIP_FUNCTIONCALL_FAILED),
                          0, 0, fname, "cprStartTimer");
        return SIP_ERROR;
    }
    CCSIP_DEBUG_STATE(DEB_F_PREFIX
        "Timer started for %lu msecs\n", DEB_F_PREFIX_ARGS(SIP_TIMER, fname), msec);
    return SIP_OK;
}
int
sip_platform_subnot_periodic_timer_start (uint32_t msec)
{
    static const char fname[] = "sip_platform_subnot_periodic_timer_start";

    if (sip_platform_subnot_periodic_timer_stop() == SIP_ERROR) {
        return SIP_ERROR;
    }

    if (cprStartTimer(sipPlatformSubNotPeriodicTimer.timer, msec, (void *) 0)
            == CPR_FAILURE) {
        CCSIP_DEBUG_STATE(get_debug_string(DEBUG_SIP_FUNCTIONCALL_FAILED),
                          -1, 0, fname, "cprStartTimer");
        return SIP_ERROR;
    }
    sipPlatformSubNotPeriodicTimer.started = TRUE;
    return SIP_OK;
}
/*
 * Call disconnect timer
 */
int
sip_platform_supervision_disconnect_timer_start (uint32_t msec, int idx)
{
    static const char fname[] = "sip_platform_supervision_disconnect_timer_start";

    if (sip_platform_supervision_disconnect_timer_stop(idx) == SIP_ERROR) {
        return SIP_ERROR;
    }

    if (cprStartTimer(sipPlatformSupervisionTimers[idx].timer, msec,
                      (void *)(long) idx) == CPR_FAILURE) {
        CCSIP_DEBUG_STATE(get_debug_string(DEBUG_SIP_FUNCTIONCALL_FAILED),
                          idx, 0, fname, "cprStartTimer");
        return SIP_ERROR;
    }

    return SIP_OK;
}
int
sip_platform_register_expires_timer_start (uint32_t msec, int idx)
{
    static const char fname[] = "sip_platform_register_expires_timer_start";

    if (sip_platform_register_expires_timer_stop(idx) == SIP_ERROR) {
        return SIP_ERROR;
    }

    if (cprStartTimer(sipPlatformUISMRegExpiresTimers[idx].timer, msec,
                      (void *)(long) idx) == CPR_FAILURE) {
        CCSIP_DEBUG_ERROR(get_debug_string(DEBUG_SIP_FUNCTIONCALL_FAILED),
                          idx, 0, fname, "cprStartTimer");
        return SIP_ERROR;
    }

    return SIP_OK;
}
int
sip_platform_unregistration_timer_start (uint32_t msec, boolean external)
{
    static const char fname[] = "sip_platform_unregistration_timer_start";

    if (sip_platform_unregistration_timer_stop() == SIP_ERROR) {
        return SIP_ERROR;
    }

    if (cprStartTimer(sipPlatformUnRegistrationTimer, msec, (void *)(long)external)
            == CPR_FAILURE) {
        CCSIP_DEBUG_STATE(get_debug_string(DEBUG_SIP_FUNCTIONCALL_FAILED),
                          0, 0, fname, "cprStartTimer");
        return SIP_ERROR;
    }
    CCSIP_DEBUG_STATE(DEB_F_PREFIX
        "Timer started for %lu msecs\n", DEB_F_PREFIX_ARGS(SIP_TIMER, fname), msec);
    return SIP_OK;
}
Example #7
0
/*
 *  Function: dp_restart_dial_timer()
 *
 *  Parameters: line - line number
 *              call_id - call indentification
 *              timeout - timeout value for the dial timer
 *
 *  Description: Start dial timer
 *
 *  Returns: none
 */
static void
dp_restart_dial_timer (line_t line, callid_t call_id, int timeout)
{
    const char fname[] = "dp_restart_dial_timer";

    DPINT_DEBUG(DEB_F_PREFIX"line=%d call_id=%d timeout=%u\n", DEB_F_PREFIX_ARGS(DIALPLAN, fname), line,
                call_id, timeout);

    g_dp_int.timer_info.index.line = line;
    g_dp_int.timer_info.index.call_id = call_id;

    if (g_dp_int.dial_timer) {
        (void) cprCancelTimer(g_dp_int.dial_timer);

        (void) cprStartTimer(g_dp_int.dial_timer, timeout,
                             &g_dp_int.timer_info);

    }
}
Example #8
0
static boolean
fsm_init_cac_failure_timer(cac_data_t *cac_data, uint32_t timeout)
{
    const char fname[] = "fsm_init_cac_failure_timer";

    CAC_DEBUG(DEB_F_PREFIX"cac_data call_id=%x",
              DEB_F_PREFIX_ARGS("CAC", fname),
              cac_data->call_id);

    cac_data->cac_fail_timer =
        cprCreateTimer("CAC failure timer", GSM_CAC_FAILURE_TIMER, TIMER_EXPIRATION,
                       gsm_msgq);

    if (cac_data->cac_fail_timer == NULL) {
        CAC_ERROR(DEB_F_PREFIX"CAC Timer allocation failed.",
                                    DEB_F_PREFIX_ARGS("CAC", fname));
        return(FALSE);
    }

    (void) cprStartTimer(cac_data->cac_fail_timer, timeout * 1000,
                         (void *)(long)cac_data->call_id);

    return(TRUE);
}
/*
 *  Function: notify_ind_cb()
 *
 *  Parameters: msg_data - the response data provoded by SIP stack.
 *
 *  Description:  is invoked by SIP stack when it receives a NOTIFY message. it takes
 *                action based on subscription_state and blf state derived from event body.
 *
 *  Returns: void
 */
static void
notify_ind_cb (ccsip_sub_not_data_t * msg_data)
{
    static const char fname[] = "notify_ind_cb";
    int sub_state = msg_data->u.notify_ind_data.subscription_state;
    sip_subs_state_reason_e reason =
    msg_data->u.notify_ind_data.subscription_state_reason;
    uint32_t retry_after = msg_data->u.notify_ind_data.retry_after;
    int request_id = msg_data->request_id;
    sub_id_t sub_id = msg_data->sub_id;
    pres_subscription_req_t *sub_req_p;
    Presence_ext_t *event_body_p = NULL;
    uint32_t cseq = msg_data->u.notify_ind_data.cseq;
    int blf_state;

    BLF_DEBUG(DEB_F_PREFIX"Entering (subscription_state=%d)",
              DEB_F_PREFIX_ARGS(BLF, fname), sub_state);

    /*
     * memory for event bodies is allocated by sip stack and it is the
     * responsibility of the user (this module) to free it when it is done with it.
     */
    if ((msg_data->u.notify_ind_data.eventData != NULL) &&
        (msg_data->u.notify_ind_data.eventData->type != EVENT_DATA_PRESENCE)) {
        BLF_ERROR(MISC_F_PREFIX"NOTIFY does not contain presence body", fname);
        free_event_data(msg_data->u.notify_ind_data.eventData);
        msg_data->u.notify_ind_data.eventData = NULL;
    }

    event_body_p = (msg_data->u.notify_ind_data.eventData == NULL) ?
        NULL : &(msg_data->u.notify_ind_data.eventData->u.presence_rpid);


    if ((s_pres_req_list == NULL) ||
        ((sub_req_p = (pres_subscription_req_t *)
          sll_find(s_pres_req_list, &request_id)) == NULL)) {
        /*
         * since we do not have subscription for this, help SIP stack clean up.
         * first, post SIPSPI_EV_CC_NOTIFY_RESPONSE so that SIP stack sends 481, then
         * post SIPSPI_EV_CC_SUBSCRIPTION_TERMINATED so that SIP stack cleans up.
         */
        (void) sub_int_notify_ack(sub_id, SIP_CLI_ERR_CALLEG, cseq);

        (void) sub_int_subscribe_term(sub_id, TRUE, request_id,
                                      CC_SUBSCRIPTIONS_PRESENCE);
        free_event_data(msg_data->u.notify_ind_data.eventData);
        BLF_DEBUG(DEB_F_PREFIX"Exiting : subscription does not exist", DEB_F_PREFIX_ARGS(BLF, fname));
        return;
    }

    /*
     * post SIPSPI_EV_CC_NOTIFY_RESPONSE.
     */
    (void) sub_int_notify_ack(sub_id, SIP_STATUS_SUCCESS, cseq);

    /*
     * check if it is out of sequence NOTIFY, if so, do not use the presence state carried in it.
     */
    if (cseq < sub_req_p->highest_cseq) {
        free_event_data(msg_data->u.notify_ind_data.eventData);
        BLF_ERROR(MISC_F_PREFIX"Exiting : out of sequence NOTIFY received", fname);
        return;
    } else {
        sub_req_p->highest_cseq = cseq;
    }


    /*
     * If the Subscription_state is terminated, then ...
     */
    if (sub_state == SUBSCRIPTION_STATE_TERMINATED) {
        /*
         * post SIPSPI_EV_CC_SUBSCRIPTION_TERMINATED to SIP stack.
         */
        (void) sub_int_subscribe_term(sub_id, TRUE, sub_req_p->request_id,
                                      CC_SUBSCRIPTIONS_PRESENCE);
        if (reason == SUBSCRIPTION_STATE_REASON_DEACTIVATED) {
            /* if the reason is "decativated", re-subscribe. */
            sub_req_p->sub_id = CCSIP_SUBS_INVALID_SUB_ID;
            sub_req_p->highest_cseq = 0;
            /*
             * post SIPSPI_EV_CC_SUBSCRIBE to SIP stack
             */
            if (send_subscribe_ev_to_sip_task(sub_req_p) != CC_RC_SUCCESS) {
                /* let platform know that we can not continue */
                ui_BLF_notification(request_id, CC_SIP_BLF_REJECTED,
                                 sub_req_p->app_id);
                /*
                 * remove the node from the list of subscriptions.
                 */
                free_sub_request(sub_req_p);
            }
        } else if ((reason == SUBSCRIPTION_STATE_REASON_TIMEOUT) ||
                   (reason == SUBSCRIPTION_STATE_REASON_PROBATION) ||
                   (reason == SUBSCRIPTION_STATE_REASON_GIVEUP)) {
            /* let the app know that susbcription expired so that it can resusbcribe later */
            ui_BLF_notification(request_id, CC_SIP_BLF_EXPIRED, sub_req_p->app_id);
            sub_req_p->blf_state = CC_SIP_BLF_EXPIRED;
            if (sub_req_p->app_id > 0) {
                /*
                 * Since it is speeddial/blf, we must send a new subscription.
                 */
                sub_req_p->sub_id = CCSIP_SUBS_INVALID_SUB_ID;
                sub_req_p->highest_cseq = 0;
                if ((reason == SUBSCRIPTION_STATE_REASON_PROBATION) ||
                    (reason == SUBSCRIPTION_STATE_REASON_GIVEUP)) {
                    /*
                     * Start a timer based on retry-after value. If retry-after value is 0,
                     * use a default value of 5 sec
                     */
                    if (retry_after == 0) {
                        retry_after = DEFAULT_RETRY_AFTER_MILLISECS;
                    } else {
                        retry_after = (retry_after * 1000); // converting into millisecs
                    }
                    if ((cprCancelTimer(s_retry_after_timers[sub_req_p->app_id - 1])
                                == CPR_SUCCESS) &&
                        (cprStartTimer(s_retry_after_timers[sub_req_p->app_id - 1],
                          retry_after, (void *) sub_req_p) == CPR_SUCCESS)) {
                        /*
                         * Timer successfully started. free up event data and return.
                         */
                        free_event_data(msg_data->u.notify_ind_data.eventData);
                        BLF_DEBUG(DEB_F_PREFIX"Exiting : retry_after Timer started",
                                  DEB_F_PREFIX_ARGS(BLF, fname));
                        return;
                    }

                }
                if (send_subscribe_ev_to_sip_task(sub_req_p) != CC_RC_SUCCESS) {
                    /*
                     * remove the node from the list of subscriptions.
                     */
                    free_sub_request(sub_req_p);
                    BLF_ERROR(MISC_F_PREFIX"Unable to send SUBSCRIBE", fname);
                }
                BLF_DEBUG(DEB_F_PREFIX"subscribed again after expiration", DEB_F_PREFIX_ARGS(BLF, fname));
            } else {
                /*
                 * and remove the node from the list of subscriptions.
                 */
                free_sub_request(sub_req_p);
            }
        } else {
            ui_BLF_notification(request_id, CC_SIP_BLF_REJECTED, sub_req_p->app_id);
            /*
             * and remove the node from the list of subscriptions.
             */
            free_sub_request(sub_req_p);
        }
    } else {
        /* derive the BLF state from event data */
        blf_state = extract_blf_state(event_body_p, sub_req_p->feature_mask);
        ui_BLF_notification(request_id, blf_state, sub_req_p->app_id);
        sub_req_p->blf_state = blf_state;
        /*
         * if blf state is ALERTING,
         * play blf alerting audible tone.
         */
        if (blf_state == CC_SIP_BLF_ALERTING) {
            /*
             * Post an event to GSM to play alerting tone.
             */
            cc_feature(CC_SRC_MISC_APP, CC_NO_CALL_ID, 0, CC_FEATURE_BLF_ALERT_TONE, NULL);
        }
        DEF_DEBUG(DEB_F_PREFIX"SUB %d: BLF %d",
            DEB_F_PREFIX_ARGS(BLF_INFO, fname), sub_state, blf_state);
    }

    free_event_data(msg_data->u.notify_ind_data.eventData);
    BLF_DEBUG(DEB_F_PREFIX"Exiting : acted based on subscription state", DEB_F_PREFIX_ARGS(BLF, fname));
    return;
}
int
sip_platform_msg_timer_start (uint32_t msec,
                              void *data,
                              int idx,
                              char *message_buffer,
                              int message_buffer_len,
                              int message_type,
                              cpr_ip_addr_t *ipaddr,
                              uint16_t port,
                              boolean isRegister)
{
    static const char fname[] = "sip_platform_msg_timer_start";
    cprTimer_t timer;

    /* validate index */
    if ((idx < MIN_TEL_LINES) || (idx >= MAX_CCBS)) {
        CCSIP_DEBUG_ERROR(get_debug_string(DEBUG_LINE_NUMBER_INVALID),
                          fname, idx);
        return SIP_ERROR;
    }

    /* validate length */
    if (message_buffer_len >= SIP_UDP_MESSAGE_SIZE) {
        CCSIP_DEBUG_ERROR(get_debug_string(DEBUG_MSG_BUFFER_TOO_BIG),
                          fname, message_buffer_len);
        return SIP_ERROR;
    }

    /* stop the timer if it is running */
    if (cprCancelTimer(sipPlatformUISMTimers[idx].timer) == CPR_FAILURE) {
        CCSIP_DEBUG_STATE(get_debug_string(DEBUG_SIP_FUNCTIONCALL_FAILED),
                          idx, 0, fname, "cprCancelTimer");
        return SIP_ERROR;
    }
    if (cprCancelTimer(sipPlatformUISMTimers[idx].reg_timer) == CPR_FAILURE) {
        CCSIP_DEBUG_STATE(get_debug_string(DEBUG_SIP_FUNCTIONCALL_FAILED),
                          idx, 0, fname, "cprCancelTimer");
        return SIP_ERROR;
    }

    if (sipPlatformUISMTimers[idx].message_buffer == NULL) {
        sipPlatformUISMTimers[idx].message_buffer = (char *)cpr_malloc(message_buffer_len+1);
        if (sipPlatformUISMTimers[idx].message_buffer == NULL) return SIP_ERROR;
    }
    else if (message_buffer != sipPlatformUISMTimers[idx].message_buffer) {
        cpr_free(sipPlatformUISMTimers[idx].message_buffer);
        sipPlatformUISMTimers[idx].message_buffer = (char *)cpr_malloc(message_buffer_len+1);
        if (sipPlatformUISMTimers[idx].message_buffer == NULL) return SIP_ERROR;
    }

    sipPlatformUISMTimers[idx].message_buffer_len = message_buffer_len;
    sipPlatformUISMTimers[idx].message_buffer[message_buffer_len] = '\0';
    memcpy(sipPlatformUISMTimers[idx].message_buffer, message_buffer,
           message_buffer_len);
    sipPlatformUISMTimers[idx].message_type = (sipMethod_t) message_type;
    sipPlatformUISMTimers[idx].ipaddr = *ipaddr;
    sipPlatformUISMTimers[idx].port = port;

    /* start the timer */
    if (isRegister) {
        timer = sipPlatformUISMTimers[idx].reg_timer;
    } else {
        timer = sipPlatformUISMTimers[idx].timer;
    }

    if (cprStartTimer(timer, msec, data) == CPR_FAILURE) {
        CCSIP_DEBUG_STATE(get_debug_string(DEBUG_SIP_FUNCTIONCALL_FAILED),
                          idx, 0, fname, "cprStartTimer");
        cpr_free(sipPlatformUISMTimers[idx].message_buffer);
        sipPlatformUISMTimers[idx].message_buffer = NULL;
        sipPlatformUISMTimers[idx].message_buffer_len = 0;
        return SIP_ERROR;
    }
    sipPlatformUISMTimers[idx].outstanding = TRUE;
    return SIP_OK;
}