oaisim_mme_client_test.c 4.92 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

Cedric Roux's avatar
Cedric Roux committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#include <arpa/inet.h>

#include "sctp_primitives_client.h"

#include "s1ap_common.h"
#include "s1ap_eNB.h"
#include "s1ap_mme.h"
#include "s1ap_ies_defs.h"

char ip_addr[] = "127.0.0.1";

int assoc[2];
uint8_t id[] = { 0x03, 0x56, 0xf0, 0xd8 };
char identity[] = { 0x02, 0x08, 0x34 };
char tac[] = { 0x00, 0x01 };
char infoNAS[] = { 0x07, 0x42, 0x01, 0xE0, 0x06, 0x00, 0x00, 0xF1, 0x10, 0x00, 0x01, 0x00, 0x2C,
                   0x52, 0x01, 0xC1, 0x01, 0x09, 0x10, 0x03, 0x77, 0x77, 0x77, 0x07, 0x61, 0x6E, 0x72, 0x69, 0x74,
                   0x73, 0x75, 0x03, 0x63, 0x6F, 0x6D, 0x05, 0x01, 0x0A, 0x01, 0x20, 0x37, 0x27, 0x0E, 0x80, 0x80,
                   0x21, 0x0A, 0x03, 0x00, 0x00, 0x0A, 0x81, 0x06, 0x0A, 0x00, 0x00, 0x01, 0x50, 0x0B, 0xF6,
                   0x00, 0xF1, 0x10, 0x80, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01
                 };

uint32_t eNB_UE_S1AP_ID = 0;

int s1ap_eNB_generate_initial_ue_message(uint8_t **buffer,
56
    uint32_t *length);
Cedric Roux's avatar
Cedric Roux committed
57 58

int s1ap_eNB_generate_initial_ue_message(uint8_t **buffer,
59
    uint32_t *length)
Cedric Roux's avatar
Cedric Roux committed
60
{
61 62
  InitialUEMessageIEs  initialUEmessageIEs;
  InitialUEMessageIEs *initialUEmessageIEs_p = &initialUEmessageIEs;
Cedric Roux's avatar
Cedric Roux committed
63

64
  memset(initialUEmessageIEs_p, 0, sizeof(InitialUEMessageIEs));
Cedric Roux's avatar
Cedric Roux committed
65

66 67 68
  initialUEmessageIEs.eNB_UE_S1AP_ID = eNB_UE_S1AP_ID;
  initialUEmessageIEs.nas_pdu.buf = infoNAS;
  initialUEmessageIEs.nas_pdu.size = sizeof(infoNAS);
Cedric Roux's avatar
Cedric Roux committed
69

70 71 72 73 74 75 76 77 78
  initialUEmessageIEs.tai.tAC.buf = tac;
  initialUEmessageIEs.tai.tAC.size = 2;
  initialUEmessageIEs.tai.pLMNidentity.buf = identity;
  initialUEmessageIEs.tai.pLMNidentity.size = 3;
  initialUEmessageIEs.eutran_cgi.pLMNidentity.buf = identity;
  initialUEmessageIEs.eutran_cgi.pLMNidentity.size = 3;
  initialUEmessageIEs.eutran_cgi.cell_ID.buf = id;
  initialUEmessageIEs.eutran_cgi.cell_ID.size = 4;
  initialUEmessageIEs.eutran_cgi.cell_ID.bits_unused = 4;
Cedric Roux's avatar
Cedric Roux committed
79

80
  initialUEmessageIEs.rrC_Establishment_Cause = RRC_Establishment_Cause_mo_Data;
Cedric Roux's avatar
Cedric Roux committed
81

82
  return s1ap_eNB_encode_initial_ue_message(initialUEmessageIEs_p, buffer, length);
Cedric Roux's avatar
Cedric Roux committed
83 84 85 86
}

void recv_callback(uint8_t *buffer, uint32_t length)
{
87 88 89 90
  uint8_t *bufferS;
  uint32_t len;
  s1ap_eNB_generate_initial_ue_message(&bufferS, &len);
  sctp_send_msg(assoc[0], 1, bufferS, len);
Cedric Roux's avatar
Cedric Roux committed
91 92 93 94
}

int main(int argc, char *argv[])
{
95 96 97
  asn_enc_rval_t retVal;
  uint8_t *buffer;
  uint32_t len;
Cedric Roux's avatar
Cedric Roux committed
98

99 100
  SupportedTAs_Item_t ta;
  PLMNidentity_t plmnIdentity;
Cedric Roux's avatar
Cedric Roux committed
101

102 103
  asn_debug = 0;
  asn1_xer_print = 0;
Cedric Roux's avatar
Cedric Roux committed
104

105 106 107 108 109 110 111
  S1SetupRequestIEs s1SetupRequest;
  memset(&s1SetupRequest, 0, sizeof(S1SetupRequestIEs));
  s1SetupRequest.global_ENB_ID.eNB_ID.present = ENB_ID_PR_macroENB_ID;
  s1SetupRequest.global_ENB_ID.eNB_ID.choice.macroENB_ID.buf = id;
  s1SetupRequest.global_ENB_ID.eNB_ID.choice.macroENB_ID.size = 3;
  s1SetupRequest.global_ENB_ID.eNB_ID.choice.macroENB_ID.bits_unused = 4;
  OCTET_STRING_fromBuf(&s1SetupRequest.global_ENB_ID.pLMNidentity, identity, 3);
Cedric Roux's avatar
Cedric Roux committed
112

113 114 115
  s1SetupRequest.presenceMask |= S1SETUPREQUESTIES_ENBNAME_PRESENT;
  OCTET_STRING_fromBuf(&s1SetupRequest.eNBname, "ENB 1 eurecom",
                       strlen("ENB 1 eurecom"));
Cedric Roux's avatar
Cedric Roux committed
116

117 118 119 120 121 122
  memset(&ta, 0, sizeof(SupportedTAs_Item_t));
  memset(&plmnIdentity, 0, sizeof(PLMNidentity_t));
  OCTET_STRING_fromBuf(&ta.tAC, tac, 2);
  OCTET_STRING_fromBuf(&plmnIdentity, identity, 3);
  ASN_SEQUENCE_ADD(&ta.broadcastPLMNs, &plmnIdentity);
  ASN_SEQUENCE_ADD(&s1SetupRequest.supportedTAs, &ta);
Cedric Roux's avatar
Cedric Roux committed
123

124
  s1SetupRequest.defaultPagingDRX = PagingDRX_v64;
Cedric Roux's avatar
Cedric Roux committed
125

126
  s1ap_eNB_encode_s1setuprequest(&s1SetupRequest, &buffer, &len);
Cedric Roux's avatar
Cedric Roux committed
127

128 129
  assoc[0] = sctp_connect_to_remote_host(ip_addr, 36412, &recv_callback);
  sctp_send_msg(0, 0, buffer, len);
Cedric Roux's avatar
Cedric Roux committed
130

131
  free(buffer);
Cedric Roux's avatar
Cedric Roux committed
132

133 134 135
  //     generateUplinkNASTransport(&buffer, &len);
  //     sctp_send_msg(assoc[0], 0, buffer, len);
  //     s1ap_mme_decode_pdu(buffer, len);
Cedric Roux's avatar
Cedric Roux committed
136

137
  pthread_join(sctp_get_receiver_thread(assoc[0]), NULL);
Cedric Roux's avatar
Cedric Roux committed
138

139
  return(0);
Cedric Roux's avatar
Cedric Roux committed
140
}