예제 #1
0
static
NwRcT s11_sgw_log_wrapper(NwGtpv2cLogMgrHandleT hLogMgr,
                          uint32_t logLevel,
                          NwCharT* file,
                          uint32_t line,
                          NwCharT* logStr)
{
  S11_DEBUG("%s\n", logStr);
  return NW_OK;
}
NwRcT s11_ie_indication_generic(uint8_t  ieType,
                                uint8_t  ieLength,
                                uint8_t  ieInstance,
                                uint8_t *ieValue,
                                void  *arg)
{
  S11_DEBUG("Received IE Parse Indication for of type %u, length %u, "
            "instance %u!\n", ieType, ieLength, ieInstance);
  return NW_OK;
}
예제 #3
0
static int s11_send_init_udp(char *address, uint16_t port_number)
{
  MessageDef *message_p;

  message_p = itti_alloc_new_message(TASK_S11, UDP_INIT);

  if (message_p == NULL) {
    return -1;
  }

  message_p->ittiMsg.udp_init.port = port_number;
  //LG message_p->ittiMsg.udpInit.address = "0.0.0.0"; //ANY address
  message_p->ittiMsg.udp_init.address = address;

  S11_DEBUG("Tx UDP_INIT IP addr %s\n", message_p->ittiMsg.udp_init.address);

  return itti_send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
}
예제 #4
0
/* ULP callback for the GTPv2-C stack */
static
NwRcT s11_sgw_ulp_process_stack_req_cb(
  NwGtpv2cUlpHandleT hUlp, NwGtpv2cUlpApiT *pUlpApi)
{
  int ret = 0;

  DevAssert(pUlpApi != NULL);

  switch (pUlpApi->apiType) {
  case NW_GTPV2C_ULP_API_INITIAL_REQ_IND:
    S11_DEBUG("Received initial req indication\n");

    switch (pUlpApi->apiInfo.initialReqIndInfo.msgType) {
    case NW_GTP_CREATE_SESSION_REQ:
      ret = s11_sgw_handle_create_session_request(
              &s11_sgw_stack_handle, pUlpApi);
      break;

    case NW_GTP_MODIFY_BEARER_REQ:
      ret = s11_sgw_handle_modify_bearer_request(
              &s11_sgw_stack_handle, pUlpApi);
      break;

    case NW_GTP_DELETE_SESSION_REQ:
      ret = s11_sgw_handle_delete_session_request(
              &s11_sgw_stack_handle, pUlpApi);
      break;

    default:
      S11_WARN("Received unhandled message type %d\n",
               pUlpApi->apiInfo.initialReqIndInfo.msgType);
      break;
    }

    break;

  default:
    S11_ERROR("Received unknown stack req message %d\n",
              pUlpApi->apiType);
    break;
  }

  return ret == -1 ? NW_FAILURE : NW_OK;
}
int s11_sgw_handle_create_session_request(NwGtpv2cStackHandleT *stack_p,
                                          NwGtpv2cUlpApiT      *pUlpApi)
{
    NwRcT  rc = NW_OK;
    NwU8T  offendingIeType, offendingIeInstance;
    NwU16T offendingIeLength;

    SgwCreateSessionRequest *create_session_request_p;
    MessageDef              *message_p;

    NwGtpv2cMsgParserT *pMsgParser;

    DevAssert(stack_p != NULL);

    message_p = itti_alloc_new_message(TASK_S11, SGW_CREATE_SESSION_REQUEST);

    create_session_request_p = &message_p->ittiMsg.sgwCreateSessionRequest;

    /* Create a new message parser */
    rc = nwGtpv2cMsgParserNew(*stack_p, NW_GTP_CREATE_SESSION_REQ,
                              s11_ie_indication_generic,
                              NULL, &pMsgParser);
    DevAssert(NW_OK == rc);

    /* Imsi IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_IMSI,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_CONDITIONAL,
                                s11_imsi_ie_get,
                                &create_session_request_p->imsi);
    DevAssert(NW_OK == rc);

    /* MSISDN IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_MSISDN,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_CONDITIONAL,
                                s11_msisdn_ie_get,
                                &create_session_request_p->msisdn);
    DevAssert(NW_OK == rc);

    /* MEI IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_MEI,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_CONDITIONAL,
                                s11_mei_ie_get,
                                &create_session_request_p->mei);
    DevAssert(NW_OK == rc);

    /* ULI IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_ULI,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_CONDITIONAL,
                                s11_uli_ie_get,
                                &create_session_request_p->uli);
    DevAssert(NW_OK == rc);

    /* Serving Network IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_SERVING_NETWORK,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_CONDITIONAL,
                                s11_serving_network_ie_get,
                                &create_session_request_p->serving_network);
    DevAssert(NW_OK == rc);

    /* RAT Type IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_RAT_TYPE,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_MANDATORY,
                                s11_rat_type_ie_get,
                                &create_session_request_p->rat_type);
    DevAssert(NW_OK == rc);

    /* Indication Flags IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_INDICATION,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_CONDITIONAL,
                                s11_indication_flags_ie_get,
                                &create_session_request_p->indication_flags);
    DevAssert(NW_OK == rc);

    /* APN IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_APN,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_MANDATORY,
                                s11_apn_ie_get, &create_session_request_p->apn);
    DevAssert(NW_OK == rc);

    /* Selection Mode IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_SELECTION_MODE,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_CONDITIONAL,
                                s11_ie_indication_generic, NULL);
    DevAssert(NW_OK == rc);

    /* PDN Type IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_PDN_TYPE,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_CONDITIONAL,
                                s11_pdn_type_ie_get, &create_session_request_p->pdn_type);
    DevAssert(NW_OK == rc);

    /* PAA IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_PAA,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_CONDITIONAL,
                                s11_paa_ie_get, &create_session_request_p->paa);
    DevAssert(NW_OK == rc);

    /* Sender FTEID for CP IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_FTEID,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_MANDATORY,
                                s11_fteid_ie_get,
                                &create_session_request_p->sender_fteid_for_cp);
    DevAssert(NW_OK == rc);

    /* PGW FTEID for CP IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_FTEID,
                                NW_GTPV2C_IE_INSTANCE_ONE,
                                NW_GTPV2C_IE_PRESENCE_CONDITIONAL,
                                s11_fteid_ie_get,
                                &create_session_request_p->pgw_address_for_cp);
    DevAssert(NW_OK == rc);

    /* APN Restriction IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_APN_RESTRICTION,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_CONDITIONAL,
                                s11_ie_indication_generic, NULL);
    DevAssert(NW_OK == rc);

    /* Bearer Context IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_BEARER_CONTEXT,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_MANDATORY,
                                s11_bearer_context_ie_get,
                                &create_session_request_p->bearer_to_create);
    DevAssert(NW_OK == rc);

    /* AMBR IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_AMBR,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_CONDITIONAL,
                                s11_ambr_ie_get,
                                &create_session_request_p->ambr);
    DevAssert(NW_OK == rc);

    /* Recovery IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_RECOVERY,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_MANDATORY,
                                s11_ie_indication_generic, NULL);
    DevAssert(NW_OK == rc);

    create_session_request_p->teid    = nwGtpv2cMsgGetTeid(pUlpApi->hMsg);
    create_session_request_p->trxn    = (void*)pUlpApi->apiInfo.initialReqIndInfo.hTrxn;
    create_session_request_p->peer_ip = pUlpApi->apiInfo.initialReqIndInfo.peerIp;

    rc = nwGtpv2cMsgParserRun(pMsgParser,
                              pUlpApi->hMsg,
                              &offendingIeType,
                              &offendingIeInstance,
                              &offendingIeLength);
    if (rc != NW_OK)
    {
        gtp_cause_t cause;

        NwGtpv2cUlpApiT     ulp_req;

        memset(&ulp_req, 0, sizeof(NwGtpv2cUlpApiT));
        memset(&cause  , 0, sizeof(gtp_cause_t));

        cause.offending_ie_type     = offendingIeType;
        cause.offending_ie_length   = offendingIeLength;
        cause.offending_ie_instance = offendingIeInstance;

        switch (rc)
        {
            case NW_GTPV2C_MANDATORY_IE_MISSING:
                S11_DEBUG("Mandatory IE type '%u' of instance '%u' missing!\n",
                          offendingIeType, offendingIeLength);
                cause.cause_value = NW_GTPV2C_CAUSE_MANDATORY_IE_MISSING;
                break;
            default:
                S11_DEBUG("Unknown message parse error!\n");
                cause.cause_value = 0;
                break;
        }

        /*
         * Send Create session response with failure to Gtpv2c Stack Instance
         */
        ulp_req.apiType = NW_GTPV2C_ULP_API_TRIGGERED_RSP;

        ulp_req.apiInfo.triggeredRspInfo.hTrxn = pUlpApi->apiInfo.initialReqIndInfo.hTrxn;

        rc = nwGtpv2cMsgNew(*stack_p,
                             NW_TRUE,
                             NW_GTP_CREATE_SESSION_RSP,
                             0,
                             nwGtpv2cMsgGetSeqNumber(pUlpApi->hMsg),
                            &(ulp_req.hMsg));

        s11_cause_ie_set(&(ulp_req.hMsg), &cause);

        S11_DEBUG("Received NW_GTP_CREATE_SESSION_REQ, Sending NW_GTP_CREATE_SESSION_RSP!\n");
        rc = nwGtpv2cProcessUlpReq(*stack_p, &ulp_req);
        DevAssert(NW_OK == rc);

        itti_free(ITTI_MSG_ORIGIN_ID(message_p), message_p);
        message_p = NULL;

        rc = nwGtpv2cMsgParserDelete(*stack_p, pMsgParser);
        DevAssert(NW_OK == rc);

        rc = nwGtpv2cMsgDelete(*stack_p, (pUlpApi->hMsg));
        DevAssert(NW_OK == rc);

        return 0;
    }

    rc = nwGtpv2cMsgParserDelete(*stack_p, pMsgParser);
    DevAssert(NW_OK == rc);

    rc = nwGtpv2cMsgDelete(*stack_p, (pUlpApi->hMsg));
    DevAssert(NW_OK == rc);

    return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
}
int s11_sgw_handle_delete_session_request(NwGtpv2cStackHandleT *stack_p,
                                          NwGtpv2cUlpApiT      *pUlpApi)
{
    NwRcT  rc = NW_OK;
    NwU8T  offendingIeType, offendingIeInstance;
    NwU16T offendingIeLength;

    SgwDeleteSessionRequest *delete_session_request_p;
    MessageDef              *message_p;

    NwGtpv2cMsgParserT *pMsgParser;

    DevAssert(stack_p != NULL);

    message_p = itti_alloc_new_message(TASK_S11, SGW_DELETE_SESSION_REQUEST);

    delete_session_request_p = &message_p->ittiMsg.sgwDeleteSessionRequest;

    /* Create a new message parser */
    rc = nwGtpv2cMsgParserNew(*stack_p, NW_GTP_DELETE_SESSION_REQ,
                              s11_ie_indication_generic,
                              NULL, &pMsgParser);
    DevAssert(NW_OK == rc);

    /* MME FTEID for CP IE */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_FTEID,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_OPTIONAL,
                                s11_fteid_ie_get,
                                &delete_session_request_p->sender_fteid_for_cp);
    DevAssert(NW_OK == rc);

    /* Linked EPS Bearer Id IE
     * This information element shall not be present for TAU/RAU/Handover with
     * S-GW relocation procedures.
     */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_EBI,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_OPTIONAL,
                                s11_ebi_ie_get,
                                &delete_session_request_p->lbi);
    DevAssert(NW_OK == rc);

    /* Indication Flags IE
     * For a Delete Session Request on S11 interface,
     * only the Operation Indication flag might be present.
     */
    rc = nwGtpv2cMsgParserAddIe(pMsgParser, NW_GTPV2C_IE_INDICATION,
                                NW_GTPV2C_IE_INSTANCE_ZERO,
                                NW_GTPV2C_IE_PRESENCE_CONDITIONAL,
                                s11_indication_flags_ie_get,
                                &delete_session_request_p->indication_flags);
    DevAssert(NW_OK == rc);

    delete_session_request_p->teid    = nwGtpv2cMsgGetTeid(pUlpApi->hMsg);
    delete_session_request_p->trxn    = (void*)pUlpApi->apiInfo.initialReqIndInfo.hTrxn;
    delete_session_request_p->peer_ip = pUlpApi->apiInfo.initialReqIndInfo.peerIp;

    rc = nwGtpv2cMsgParserRun(pMsgParser,
                              pUlpApi->hMsg,
                              &offendingIeType,
                              &offendingIeInstance,
                              &offendingIeLength);
    if (rc != NW_OK) {
        NwGtpv2cUlpApiT     ulp_req;
        gtp_cause_t         cause;

        memset(&ulp_req, 0, sizeof(NwGtpv2cUlpApiT));
        memset(&cause  , 0, sizeof(gtp_cause_t));

        cause.offending_ie_type     = offendingIeType;
        cause.offending_ie_length   = offendingIeLength;
        cause.offending_ie_instance = offendingIeInstance;

        switch (rc)
        {
            case NW_GTPV2C_MANDATORY_IE_MISSING:
                S11_DEBUG("Mandatory IE type '%u' of instance '%u' missing!\n",
                          offendingIeType, offendingIeLength);
                cause.cause_value = NW_GTPV2C_CAUSE_MANDATORY_IE_MISSING;
                break;
            default:
                S11_DEBUG("Unknown message parse error!\n");
                cause.cause_value = 0;
                break;
        }

        /*
         * Send Create session response with failure to Gtpv2c Stack Instance
         */
        ulp_req.apiType = NW_GTPV2C_ULP_API_TRIGGERED_RSP;

        ulp_req.apiInfo.triggeredRspInfo.hTrxn = pUlpApi->apiInfo.initialReqIndInfo.hTrxn;

        rc = nwGtpv2cMsgNew(*stack_p,
                             NW_TRUE,
                             NW_GTP_DELETE_SESSION_RSP,
                             0,
                             nwGtpv2cMsgGetSeqNumber(pUlpApi->hMsg),
                            &(ulp_req.hMsg));

        /* Adding the cause */
        s11_cause_ie_set(&(ulp_req.hMsg), &cause);

        S11_DEBUG("Received NW_GTP_DELETE_SESSION_REQ, Sending NW_GTP_DELETE_SESSION_RSP!\n");
        rc = nwGtpv2cProcessUlpReq(*stack_p, &ulp_req);
        DevAssert(NW_OK == rc);

        itti_free(ITTI_MSG_ORIGIN_ID(message_p), message_p);
        message_p = NULL;

        rc = nwGtpv2cMsgParserDelete(*stack_p, pMsgParser);
        DevAssert(NW_OK == rc);

        rc = nwGtpv2cMsgDelete(*stack_p, (pUlpApi->hMsg));
        DevAssert(NW_OK == rc);

        return 0;
    }

    rc = nwGtpv2cMsgParserDelete(*stack_p, pMsgParser);
    DevAssert(NW_OK == rc);

    rc = nwGtpv2cMsgDelete(*stack_p, (pUlpApi->hMsg));
    DevAssert(NW_OK == rc);

    return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
}
예제 #7
0
int s11_sgw_init(const mme_config_t *mme_config_p)
{
  int ret = 0;
  NwGtpv2cUlpEntityT      ulp;
  NwGtpv2cUdpEntityT      udp;
  NwGtpv2cTimerMgrEntityT tmrMgr;
  NwGtpv2cLogMgrEntityT   logMgr;
  struct in_addr addr;
  char *s11_address_str = NULL;

  S11_DEBUG("Initializing S11 interface\n");

  if (nwGtpv2cInitialize(&s11_sgw_stack_handle) != NW_OK) {
    S11_ERROR("Failed to initialize gtpv2-c stack\n");
    goto fail;
  }

  /* Set ULP entity */
  ulp.hUlp           = (NwGtpv2cUlpHandleT)NULL;
  ulp.ulpReqCallback = s11_sgw_ulp_process_stack_req_cb;
  DevAssert(NW_OK == nwGtpv2cSetUlpEntity(s11_sgw_stack_handle, &ulp));

  /* Set UDP entity */
  udp.hUdp               = (NwGtpv2cUdpHandleT)NULL;
  udp.udpDataReqCallback = s11_sgw_send_udp_msg;
  DevAssert(NW_OK == nwGtpv2cSetUdpEntity(s11_sgw_stack_handle, &udp));

  /* Set Timer entity */
  tmrMgr.tmrMgrHandle = (NwGtpv2cTimerMgrHandleT)NULL;
  tmrMgr.tmrStartCallback = s11_sgw_start_timer_wrapper;
  tmrMgr.tmrStopCallback  = s11_sgw_stop_timer_wrapper;
  DevAssert(NW_OK == nwGtpv2cSetTimerMgrEntity(s11_sgw_stack_handle, &tmrMgr));

  logMgr.logMgrHandle    = 0;
  logMgr.logReqCallback  = s11_sgw_log_wrapper;

  DevAssert(NW_OK == nwGtpv2cSetLogMgrEntity(s11_sgw_stack_handle, &logMgr));

  if (itti_create_task(TASK_S11, &s11_sgw_thread, NULL) < 0) {
    S11_ERROR("gtpv1u phtread_create: %s\n", strerror(errno));
    goto fail;
  }

  DevAssert(NW_OK == nwGtpv2cSetLogLevel(s11_sgw_stack_handle,
                                         NW_LOG_LEVEL_DEBG));

  config_read_lock(&mme_config);
  addr.s_addr = mme_config.ipv4.sgw_ip_address_for_S11;
  config_unlock(&mme_config);

  s11_address_str = inet_ntoa(addr);

  DevAssert(s11_address_str != NULL);

  s11_send_init_udp(s11_address_str, 2123);

  S11_DEBUG("Initializing S11 interface: DONE\n");

  return ret;

fail:
  S11_DEBUG("Initializing S11 interface: FAILURE\n");
  return -1;
}
예제 #8
0
static void *s11_sgw_thread(void *args)
{
  itti_mark_task_ready(TASK_S11);

  while(1) {
    MessageDef *received_message_p = NULL;
    itti_receive_msg(TASK_S11, &received_message_p);
    assert(received_message_p != NULL);

    switch (ITTI_MSG_ID(received_message_p)) {
    case UDP_DATA_IND: {
      /* We received new data to handle from the UDP layer */
      NwRcT rc;
      udp_data_ind_t *udp_data_ind;

      udp_data_ind = &received_message_p->ittiMsg.udp_data_ind;

      S11_DEBUG("Processing new data indication from UDP\n");

      rc = nwGtpv2cProcessUdpReq(s11_sgw_stack_handle,
                                 udp_data_ind->buffer,
                                 udp_data_ind->buffer_length,
                                 udp_data_ind->peer_port,
                                 udp_data_ind->peer_address);

      DevAssert(rc == NW_OK);
    }
    break;

    case SGW_CREATE_SESSION_RESPONSE: {
      S11_DEBUG("Received create session response from S-PGW APP\n");
      s11_sgw_handle_create_session_response(
        &s11_sgw_stack_handle,
        &received_message_p->ittiMsg.sgwCreateSessionResponse);
    }
    break;

    case SGW_MODIFY_BEARER_RESPONSE: {
      S11_DEBUG("Received modify bearer response from S-PGW APP\n");
      s11_sgw_handle_modify_bearer_response(
        &s11_sgw_stack_handle,
        &received_message_p->ittiMsg.sgwModifyBearerResponse);
    }
    break;

    case SGW_DELETE_SESSION_RESPONSE: {
      S11_DEBUG("Received delete session response from S-PGW APP\n");
      s11_sgw_handle_delete_session_response(
        &s11_sgw_stack_handle,
        &received_message_p->ittiMsg.sgwDeleteSessionResponse);
    }
    break;

    case TIMER_HAS_EXPIRED: {
      S11_DEBUG("Processing timeout for timer_id 0x%lx and arg %p\n",
                received_message_p->ittiMsg.timer_has_expired.timer_id,
                received_message_p->ittiMsg.timer_has_expired.arg);
      DevAssert(nwGtpv2cProcessTimeout(received_message_p->ittiMsg.timer_has_expired.arg) == NW_OK);
    }
    break;

    default: {
      S11_ERROR("Unkwnon message ID %d:%s\n",
                ITTI_MSG_ID(received_message_p), ITTI_MSG_NAME(received_message_p));
    }
    break;
    }

    itti_free(ITTI_MSG_ORIGIN_ID(received_message_p), received_message_p);
    received_message_p = NULL;
  }

  return NULL;
}