void
recv_callback (
  uint8_t * buffer,
  uint32_t length)
{
  uint8_t                                *bufferS;
  uint32_t                                len;

  s1ap_eNB_generate_initial_ue_message (&bufferS, &len);
  sctp_send_msg (assoc[0], 1, bufferS, len);
}
Esempio n. 2
0
int s1ap_eNB_new_data_request(uint8_t eNB_id, uint8_t ue_id, uint8_t *buffer, uint32_t length) {
    s1ap_message message;
    struct s1ap_eNB_UE_description_s *ue_ref;
    struct s1ap_eNB_description_s *eNB_ref;

    /* If we don't found the eNB as S1 associated, this may indicate that no S1 Setup Request has been sent,
     * or S1 Setup has failed.
     */
    if ((eNB_ref = s1ap_get_eNB_eNB_id(eNB_id)) == NULL) {
        S1AP_ERROR("This eNB (%d) has no known S1 association with any MME\n", eNB_id);
        return -1;
    }

    ///TODO: Check if eNB is associated to a MME

    /* Searching for UE in eNB.
     * If we failed founding it, request a new initial UE message to MME.
     */
    if ((ue_ref = s1ap_get_ue_id_pair(eNB_id, ue_id)) == NULL) {
        if ((ue_ref = s1ap_UE_add_new(eNB_ref)) == NULL) {
            /* We failed to allocate a new UE in list */
            S1AP_ERROR("Failed to allocate new UE description for UE %d attached to eNB %d\n",
                  ue_id, eNB_id);
            return -1;
        }
        ue_ref->eNB_UE_s1ap_id = ue_id;
        /* MME UE S1AP ID is allocated by MME, waiting for Initial Context Setup Request Message
         * before setting it.
         */
        ue_ref->mme_UE_s1ap_id = 0;
        ue_ref->eNB->nextstream++;
        /* Do we reached max number of output streams ?.
         * If so wrap to 1.
         */
        if (ue_ref->eNB->nextstream == ue_ref->eNB->outstreams)
            ue_ref->eNB->nextstream = 1;

        /* Set the output stream that will be used for this UE */
        ue_ref->stream_send = ue_ref->eNB->nextstream;

        S1AP_ERROR("Sending Initial UE message for UE %d on eNB %d\n",
              ue_id, eNB_id);

        return s1ap_eNB_generate_initial_ue_message(ue_ref, buffer, length);
    } else {
        /* UE is already associated to a valid Context.
         * Consider request as Uplink NAS transport.
         */
        S1AP_ERROR("Sending Uplink NAS transport message for UE %d on eNB %d\n",
              ue_id, eNB_id);
        return s1ap_eNB_generate_uplink_nas_transport(ue_ref, buffer, length);
    }
}