Skip to content

Commit

Permalink
Aug 31 11:05AM
Browse files Browse the repository at this point in the history
  • Loading branch information
Sadagopan committed Aug 31, 2015
1 parent 875b31a commit 5fb31e1
Show file tree
Hide file tree
Showing 23 changed files with 362 additions and 310 deletions.
9 changes: 6 additions & 3 deletions Documentation
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
Problems facing so-far:

- Too many open files (For connections < 100)

Things to do:

- Encryption
- Integrity check
- Detach procedure
- Running program for a fixed amount of time
- Employing Distribution function
- Employing APN during registration

Doubts in the implementation:

Expand Down Expand Up @@ -84,7 +87,7 @@ When the authentication match was successful at the MME, the RAN is supposed to

MME to SGW:(Plain)
MME GTP-C TEID
UE IMSI
UE IMSI (UE NUM is made to send instead)
UE Bearer ID

Step-2:
Expand Down
1 change: 1 addition & 0 deletions client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Client::Client(){
report_error(client_socket);
client_addr = allocate_str_mem(INET_ADDRSTRLEN);
server_addr = allocate_str_mem(INET_ADDRSTRLEN);
setsockopt(client_socket, SOL_SOCKET, SO_REUSEADDR, &g_reuse, sizeof(int));
signal(SIGPIPE, SIG_IGN);
//status = 0;
//setsockopt(client_socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&g_timeout, sizeof(timeval));
Expand Down
13 changes: 5 additions & 8 deletions hss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ void* multithreading_func(void *arg){
hss.client_num = mme.num;
hss.connect_with_client();
hss.read_data();
memcpy(&type, hss.pkt.data, sizeof(int));
if(type == 1){
memcpy(&imsi, hss.pkt.data + sizeof(type), sizeof(imsi));
memcpy(&msisdn, hss.pkt.data + sizeof(type) + sizeof(imsi), sizeof(msisdn));
authenticate_query(imsi, msisdn, hss.pkt);
hss.pkt.make_data_packet();
hss.write_data();
}
memcpy(&imsi, hss.pkt.data, sizeof(unsigned long long));
memcpy(&msisdn, hss.pkt.data + sizeof(unsigned long long), sizeof(unsigned long long));
authenticate_query(imsi, msisdn, hss.pkt);
hss.pkt.make_data_packet();
hss.write_data();
mysql_thread_end();
}

Expand Down
212 changes: 208 additions & 4 deletions mme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,225 @@ MME::MME(){
reply = allocate_str_mem(BUFFER_SIZE);
}

void MME::set_ue_num(){
void MME::set_cteid(){

tun_data.mme_cteid = generate_cteid(ue_num);
}

uint16_t MME::generate_cteid(int &ue_number){

return ue_number;
}

void MME::set_cteid(){
void MME::set_bearer_id(){

cteid = generate_cteid(ue_num);
bearer_id = generate_bearer_id(ue_num);
}

uint16_t MME::generate_cteid(int &ue_number){
int MME::generate_bearer_id(int &ue_number){

return ue_number;
}

void MME::set_sgw(){

tun_data.sgw_port = g_sgw1_port;
strcpy(tun_data.sgw_addr, g_sgw1_addr);
}

void MME::set_pgw(){

tun_data.pgw_port = g_pgw_port;
strcpy(tun_data.pgw_addr, g_pgw_addr);
}

void MME::startup_mme_server(ClientDetails &entity){

mme_server.fill_server_details(g_freeport, g_mme_addr);
mme_server.bind_server();
mme_server.client_sock_addr = entity.client_sock_addr;
mme_server.client_num = ue_num;
mme_server.connect_with_client();
}

void MME::set_ue_num(){

ue_num = mme_server.client_num;
}

void MME::attach_req_from_ue(){

mme_server.read_data();
}

void MME::setup_hss_client(){

to_hss.bind_client();
to_hss.fill_server_details(g_hss_port, g_hss_addr);
to_hss.connect_with_server(ue_num);
}

void MME::fetch_ue_data(){

to_hss.pkt.clear_data();
to_hss.pkt.fill_data(0, mme_server.pkt.data_len, mme_server.pkt.data);
to_hss.pkt.make_data_packet();
to_hss.write_data();
to_hss.read_data();
memcpy(&autn_num, to_hss.pkt.data, sizeof(unsigned long long));
memcpy(&rand_num, to_hss.pkt.data + sizeof(unsigned long long), sizeof(unsigned long long));
memcpy(&autn_xres, to_hss.pkt.data + 2 * sizeof(unsigned long long), sizeof(unsigned long long));
}

void MME::authenticate_ue(){

mme_server.pkt.clear_data();
mme_server.pkt.fill_data(0, 2 * sizeof(unsigned long long), to_hss.pkt.data);
mme_server.pkt.make_data_packet();
mme_server.write_data();
mme_server.read_data();
memcpy(&autn_res, mme_server.pkt.data, sizeof(unsigned long long));
if(autn_xres == autn_res){
strcpy(reply, "OK");
mme_server.pkt.clear_data();
mme_server.pkt.fill_data(0, strlen(reply), reply);
mme_server.pkt.make_data_packet();
mme_server.write_data();
cout<<"Authentication is successful for UE - "<<ue_num<<endl;
}
else{
cout<<"Authentication failed: Please disconnect and connect again with proper authentication"<<endl;
handle_exceptions();
}
}

void MME::setup_sgw_client(){

to_sgw.bind_client();
to_sgw.fill_server_details(tun_data.sgw_port, tun_data.sgw_addr);
to_sgw.connect_with_server(ue_num);
}

void MME::create_session_req_to_sgw(){

type = 1;
to_sgw.pkt.clear_data();
to_sgw.pkt.fill_data(0, sizeof(int), type);
to_sgw.pkt.fill_data(sizeof(int), sizeof(int), ue_num);
to_sgw.pkt.fill_data(2 * sizeof(int), sizeof(int), bearer_id);
to_sgw.pkt.fill_data(3 * sizeof(int), sizeof(uint16_t), tun_data.mme_cteid);
to_sgw.pkt.make_data_packet();
to_sgw.write_data();
}

void MME::create_session_res_from_sgw(){

to_sgw.read_data();
to_sgw.pkt.rem_gtpc_hdr();
memcpy(&tun_data.sgw_cteid, to_sgw.pkt.data, sizeof(uint16_t));
memcpy(reply, to_sgw.pkt.data + sizeof(uint16_t), to_sgw.pkt.data_len - sizeof(uint16_t));
if(strcmp((const char*)reply, "OK") == 0){
cout<<"Create session request was successful for UE - "<<ue_num<<endl;
}
else{
cout<<"Create session request failed: Please disconnect and connect again"<<endl;
handle_exceptions();
}
}

void MME::recv_enodeb(){

mme_server.read_data();
memcpy(&tun_data.enodeb_uteid, mme_server.pkt.data, sizeof(uint16_t));
}

void MME::modify_session_req_to_sgw(){

to_sgw.pkt.clear_data();
to_sgw.pkt.fill_gtpc_hdr(tun_data.sgw_cteid);
to_sgw.pkt.fill_data(0, sizeof(uint16_t), tun_data.enodeb_uteid);
to_sgw.pkt.add_gtpc_hdr();
to_sgw.pkt.make_data_packet();
to_sgw.write_data();
}

void MME::modify_session_res_from_sgw(){

to_sgw.read_data();
to_sgw.pkt.rem_gtpc_hdr();
memcpy(&tun_data.sgw_uteid, to_sgw.pkt.data, sizeof(uint16_t));
memcpy(ue_ip, to_sgw.pkt.data + sizeof(uint16_t), INET_ADDRSTRLEN);
memcpy(reply, to_sgw.pkt.data + sizeof(uint16_t) + INET_ADDRSTRLEN, to_sgw.pkt.data_len - sizeof(uint16_t) - INET_ADDRSTRLEN);
if(strcmp((const char*)reply, "OK") == 0){
cout<<"Modify Session Request was successful for UE - "<<ue_num<<endl;
}
else{
cout<<"Modify session request failed: Please disconnect and connect again"<<endl;
handle_exceptions();
}
}

void MME::send_enodeb(){

mme_server.pkt.clear_data();
mme_server.pkt.fill_data(0, sizeof(uint16_t), tun_data.sgw_uteid);
mme_server.pkt.fill_data(sizeof(uint16_t), INET_ADDRSTRLEN, ue_ip);
mme_server.pkt.make_data_packet();
mme_server.write_data();
}

void MME::detach_req_from_ue(){

mme_server.read_data();
memcpy(&type, mme_server.pkt.data, sizeof(int));
if(type == 3){
cout<<"Detach request has been received successfully at MME for UE - "<<ue_num<<endl;
}
else{
cout<<"Invalid Detach type num: Please disconnect and connect again"<<endl;
handle_exceptions();
}
}

void MME::delete_session_req_to_sgw(){

to_sgw.pkt.clear_data();
to_sgw.pkt.fill_data(0, mme_server.pkt.data_len, mme_server.pkt.data);
to_sgw.pkt.fill_gtpc_hdr(tun_data.sgw_cteid);
to_sgw.pkt.add_gtpc_hdr();
to_sgw.pkt.make_data_packet();
to_sgw.write_data();
}

void MME::delete_session_res_from_sgw(){

to_sgw.read_data();
to_sgw.pkt.rem_gtpc_hdr();
memcpy(reply, to_sgw.pkt.data, to_sgw.pkt.data_len);
if(strcmp((const char*)reply, "OK") == 0){
cout<<"MME has received successful detach response for UE - "<<ue_num<<endl;
}
else{
cout<<"Detach process failure at SGW: Please disconnect and connect again"<<endl;
handle_exceptions();
}
}

void MME::detach_res_to_ue(){

strcpy(reply, "OK");
mme_server.pkt.clear_data();
mme_server.pkt.fill_data(0, strlen(reply), reply);
mme_server.pkt.make_data_packet();
mme_server.write_data();
cout<<"MME has successfully deallocated resources for UE - "<<ue_num<<endl;
}

void MME::rem_bearer_id(){

bearer_id = -1; // Dummy statement
}

MME::~MME(){

free(ue_ip);
Expand Down
43 changes: 39 additions & 4 deletions mme.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@

#include "utils.h"
#include "packet.h"
#include "server.h"
#include "thread_pool.h"
#include "client.h"

struct TunData{
uint16_t mme_cteid;
uint16_t sgw_cteid;
uint16_t sgw_uteid;
uint16_t enodeb_uteid;
int sgw_port;
int pgw_port;
char *sgw_addr;
Expand All @@ -15,18 +21,47 @@ struct TunData{
~TunData();
};

struct MME{
uint16_t cteid;
struct MME{
Server mme_server;
Client to_hss;
Client to_sgw;
int ue_num;
int bearer_id;
int type;
char *ue_ip;
char *reply;
unsigned long long autn_num;
unsigned long long rand_num;
unsigned long long autn_xres;
unsigned long long autn_res;
TunData tun_data;

MME();
void set_ue_num();
void set_cteid();
uint16_t generate_cteid(int&);
void set_bearer_id();
int generate_bearer_id(int&);
void set_sgw();
void set_pgw();
void startup_mme_server(ClientDetails&);
void set_ue_num();
void attach_req_from_ue();
void setup_hss_client();
void fetch_ue_data();
void authenticate_ue();
void setup_sgw_client();
void create_session_req_to_sgw();
void create_session_res_from_sgw();
void recv_enodeb();
void modify_session_req_to_sgw();
void modify_session_res_from_sgw();
void send_enodeb();
void detach_req_from_ue();
void delete_session_req_to_sgw();
void delete_session_res_from_sgw();
void detach_res_to_ue();
void rem_bearer_id();
~MME();
};


#endif //MME_H
Loading

0 comments on commit 5fb31e1

Please sign in to comment.