| 1 |
#define TRACE_MODULE _sgw_s11_handler |
| 2 |
|
| 3 |
#include "core_debug.h" |
| 4 |
#include "core_lib.h" |
| 5 |
|
| 6 |
#include "gtp/gtp_types.h" |
| 7 |
#include "gtp/gtp_conv.h" |
| 8 |
#include "gtp/gtp_node.h" |
| 9 |
#include "gtp/gtp_path.h" |
| 10 |
|
| 11 |
#include "common/context.h" |
| 12 |
#include "sgw_event.h" |
| 13 |
#include "sgw_context.h" |
| 14 |
#include "sgw_gtp_path.h" |
| 15 |
#include "sgw_s11_handler.h" |
| 16 |
|
| 17 |
void sgw_s11_handle_create_session_request( |
| 18 |
gtp_xact_t *s11_xact, sgw_ue_t *sgw_ue, gtp_message_t *gtp_message) |
| 19 |
{ |
| 20 |
status_t rv; |
| 21 |
c_uint16_t decoded; |
| 22 |
gtp_create_session_request_t *req = NULL; |
| 23 |
pkbuf_t *pkbuf = NULL; |
| 24 |
gtp_f_teid_t *mme_s11_teid = NULL; |
| 25 |
gtp_f_teid_t *pgw_s5c_teid = NULL; |
| 26 |
int len = 0; |
| 27 |
gtp_node_t *pgw = NULL; |
| 28 |
gtp_f_teid_t sgw_s5c_teid, sgw_s5u_teid; |
| 29 |
gtp_uli_t uli; |
| 30 |
|
| 31 |
gtp_xact_t *s5c_xact = NULL; |
| 32 |
sgw_sess_t *sess = NULL; |
| 33 |
sgw_bearer_t *bearer = NULL; |
| 34 |
sgw_tunnel_t *s5u_tunnel = NULL; |
| 35 |
|
| 36 |
d_assert(s11_xact, return, "Null param"); |
| 37 |
d_assert(gtp_message, return, "Null param"); |
| 38 |
|
| 39 |
req = >p_message->create_session_request; |
| 40 |
|
| 41 |
d_trace(3, "[SGW] Create Session Reqeust\n"); |
| 42 |
if (req->bearer_contexts_to_be_created.presence == 0) |
| 43 |
{ |
| 44 |
d_error("No Bearer"); |
| 45 |
return; |
| 46 |
} |
| 47 |
if (req->bearer_contexts_to_be_created.eps_bearer_id.presence == 0) |
| 48 |
{ |
| 49 |
d_error("No EPS Bearer ID"); |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
d_assert(sgw_ue, return, "Null param"); |
| 54 |
sess = sgw_sess_find_by_ebi(sgw_ue, |
| 55 |
req->bearer_contexts_to_be_created.eps_bearer_id.u8); |
| 56 |
if (!sess) |
| 57 |
{ |
| 58 |
c_int8_t apn[MAX_APN_LEN]; |
| 59 |
|
| 60 |
if (req->access_point_name.presence == 0) |
| 61 |
{ |
| 62 |
d_error("No APN"); |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
apn_parse(apn, req->access_point_name.data, req->access_point_name.len); |
| 67 |
sess = sgw_sess_add(sgw_ue, apn, |
| 68 |
req->bearer_contexts_to_be_created.eps_bearer_id.u8); |
| 69 |
d_assert(sess, return, "Null param"); |
| 70 |
} |
| 71 |
|
| 72 |
if (req->sender_f_teid_for_control_plane.presence == 0) |
| 73 |
{ |
| 74 |
d_error("No Sender F-TEID"); |
| 75 |
return; |
| 76 |
} |
| 77 |
if (req->pgw_s5_s8_address_for_control_plane_or_pmip.presence == 0) |
| 78 |
{ |
| 79 |
d_error("No PGW IP"); |
| 80 |
return; |
| 81 |
} |
| 82 |
if (req->user_location_information.presence == 0) |
| 83 |
{ |
| 84 |
d_error("No User Location Inforamtion"); |
| 85 |
return; |
| 86 |
} |
| 87 |
|
| 88 |
d_assert(sess, return, "Null param"); |
| 89 |
bearer = sgw_default_bearer_in_sess(sess); |
| 90 |
d_assert(bearer, return, "Null param"); |
| 91 |
s5u_tunnel = sgw_s5u_tunnel_in_bearer(bearer); |
| 92 |
d_assert(s5u_tunnel, return, "Null param"); |
| 93 |
|
| 94 |
/* Receive Control Plane(DL) : MME-S11 */ |
| 95 |
mme_s11_teid = req->sender_f_teid_for_control_plane.data; |
| 96 |
d_assert(mme_s11_teid, return, "Null param"); |
| 97 |
sgw_ue->mme_s11_teid = ntohl(mme_s11_teid->teid); |
| 98 |
|
| 99 |
/* Send Control Plane(DL) : SGW-S5C */ |
| 100 |
memset(&sgw_s5c_teid, 0, sizeof(gtp_f_teid_t)); |
| 101 |
sgw_s5c_teid.interface_type = GTP_F_TEID_S5_S8_SGW_GTP_C; |
| 102 |
sgw_s5c_teid.teid = htonl(sess->sgw_s5c_teid); |
| 103 |
rv = gtp_sockaddr_to_f_teid( |
| 104 |
sgw_self()->gtpc_addr, sgw_self()->gtpc_addr6, &sgw_s5c_teid, &len); |
| 105 |
d_assert(rv == CORE_OK, return,); |
| 106 |
req->sender_f_teid_for_control_plane.presence = 1; |
| 107 |
req->sender_f_teid_for_control_plane.data = &sgw_s5c_teid; |
| 108 |
req->sender_f_teid_for_control_plane.len = len; |
| 109 |
|
| 110 |
d_trace(5, " MME_S11_TEID[%d] SGW_S11_TEID[%d]\n", |
| 111 |
sgw_ue->mme_s11_teid, sgw_ue->sgw_s11_teid); |
| 112 |
d_trace(5, " SGW_S5C_TEID[0x%x] PGW_S5C_TEID[0x%x]\n", |
| 113 |
sess->sgw_s5c_teid, sess->pgw_s5c_teid); |
| 114 |
d_trace(5, " SGW_S5U_TEID[%d] PGW_S5U_TEID[%d]\n", |
| 115 |
s5u_tunnel->local_teid, s5u_tunnel->remote_teid); |
| 116 |
|
| 117 |
pgw_s5c_teid = req->pgw_s5_s8_address_for_control_plane_or_pmip.data; |
| 118 |
d_assert(pgw_s5c_teid, return, "Null param"); |
| 119 |
|
| 120 |
pgw = gtp_find_node(&sgw_self()->pgw_s5c_list, pgw_s5c_teid); |
| 121 |
if (!pgw) |
| 122 |
{ |
| 123 |
pgw = gtp_add_node_with_teid(&sgw_self()->pgw_s5c_list, pgw_s5c_teid, |
| 124 |
sgw_self()->gtpc_port, |
| 125 |
context_self()->parameter.no_ipv4, |
| 126 |
context_self()->parameter.no_ipv6, |
| 127 |
context_self()->parameter.prefer_ipv4); |
| 128 |
d_assert(pgw, return,); |
| 129 |
|
| 130 |
rv = gtp_client(pgw); |
| 131 |
d_assert(rv == CORE_OK, return,); |
| 132 |
} |
| 133 |
/* Setup GTP Node */ |
| 134 |
SETUP_GTP_NODE(sess, pgw); |
| 135 |
|
| 136 |
/* Remove PGW-S5C */ |
| 137 |
req->pgw_s5_s8_address_for_control_plane_or_pmip.presence = 0; |
| 138 |
|
| 139 |
/* Data Plane(DL) : SGW-S5U */ |
| 140 |
memset(&sgw_s5u_teid, 0, sizeof(gtp_f_teid_t)); |
| 141 |
sgw_s5u_teid.teid = htonl(s5u_tunnel->local_teid); |
| 142 |
sgw_s5u_teid.interface_type = GTP_F_TEID_S5_S8_SGW_GTP_U; |
| 143 |
rv = gtp_sockaddr_to_f_teid( |
| 144 |
sgw_self()->gtpu_addr, sgw_self()->gtpu_addr6, &sgw_s5u_teid, &len); |
| 145 |
d_assert(rv == CORE_OK, return,); |
| 146 |
req->bearer_contexts_to_be_created.s5_s8_u_sgw_f_teid.presence = 1; |
| 147 |
req->bearer_contexts_to_be_created.s5_s8_u_sgw_f_teid.data = &sgw_s5u_teid; |
| 148 |
req->bearer_contexts_to_be_created.s5_s8_u_sgw_f_teid.len = len; |
| 149 |
|
| 150 |
/* Set User Location Information */ |
| 151 |
decoded = gtp_parse_uli(&uli, &req->user_location_information); |
| 152 |
d_assert(req->user_location_information.len == decoded, return,); |
| 153 |
memcpy(&bearer->tai.plmn_id, &uli.tai.plmn_id, sizeof(uli.tai.plmn_id)); |
| 154 |
bearer->tai.tac = uli.tai.tac; |
| 155 |
memcpy(&bearer->e_cgi.plmn_id, &uli.e_cgi.plmn_id, sizeof(uli.e_cgi.plmn_id)); |
| 156 |
bearer->e_cgi.cell_id = uli.e_cgi.cell_id; |
| 157 |
|
| 158 |
gtp_message->h.type = GTP_CREATE_SESSION_REQUEST_TYPE; |
| 159 |
gtp_message->h.teid = sess->pgw_s5c_teid; |
| 160 |
|
| 161 |
rv = gtp_build_msg(&pkbuf, gtp_message); |
| 162 |
d_assert(rv == CORE_OK, return, "gtp build failed"); |
| 163 |
|
| 164 |
s5c_xact = gtp_xact_local_create(sess->gnode, >p_message->h, pkbuf); |
| 165 |
d_assert(s5c_xact, return, "Null param"); |
| 166 |
|
| 167 |
gtp_xact_associate(s11_xact, s5c_xact); |
| 168 |
|
| 169 |
rv = gtp_xact_commit(s5c_xact); |
| 170 |
d_assert(rv == CORE_OK, return, "xact_commit error"); |
| 171 |
} |
| 172 |
|
| 173 |
CORE_DECLARE(void) sgw_s11_handle_modify_bearer_request(gtp_xact_t *s11_xact, |
| 174 |
sgw_ue_t *sgw_ue, gtp_modify_bearer_request_t *req) |
| 175 |
{ |
| 176 |
status_t rv; |
| 177 |
char buf[CORE_ADDRSTRLEN]; |
| 178 |
|
| 179 |
c_uint16_t decoded; |
| 180 |
gtp_node_t *enb = NULL; |
| 181 |
sgw_bearer_t *bearer = NULL; |
| 182 |
sgw_tunnel_t *s1u_tunnel = NULL; |
| 183 |
gtp_modify_bearer_response_t *rsp = NULL; |
| 184 |
pkbuf_t *pkbuf = NULL; |
| 185 |
gtp_message_t gtp_message; |
| 186 |
|
| 187 |
gtp_cause_t cause; |
| 188 |
gtp_f_teid_t *enb_s1u_teid = NULL; |
| 189 |
gtp_uli_t uli; |
| 190 |
|
| 191 |
d_assert(s11_xact, return, "Null param"); |
| 192 |
d_assert(sgw_ue, return, "Null param"); |
| 193 |
d_assert(req, return, "Null param"); |
| 194 |
|
| 195 |
d_trace(3, "[SGW] Modify Bearer Reqeust\n"); |
| 196 |
if (req->bearer_contexts_to_be_modified.presence == 0) |
| 197 |
{ |
| 198 |
d_error("No Bearer"); |
| 199 |
return; |
| 200 |
} |
| 201 |
if (req->bearer_contexts_to_be_modified.eps_bearer_id.presence == 0) |
| 202 |
{ |
| 203 |
d_error("No EPS Bearer ID"); |
| 204 |
return; |
| 205 |
} |
| 206 |
if (req->bearer_contexts_to_be_modified.s1_u_enodeb_f_teid.presence == 0) |
| 207 |
{ |
| 208 |
d_error("No eNB TEID"); |
| 209 |
return; |
| 210 |
} |
| 211 |
|
| 212 |
bearer = sgw_bearer_find_by_ue_ebi(sgw_ue, |
| 213 |
req->bearer_contexts_to_be_modified.eps_bearer_id.u8); |
| 214 |
d_assert(bearer, return, "No Bearer Context"); |
| 215 |
s1u_tunnel = sgw_s1u_tunnel_in_bearer(bearer); |
| 216 |
d_assert(s1u_tunnel, return, "No S1U Tunnel Context"); |
| 217 |
|
| 218 |
/* Data Plane(DL) : eNB-S1U */ |
| 219 |
enb_s1u_teid = req->bearer_contexts_to_be_modified.s1_u_enodeb_f_teid.data; |
| 220 |
s1u_tunnel->remote_teid = ntohl(enb_s1u_teid->teid); |
| 221 |
|
| 222 |
d_trace(5, " MME_S11_TEID[%d] SGW_S11_TEID[%d]\n", |
| 223 |
sgw_ue->mme_s11_teid, sgw_ue->sgw_s11_teid); |
| 224 |
d_trace(5, " ENB_S1U_TEID[%d] SGW_S1U_TEID[%d]\n", |
| 225 |
s1u_tunnel->remote_teid, s1u_tunnel->local_teid); |
| 226 |
|
| 227 |
enb = gtp_find_node(&sgw_self()->enb_s1u_list, enb_s1u_teid); |
| 228 |
if (!enb) |
| 229 |
{ |
| 230 |
enb = gtp_add_node_with_teid(&sgw_self()->enb_s1u_list, enb_s1u_teid, |
| 231 |
sgw_self()->gtpu_port, |
| 232 |
context_self()->parameter.no_ipv4, |
| 233 |
context_self()->parameter.no_ipv6, |
| 234 |
context_self()->parameter.prefer_ipv4); |
| 235 |
d_assert(enb, return,); |
| 236 |
|
| 237 |
#if UNBOUNDED_UDP_SOCKET |
| 238 |
rv = gtp_connect(sgw_self()->gtpu_sock, sgw_self()->gtpu_sock6, enb); |
| 239 |
#else |
| 240 |
rv = gtp_client(enb); |
| 241 |
#endif |
| 242 |
d_assert(rv == CORE_OK, return,); |
| 243 |
} |
| 244 |
|
| 245 |
#if ULI_END_MARKER |
| 246 |
/* if ULI's Cell ID changes, End Marker is sent out or not */ |
| 247 |
if (req->user_location_information.presence == 1) |
| 248 |
{ |
| 249 |
/* Set User Location Information */ |
| 250 |
decoded = gtp_parse_uli(&uli, &req->user_location_information); |
| 251 |
d_assert(req->user_location_information.len == decoded, return,); |
| 252 |
memcpy(&bearer->tai.plmn_id, &uli.tai.plmn_id, sizeof(uli.tai.plmn_id)); |
| 253 |
bearer->tai.tac = uli.tai.tac; |
| 254 |
memcpy(&bearer->e_cgi.plmn_id, &uli.e_cgi.plmn_id, |
| 255 |
sizeof(uli.e_cgi.plmn_id)); |
| 256 |
d_trace(5, " ULI Presence: CellID[OLD:0x%x, NEW:0x%x]\n", |
| 257 |
bearer->e_cgi.cell_id, uli.e_cgi.cell_id); |
| 258 |
if (bearer->e_cgi.cell_id != uli.e_cgi.cell_id) |
| 259 |
{ |
| 260 |
d_trace(3, "[SGW] SEND End Marker to ENB[%s]: TEID[0x%x]\n", |
| 261 |
CORE_ADDR(sock_remote_addr(s1u_tunnel->gnode->sock), buf), |
| 262 |
s1u_tunnel->remote_teid); |
| 263 |
rv = sgw_gtp_send_end_marker(s1u_tunnel); |
| 264 |
if (rv != CORE_OK) |
| 265 |
d_error("gtp send end marker failed"); |
| 266 |
|
| 267 |
bearer->e_cgi.cell_id = uli.e_cgi.cell_id; |
| 268 |
} |
| 269 |
} |
| 270 |
#else /* GNODE_END_MARKER */ |
| 271 |
/* if GTP Node changes, End Marker is sent out or not */ |
| 272 |
if (req->user_location_information.presence == 1) |
| 273 |
{ |
| 274 |
/* Set User Location Information */ |
| 275 |
decoded = gtp_parse_uli(&uli, &req->user_location_information); |
| 276 |
d_assert(req->user_location_information.len == decoded, return,); |
| 277 |
memcpy(&bearer->tai.plmn_id, &uli.tai.plmn_id, sizeof(uli.tai.plmn_id)); |
| 278 |
bearer->tai.tac = uli.tai.tac; |
| 279 |
memcpy(&bearer->e_cgi.plmn_id, &uli.e_cgi.plmn_id, |
| 280 |
sizeof(uli.e_cgi.plmn_id)); |
| 281 |
bearer->e_cgi.cell_id = uli.e_cgi.cell_id; |
| 282 |
d_trace(5, " TAI[PLMN_ID:0x%x,TAC:%d]\n", |
| 283 |
bearer->tai.plmn_id, bearer->tai.tac); |
| 284 |
d_trace(5, " E_CGI[PLMN_ID:0x%x,CELL_ID:%d]\n", |
| 285 |
bearer->e_cgi.plmn_id, bearer->e_cgi.cell_id); |
| 286 |
} |
| 287 |
|
| 288 |
if (s1u_tunnel->gnode && s1u_tunnel->gnode != enb) |
| 289 |
{ |
| 290 |
d_assert(s1u_tunnel->gnode->sock, return,); |
| 291 |
|
| 292 |
d_trace(3, "[SGW] SEND End Marker to ENB[%s]: TEID[0x%x]", |
| 293 |
CORE_ADDR(sock_remote_addr(s1u_tunnel->gnode->sock), buf), |
| 294 |
s1u_tunnel->remote_teid); |
| 295 |
rv = sgw_gtp_send_end_marker(s1u_tunnel); |
| 296 |
if (rv != CORE_OK) |
| 297 |
d_error("gtp send end marker failed"); |
| 298 |
} |
| 299 |
#endif |
| 300 |
|
| 301 |
/* Setup GTP Node */ |
| 302 |
SETUP_GTP_NODE(s1u_tunnel, enb); |
| 303 |
|
| 304 |
/* Reset UE state */ |
| 305 |
SGW_RESET_UE_STATE(sgw_ue, SGW_S1U_INACTIVE); |
| 306 |
|
| 307 |
rsp = >p_message.modify_bearer_response; |
| 308 |
memset(>p_message, 0, sizeof(gtp_message_t)); |
| 309 |
|
| 310 |
memset(&cause, 0, sizeof(cause)); |
| 311 |
cause.value = GTP_CAUSE_REQUEST_ACCEPTED; |
| 312 |
|
| 313 |
rsp->cause.presence = 1; |
| 314 |
rsp->cause.data = &cause; |
| 315 |
rsp->cause.len = sizeof(cause); |
| 316 |
|
| 317 |
gtp_message.h.type = GTP_MODIFY_BEARER_RESPONSE_TYPE; |
| 318 |
gtp_message.h.teid = sgw_ue->mme_s11_teid; |
| 319 |
|
| 320 |
rv = gtp_build_msg(&pkbuf, >p_message); |
| 321 |
d_assert(rv == CORE_OK, return, "gtp build failed"); |
| 322 |
|
| 323 |
rv = gtp_xact_update_tx(s11_xact, >p_message.h, pkbuf); |
| 324 |
d_assert(rv == CORE_OK, return, "gtp_xact_update_tx error"); |
| 325 |
|
| 326 |
rv = gtp_xact_commit(s11_xact); |
| 327 |
d_assert(rv == CORE_OK, return, "xact_commit error"); |
| 328 |
} |
| 329 |
|
| 330 |
void sgw_s11_handle_delete_session_request(gtp_xact_t *s11_xact, |
| 331 |
sgw_ue_t *sgw_ue, gtp_message_t *gtp_message) |
| 332 |
{ |
| 333 |
status_t rv; |
| 334 |
pkbuf_t *pkbuf = NULL; |
| 335 |
gtp_xact_t *s5c_xact = NULL; |
| 336 |
sgw_sess_t *sess = NULL; |
| 337 |
gtp_delete_session_request_t *req = NULL; |
| 338 |
|
| 339 |
d_assert(s11_xact, return, "Null param"); |
| 340 |
d_assert(sgw_ue, return, "Null param"); |
| 341 |
d_assert(gtp_message, return, "Null param"); |
| 342 |
|
| 343 |
req = >p_message->delete_session_request; |
| 344 |
d_assert(req, return, "Null param"); |
| 345 |
|
| 346 |
d_trace(3, "[SGW] Delete Session Reqeust\n"); |
| 347 |
if (req->linked_eps_bearer_id.presence == 0) |
| 348 |
{ |
| 349 |
d_error("No EPS Bearer ID"); |
| 350 |
return; |
| 351 |
} |
| 352 |
|
| 353 |
sess = sgw_sess_find_by_ebi(sgw_ue, req->linked_eps_bearer_id.u8); |
| 354 |
d_assert(sess, return, "Null param"); |
| 355 |
d_trace(5, " MME_S11_TEID[%d] SGW_S11_TEID[%d]\n", |
| 356 |
sgw_ue->mme_s11_teid, sgw_ue->sgw_s11_teid); |
| 357 |
d_trace(5, " SGW_S5C_TEID[0x%x] PGW_S5C_TEID[0x%x]\n", |
| 358 |
sess->sgw_s5c_teid, sess->pgw_s5c_teid); |
| 359 |
|
| 360 |
gtp_message->h.type = GTP_DELETE_SESSION_REQUEST_TYPE; |
| 361 |
gtp_message->h.teid = sess->pgw_s5c_teid; |
| 362 |
|
| 363 |
rv = gtp_build_msg(&pkbuf, gtp_message); |
| 364 |
d_assert(rv == CORE_OK, return, "gtp build failed"); |
| 365 |
|
| 366 |
s5c_xact = gtp_xact_local_create(sess->gnode, >p_message->h, pkbuf); |
| 367 |
d_assert(s5c_xact, return, "Null param"); |
| 368 |
|
| 369 |
gtp_xact_associate(s11_xact, s5c_xact); |
| 370 |
|
| 371 |
rv = gtp_xact_commit(s5c_xact); |
| 372 |
d_assert(rv == CORE_OK, return, "xact_commit error"); |
| 373 |
} |
| 374 |
|
| 375 |
void sgw_s11_handle_create_bearer_response(gtp_xact_t *s11_xact, |
| 376 |
sgw_ue_t *sgw_ue, gtp_message_t *gtp_message) |
| 377 |
{ |
| 378 |
status_t rv; |
| 379 |
c_uint16_t decoded; |
| 380 |
pkbuf_t *pkbuf = NULL; |
| 381 |
gtp_node_t *enb = NULL; |
| 382 |
gtp_xact_t *s5c_xact = NULL; |
| 383 |
sgw_sess_t *sess = NULL; |
| 384 |
sgw_bearer_t *bearer = NULL; |
| 385 |
sgw_tunnel_t *s1u_tunnel = NULL, *s5u_tunnel = NULL; |
| 386 |
gtp_create_bearer_response_t *req = NULL; |
| 387 |
|
| 388 |
gtp_f_teid_t *sgw_s1u_teid = NULL, *enb_s1u_teid = NULL; |
| 389 |
gtp_f_teid_t sgw_s5u_teid, pgw_s5u_teid; |
| 390 |
int len; |
| 391 |
gtp_uli_t uli; |
| 392 |
|
| 393 |
d_assert(s11_xact, return, "Null param"); |
| 394 |
d_assert(sgw_ue, return, "Null param"); |
| 395 |
d_assert(gtp_message, return, "Null param"); |
| 396 |
s5c_xact = s11_xact->assoc_xact; |
| 397 |
d_assert(s5c_xact, return, "Null param"); |
| 398 |
|
| 399 |
d_trace(3, "[SGW] Cerate Bearer Reqeust\n"); |
| 400 |
req = >p_message->create_bearer_response; |
| 401 |
d_assert(req, return, "Null param"); |
| 402 |
|
| 403 |
if (req->bearer_contexts.presence == 0) |
| 404 |
{ |
| 405 |
d_error("No Bearer"); |
| 406 |
return; |
| 407 |
} |
| 408 |
if (req->bearer_contexts.eps_bearer_id.presence == 0) |
| 409 |
{ |
| 410 |
d_error("No EPS Bearer ID"); |
| 411 |
return; |
| 412 |
} |
| 413 |
if (req->bearer_contexts.s1_u_enodeb_f_teid.presence == 0) |
| 414 |
{ |
| 415 |
d_error("No eNB TEID"); |
| 416 |
return; |
| 417 |
} |
| 418 |
if (req->bearer_contexts.s4_u_sgsn_f_teid.presence == 0) |
| 419 |
{ |
| 420 |
d_error("No SGW TEID"); |
| 421 |
return; |
| 422 |
} |
| 423 |
if (req->user_location_information.presence == 0) |
| 424 |
{ |
| 425 |
d_error("No User Location Inforamtion"); |
| 426 |
return; |
| 427 |
} |
| 428 |
|
| 429 |
/* Correlate with SGW-S1U-TEID */ |
| 430 |
sgw_s1u_teid = req->bearer_contexts.s4_u_sgsn_f_teid.data; |
| 431 |
d_assert(sgw_s1u_teid, return, "Null param"); |
| 432 |
req->bearer_contexts.s4_u_sgsn_f_teid.presence = 0; |
| 433 |
|
| 434 |
/* Find the Tunnel by SGW-S1U-TEID */ |
| 435 |
s1u_tunnel = sgw_tunnel_find_by_teid(ntohl(sgw_s1u_teid->teid)); |
| 436 |
d_assert(s1u_tunnel, return, "Null param"); |
| 437 |
bearer = s1u_tunnel->bearer; |
| 438 |
d_assert(bearer, return, "Null param"); |
| 439 |
s5u_tunnel = sgw_s5u_tunnel_in_bearer(bearer); |
| 440 |
d_assert(s5u_tunnel, return, "Null param"); |
| 441 |
sess = bearer->sess; |
| 442 |
d_assert(sess, return, "Null param"); |
| 443 |
|
| 444 |
/* Set EBI */ |
| 445 |
bearer->ebi = req->bearer_contexts.eps_bearer_id.u8; |
| 446 |
|
| 447 |
/* Data Plane(DL) : eNB-S1U */ |
| 448 |
enb_s1u_teid = req->bearer_contexts.s1_u_enodeb_f_teid.data; |
| 449 |
s1u_tunnel->remote_teid = ntohl(enb_s1u_teid->teid); |
| 450 |
|
| 451 |
d_trace(5, " MME_S11_TEID[%d] SGW_S11_TEID[%d]\n", |
| 452 |
sgw_ue->mme_s11_teid, sgw_ue->sgw_s11_teid); |
| 453 |
d_trace(5, " SGW_S5C_TEID[0x%x] PGW_S5C_TEID[0x%x]\n", |
| 454 |
sess->sgw_s5c_teid, sess->pgw_s5c_teid); |
| 455 |
d_trace(5, " ENB_S1U_TEID[%d] SGW_S1U_TEID[%d]\n", |
| 456 |
s1u_tunnel->remote_teid, s1u_tunnel->local_teid); |
| 457 |
d_trace(5, " SGW_S5U_TEID[%d] PGW_S5U_TEID[%d]\n", |
| 458 |
s5u_tunnel->local_teid, s5u_tunnel->remote_teid); |
| 459 |
|
| 460 |
enb = gtp_find_node(&sgw_self()->enb_s1u_list, enb_s1u_teid); |
| 461 |
if (!enb) |
| 462 |
{ |
| 463 |
enb = gtp_add_node_with_teid(&sgw_self()->enb_s1u_list, enb_s1u_teid, |
| 464 |
sgw_self()->gtpu_port, |
| 465 |
context_self()->parameter.no_ipv4, |
| 466 |
context_self()->parameter.no_ipv6, |
| 467 |
context_self()->parameter.prefer_ipv4); |
| 468 |
d_assert(enb, return,); |
| 469 |
|
| 470 |
rv = gtp_client(enb); |
| 471 |
d_assert(rv == CORE_OK, return,); |
| 472 |
} |
| 473 |
/* Setup GTP Node */ |
| 474 |
SETUP_GTP_NODE(s1u_tunnel, enb); |
| 475 |
|
| 476 |
/* Remove S1U-F-TEID */ |
| 477 |
req->bearer_contexts.s1_u_enodeb_f_teid.presence = 0; |
| 478 |
|
| 479 |
decoded = gtp_parse_uli(&uli, &req->user_location_information); |
| 480 |
d_assert(req->user_location_information.len == decoded, return,); |
| 481 |
memcpy(&bearer->tai.plmn_id, &uli.tai.plmn_id, sizeof(uli.tai.plmn_id)); |
| 482 |
bearer->tai.tac = uli.tai.tac; |
| 483 |
memcpy(&bearer->e_cgi.plmn_id, &uli.e_cgi.plmn_id, sizeof(uli.e_cgi.plmn_id)); |
| 484 |
bearer->e_cgi.cell_id = uli.e_cgi.cell_id; |
| 485 |
|
| 486 |
/* Reset UE state */ |
| 487 |
SGW_RESET_UE_STATE(sgw_ue, SGW_S1U_INACTIVE); |
| 488 |
|
| 489 |
/* Data Plane(DL) : SGW-S5U */ |
| 490 |
memset(&sgw_s5u_teid, 0, sizeof(gtp_f_teid_t)); |
| 491 |
sgw_s5u_teid.interface_type = GTP_F_TEID_S5_S8_SGW_GTP_U; |
| 492 |
sgw_s5u_teid.teid = htonl(s5u_tunnel->local_teid); |
| 493 |
rv = gtp_sockaddr_to_f_teid( |
| 494 |
sgw_self()->gtpu_addr, sgw_self()->gtpu_addr6, &sgw_s5u_teid, &len); |
| 495 |
d_assert(rv == CORE_OK, return,); |
| 496 |
req->bearer_contexts.s5_s8_u_sgw_f_teid.presence = 1; |
| 497 |
req->bearer_contexts.s5_s8_u_sgw_f_teid.data = &sgw_s5u_teid; |
| 498 |
req->bearer_contexts.s5_s8_u_sgw_f_teid.len = len; |
| 499 |
|
| 500 |
/* Data Plane(DL) : PGW-S5U */ |
| 501 |
d_assert(s5u_tunnel->gnode, return,); |
| 502 |
pgw_s5u_teid.interface_type = GTP_F_TEID_S5_S8_PGW_GTP_U; |
| 503 |
pgw_s5u_teid.teid = htonl(s5u_tunnel->remote_teid); |
| 504 |
rv = gtp_ip_to_f_teid(&s5u_tunnel->gnode->ip, &pgw_s5u_teid, &len); |
| 505 |
req->bearer_contexts.s5_s8_u_pgw_f_teid.presence = 1; |
| 506 |
req->bearer_contexts.s5_s8_u_pgw_f_teid.data = &pgw_s5u_teid; |
| 507 |
req->bearer_contexts.s5_s8_u_pgw_f_teid.len = len; |
| 508 |
|
| 509 |
gtp_message->h.type = GTP_CREATE_BEARER_RESPONSE_TYPE; |
| 510 |
gtp_message->h.teid = sess->pgw_s5c_teid; |
| 511 |
|
| 512 |
rv = gtp_build_msg(&pkbuf, gtp_message); |
| 513 |
d_assert(rv == CORE_OK, return, "gtp build failed"); |
| 514 |
|
| 515 |
rv = gtp_xact_update_tx(s5c_xact, >p_message->h, pkbuf); |
| 516 |
d_assert(s5c_xact, return, "Null param"); |
| 517 |
|
| 518 |
rv = gtp_xact_commit(s5c_xact); |
| 519 |
d_assert(rv == CORE_OK, return, "xact_commit error"); |
| 520 |
} |
| 521 |
|
| 522 |
void sgw_s11_handle_update_bearer_response(gtp_xact_t *s11_xact, |
| 523 |
sgw_ue_t *sgw_ue, gtp_message_t *gtp_message) |
| 524 |
{ |
| 525 |
status_t rv; |
| 526 |
pkbuf_t *pkbuf = NULL; |
| 527 |
gtp_xact_t *s5c_xact = NULL; |
| 528 |
sgw_sess_t *sess = NULL; |
| 529 |
sgw_bearer_t *bearer = NULL; |
| 530 |
gtp_update_bearer_response_t *req = NULL; |
| 531 |
|
| 532 |
d_assert(s11_xact, return, "Null param"); |
| 533 |
d_assert(sgw_ue, return, "Null param"); |
| 534 |
d_assert(gtp_message, return, "Null param"); |
| 535 |
s5c_xact = s11_xact->assoc_xact; |
| 536 |
d_assert(s5c_xact, return, "Null param"); |
| 537 |
|
| 538 |
req = >p_message->update_bearer_response; |
| 539 |
d_assert(req, return, "Null param"); |
| 540 |
|
| 541 |
d_trace(3, "[SGW] Update Bearer Reqeust\n"); |
| 542 |
if (req->bearer_contexts.presence == 0) |
| 543 |
{ |
| 544 |
d_error("No Bearer"); |
| 545 |
return; |
| 546 |
} |
| 547 |
if (req->bearer_contexts.eps_bearer_id.presence == 0) |
| 548 |
{ |
| 549 |
d_error("No EPS Bearer ID"); |
| 550 |
return; |
| 551 |
} |
| 552 |
|
| 553 |
bearer = sgw_bearer_find_by_ue_ebi( |
| 554 |
sgw_ue, req->bearer_contexts.eps_bearer_id.u8); |
| 555 |
d_assert(bearer, return, "No Bearer Context[EBI:%d]", |
| 556 |
req->bearer_contexts.eps_bearer_id); |
| 557 |
sess = bearer->sess; |
| 558 |
d_assert(sess, return, "Null param"); |
| 559 |
|
| 560 |
d_trace(5, " MME_S11_TEID[%d] SGW_S11_TEID[%d]\n", |
| 561 |
sgw_ue->mme_s11_teid, sgw_ue->sgw_s11_teid); |
| 562 |
d_trace(5, " SGW_S5C_TEID[0x%x] PGW_S5C_TEID[0x%x]\n", |
| 563 |
sess->sgw_s5c_teid, sess->pgw_s5c_teid); |
| 564 |
|
| 565 |
gtp_message->h.type = GTP_UPDATE_BEARER_RESPONSE_TYPE; |
| 566 |
gtp_message->h.teid = sess->pgw_s5c_teid; |
| 567 |
|
| 568 |
rv = gtp_build_msg(&pkbuf, gtp_message); |
| 569 |
d_assert(rv == CORE_OK, return, "gtp build failed"); |
| 570 |
|
| 571 |
rv = gtp_xact_update_tx(s5c_xact, >p_message->h, pkbuf); |
| 572 |
d_assert(s5c_xact, return, "Null param"); |
| 573 |
|
| 574 |
rv = gtp_xact_commit(s5c_xact); |
| 575 |
d_assert(rv == CORE_OK, return, "xact_commit error"); |
| 576 |
} |
| 577 |
|
| 578 |
void sgw_s11_handle_delete_bearer_response(gtp_xact_t *s11_xact, |
| 579 |
sgw_ue_t *sgw_ue, gtp_message_t *gtp_message) |
| 580 |
{ |
| 581 |
status_t rv; |
| 582 |
pkbuf_t *pkbuf = NULL; |
| 583 |
gtp_xact_t *s5c_xact = NULL; |
| 584 |
sgw_sess_t *sess = NULL; |
| 585 |
sgw_bearer_t *bearer = NULL; |
| 586 |
gtp_delete_bearer_response_t *req = NULL; |
| 587 |
|
| 588 |
d_assert(s11_xact, return, "Null param"); |
| 589 |
d_assert(sgw_ue, return, "Null param"); |
| 590 |
d_assert(gtp_message, return, "Null param"); |
| 591 |
s5c_xact = s11_xact->assoc_xact; |
| 592 |
d_assert(s5c_xact, return, "Null param"); |
| 593 |
|
| 594 |
req = >p_message->delete_bearer_response; |
| 595 |
d_assert(req, return, "Null param"); |
| 596 |
|
| 597 |
d_trace(3, "[SGW] Delete Bearer Response\n"); |
| 598 |
if (req->bearer_contexts.presence == 0) |
| 599 |
{ |
| 600 |
d_error("No Bearer"); |
| 601 |
return; |
| 602 |
} |
| 603 |
if (req->bearer_contexts.eps_bearer_id.presence == 0) |
| 604 |
{ |
| 605 |
d_error("No EPS Bearer ID"); |
| 606 |
return; |
| 607 |
} |
| 608 |
|
| 609 |
bearer = sgw_bearer_find_by_ue_ebi( |
| 610 |
sgw_ue, req->bearer_contexts.eps_bearer_id.u8); |
| 611 |
d_assert(bearer, return, "No Bearer Context[EBI:%d]", |
| 612 |
req->bearer_contexts.eps_bearer_id); |
| 613 |
sess = bearer->sess; |
| 614 |
d_assert(sess, return, "Null param"); |
| 615 |
|
| 616 |
d_trace(5, " MME_S11_TEID[%d] SGW_S11_TEID[%d]\n", |
| 617 |
sgw_ue->mme_s11_teid, sgw_ue->sgw_s11_teid); |
| 618 |
d_trace(5, " SGW_S5C_TEID[0x%x] PGW_S5C_TEID[0x%x]\n", |
| 619 |
sess->sgw_s5c_teid, sess->pgw_s5c_teid); |
| 620 |
|
| 621 |
gtp_message->h.type = GTP_DELETE_BEARER_RESPONSE_TYPE; |
| 622 |
gtp_message->h.teid = sess->pgw_s5c_teid; |
| 623 |
|
| 624 |
rv = gtp_build_msg(&pkbuf, gtp_message); |
| 625 |
d_assert(rv == CORE_OK, return, "gtp build failed"); |
| 626 |
|
| 627 |
rv = gtp_xact_update_tx(s5c_xact, >p_message->h, pkbuf); |
| 628 |
d_assert(s5c_xact, return, "Null param"); |
| 629 |
|
| 630 |
rv = gtp_xact_commit(s5c_xact); |
| 631 |
d_assert(rv == CORE_OK, return, "xact_commit error"); |
| 632 |
|
| 633 |
sgw_bearer_remove(bearer); |
| 634 |
} |
| 635 |
|
| 636 |
void sgw_s11_handle_release_access_bearers_request(gtp_xact_t *s11_xact, |
| 637 |
sgw_ue_t *sgw_ue, gtp_release_access_bearers_request_t *req) |
| 638 |
{ |
| 639 |
status_t rv; |
| 640 |
gtp_release_access_bearers_response_t *rsp = NULL; |
| 641 |
pkbuf_t *pkbuf = NULL; |
| 642 |
gtp_message_t gtp_message; |
| 643 |
sgw_bearer_t *bearer = NULL, *next_bearer = NULL; |
| 644 |
sgw_tunnel_t *s1u_tunnel = NULL; |
| 645 |
sgw_sess_t *sess = NULL; |
| 646 |
|
| 647 |
gtp_cause_t cause; |
| 648 |
|
| 649 |
d_assert(sgw_ue, return, "Null param"); |
| 650 |
d_assert(s11_xact, return, "Null param"); |
| 651 |
d_assert(req, return, "Null param"); |
| 652 |
|
| 653 |
d_trace(3, "[SGW] Release Access Bearers Request\n"); |
| 654 |
d_trace(5, " MME_S11_TEID[%d] SGW_S11_TEID[%d]\n", |
| 655 |
sgw_ue->mme_s11_teid, sgw_ue->sgw_s11_teid); |
| 656 |
/* Set UE state to S1UE_INACTIVE */ |
| 657 |
SGW_SET_UE_STATE(sgw_ue, SGW_S1U_INACTIVE); |
| 658 |
/* ReSet UE state to S1UE_INACTIVE */ |
| 659 |
SGW_RESET_UE_STATE(sgw_ue, SGW_DL_NOTI_SENT); |
| 660 |
|
| 661 |
/* Release S1U(DL) path */ |
| 662 |
sess = sgw_sess_first(sgw_ue); |
| 663 |
while (sess) |
| 664 |
{ |
| 665 |
bearer = list_first(&sess->bearer_list); |
| 666 |
while (bearer) |
| 667 |
{ |
| 668 |
next_bearer = list_next(bearer); |
| 669 |
|
| 670 |
s1u_tunnel = sgw_s1u_tunnel_in_bearer(bearer); |
| 671 |
d_assert(s1u_tunnel, return, "Null param"); |
| 672 |
|
| 673 |
s1u_tunnel->remote_teid = 0; |
| 674 |
|
| 675 |
bearer = next_bearer; |
| 676 |
} |
| 677 |
|
| 678 |
sess = sgw_sess_next(sess); |
| 679 |
} |
| 680 |
|
| 681 |
rsp = >p_message.release_access_bearers_response; |
| 682 |
memset(>p_message, 0, sizeof(gtp_message_t)); |
| 683 |
|
| 684 |
memset(&cause, 0, sizeof(cause)); |
| 685 |
cause.value = GTP_CAUSE_REQUEST_ACCEPTED; |
| 686 |
|
| 687 |
rsp->cause.presence = 1; |
| 688 |
rsp->cause.data = &cause; |
| 689 |
rsp->cause.len = sizeof(cause); |
| 690 |
|
| 691 |
gtp_message.h.type = GTP_RELEASE_ACCESS_BEARERS_RESPONSE_TYPE; |
| 692 |
gtp_message.h.teid = sgw_ue->mme_s11_teid; |
| 693 |
|
| 694 |
rv = gtp_build_msg(&pkbuf, >p_message); |
| 695 |
d_assert(rv == CORE_OK, return, "gtp build failed"); |
| 696 |
|
| 697 |
rv = gtp_xact_update_tx(s11_xact, >p_message.h, pkbuf); |
| 698 |
d_assert(rv == CORE_OK, return, "gtp_xact_update_tx error"); |
| 699 |
|
| 700 |
rv = gtp_xact_commit(s11_xact); |
| 701 |
d_assert(rv == CORE_OK, return, "xact_commit error"); |
| 702 |
} |
| 703 |
|
| 704 |
void sgw_s11_handle_lo_dldata_notification(sgw_bearer_t *bearer) |
| 705 |
{ |
| 706 |
status_t rv; |
| 707 |
gtp_downlink_data_notification_t *noti = NULL; |
| 708 |
pkbuf_t *pkbuf = NULL; |
| 709 |
gtp_message_t gtp_message; |
| 710 |
sgw_ue_t *sgw_ue = NULL; |
| 711 |
gtp_xact_t *xact = NULL; |
| 712 |
/* FIXME : ARP should be retrieved from ? */ |
| 713 |
c_uint8_t arp = 0x61; |
| 714 |
|
| 715 |
d_assert(bearer, return, "Null param"); |
| 716 |
|
| 717 |
sgw_ue = bearer->sgw_ue; |
| 718 |
d_assert(sgw_ue, return, "Null param"); |
| 719 |
|
| 720 |
d_trace(3, "[SGW] Downlink Data Notification\n"); |
| 721 |
d_trace(5, " MME_S11_TEID[%d] SGW_S11_TEID[%d]\n", |
| 722 |
sgw_ue->mme_s11_teid, sgw_ue->sgw_s11_teid); |
| 723 |
|
| 724 |
/* Build downlink notification message */ |
| 725 |
noti = >p_message.downlink_data_notification; |
| 726 |
memset(>p_message, 0, sizeof(gtp_message_t)); |
| 727 |
|
| 728 |
noti->eps_bearer_id.presence = 1; |
| 729 |
noti->eps_bearer_id.u8 = bearer->ebi; |
| 730 |
|
| 731 |
/* FIXME : ARP should be retrieved from ? */ |
| 732 |
noti->allocation_retention_priority.presence = 1; |
| 733 |
noti->allocation_retention_priority.data = &arp; |
| 734 |
noti->allocation_retention_priority.len = sizeof(arp); |
| 735 |
|
| 736 |
gtp_message.h.type = GTP_DOWNLINK_DATA_NOTIFICATION_TYPE; |
| 737 |
gtp_message.h.teid = sgw_ue->mme_s11_teid; |
| 738 |
|
| 739 |
rv = gtp_build_msg(&pkbuf, >p_message); |
| 740 |
d_assert(rv == CORE_OK, return, "gtp build failed"); |
| 741 |
|
| 742 |
xact = gtp_xact_local_create(sgw_ue->gnode, >p_message.h, pkbuf); |
| 743 |
d_assert(xact, return, "Null param"); |
| 744 |
|
| 745 |
rv = gtp_xact_commit(xact); |
| 746 |
d_assert(rv == CORE_OK, return, "xact_commit error"); |
| 747 |
} |
| 748 |
|
| 749 |
void sgw_s11_handle_downlink_data_notification_ack( |
| 750 |
gtp_xact_t *s11_xact, sgw_ue_t *sgw_ue, |
| 751 |
gtp_downlink_data_notification_acknowledge_t *ack) |
| 752 |
{ |
| 753 |
status_t rv; |
| 754 |
d_assert(sgw_ue, return, "Null param"); |
| 755 |
d_assert(s11_xact, return, "Null param"); |
| 756 |
|
| 757 |
d_trace(3, "[SGW] Downlink Data Notification Acknowledge\n"); |
| 758 |
d_trace(5, " MME_S11_TEID[%d] SGW_S11_TEID[%d]\n", |
| 759 |
sgw_ue->mme_s11_teid, sgw_ue->sgw_s11_teid); |
| 760 |
|
| 761 |
rv = gtp_xact_commit(s11_xact); |
| 762 |
d_assert(rv == CORE_OK, return, "xact_commit error"); |
| 763 |
} |
| 764 |
|
| 765 |
void sgw_s11_handle_create_indirect_data_forwarding_tunnel_request( |
| 766 |
gtp_xact_t *s11_xact, sgw_ue_t *sgw_ue, |
| 767 |
gtp_create_indirect_data_forwarding_tunnel_request_t *req) |
| 768 |
{ |
| 769 |
status_t rv; |
| 770 |
gtp_create_indirect_data_forwarding_tunnel_response_t *rsp = NULL; |
| 771 |
pkbuf_t *pkbuf = NULL; |
| 772 |
gtp_message_t gtp_message; |
| 773 |
int i; |
| 774 |
|
| 775 |
gtp_node_t *enb = NULL; |
| 776 |
sgw_bearer_t *bearer = NULL; |
| 777 |
sgw_tunnel_t *tunnel = NULL; |
| 778 |
|
| 779 |
gtp_cause_t cause; |
| 780 |
tlv_bearer_context_t *req_bearers[GTP_MAX_NUM_OF_INDIRECT_TUNNEL]; |
| 781 |
tlv_bearer_context_t *rsp_bearers[GTP_MAX_NUM_OF_INDIRECT_TUNNEL]; |
| 782 |
gtp_f_teid_t *req_teid = NULL; |
| 783 |
gtp_f_teid_t rsp_dl_teid[GTP_MAX_NUM_OF_INDIRECT_TUNNEL]; |
| 784 |
gtp_f_teid_t rsp_ul_teid[GTP_MAX_NUM_OF_INDIRECT_TUNNEL]; |
| 785 |
int len; |
| 786 |
|
| 787 |
d_assert(sgw_ue, return, "Null param"); |
| 788 |
d_assert(s11_xact, return, "Null param"); |
| 789 |
d_assert(req, return, "Null param"); |
| 790 |
|
| 791 |
d_trace(3, "[SGW] Create Indirect Data Forwarding Tunnel Request\n"); |
| 792 |
d_trace(5, " MME_S11_TEID[%d] SGW_S11_TEID[%d]\n", |
| 793 |
sgw_ue->mme_s11_teid, sgw_ue->sgw_s11_teid); |
| 794 |
|
| 795 |
rsp = >p_message.create_indirect_data_forwarding_tunnel_response; |
| 796 |
memset(>p_message, 0, sizeof(gtp_message_t)); |
| 797 |
|
| 798 |
gtp_bearers_in_create_indirect_tunnel_request(&req_bearers, req); |
| 799 |
gtp_bearers_in_create_indirect_tunnel_response(&rsp_bearers, rsp); |
| 800 |
|
| 801 |
memset(&cause, 0, sizeof(cause)); |
| 802 |
cause.value = GTP_CAUSE_REQUEST_ACCEPTED; |
| 803 |
|
| 804 |
rsp->cause.presence = 1; |
| 805 |
rsp->cause.data = &cause; |
| 806 |
rsp->cause.len = sizeof(cause); |
| 807 |
|
| 808 |
for (i = 0; req_bearers[i]->presence; i++) |
| 809 |
{ |
| 810 |
if (req_bearers[i]->eps_bearer_id.presence == 0) |
| 811 |
{ |
| 812 |
d_error("No EBI"); |
| 813 |
return; |
| 814 |
} |
| 815 |
|
| 816 |
bearer = sgw_bearer_find_by_ue_ebi(sgw_ue, |
| 817 |
req_bearers[i]->eps_bearer_id.u8); |
| 818 |
d_assert(bearer, return, "No Bearer Context"); |
| 819 |
|
| 820 |
if (req_bearers[i]->s1_u_enodeb_f_teid.presence) |
| 821 |
{ |
| 822 |
req_teid = req_bearers[i]->s1_u_enodeb_f_teid.data; |
| 823 |
d_assert(req_teid, return,); |
| 824 |
|
| 825 |
tunnel = sgw_tunnel_add(bearer, |
| 826 |
GTP_F_TEID_SGW_GTP_U_FOR_DL_DATA_FORWARDING); |
| 827 |
d_assert(tunnel, return, "No Tunnel Context"); |
| 828 |
|
| 829 |
tunnel->remote_teid = ntohl(req_teid->teid); |
| 830 |
enb = gtp_find_node(&sgw_self()->enb_s1u_list, req_teid); |
| 831 |
if (!enb) |
| 832 |
{ |
| 833 |
enb = gtp_add_node_with_teid( |
| 834 |
&sgw_self()->enb_s1u_list, req_teid, |
| 835 |
sgw_self()->gtpu_port, |
| 836 |
context_self()->parameter.no_ipv4, |
| 837 |
context_self()->parameter.no_ipv6, |
| 838 |
context_self()->parameter.prefer_ipv4); |
| 839 |
d_assert(enb, return,); |
| 840 |
|
| 841 |
rv = gtp_client(enb); |
| 842 |
d_assert(rv == CORE_OK, return,); |
| 843 |
} |
| 844 |
/* Setup GTP Node */ |
| 845 |
SETUP_GTP_NODE(tunnel, enb); |
| 846 |
|
| 847 |
memset(&rsp_dl_teid[i], 0, sizeof(gtp_f_teid_t)); |
| 848 |
rsp_dl_teid[i].interface_type = tunnel->interface_type; |
| 849 |
rsp_dl_teid[i].teid = htonl(tunnel->local_teid); |
| 850 |
rv = gtp_sockaddr_to_f_teid(sgw_self()->gtpu_addr, |
| 851 |
sgw_self()->gtpu_addr6, &rsp_dl_teid[i], &len); |
| 852 |
d_assert(len > 0, return,); |
| 853 |
rsp_bearers[i]->s4_u_sgsn_f_teid.presence = 1; |
| 854 |
rsp_bearers[i]->s4_u_sgsn_f_teid.data = &rsp_dl_teid[i]; |
| 855 |
rsp_bearers[i]->s4_u_sgsn_f_teid.len = len; |
| 856 |
|
| 857 |
d_trace(5, " SGW_DL_TEID[%d] ENB_DL_TEID[%d]\n", |
| 858 |
tunnel->local_teid, tunnel->remote_teid); |
| 859 |
} |
| 860 |
|
| 861 |
if (req_bearers[i]->s12_rnc_f_teid.presence) |
| 862 |
{ |
| 863 |
req_teid = req_bearers[i]->s12_rnc_f_teid.data; |
| 864 |
d_assert(req_teid, return,); |
| 865 |
|
| 866 |
tunnel = sgw_tunnel_add(bearer, |
| 867 |
GTP_F_TEID_SGW_GTP_U_FOR_UL_DATA_FORWARDING); |
| 868 |
d_assert(tunnel, return, "No Tunnel Context"); |
| 869 |
|
| 870 |
tunnel->remote_teid = ntohl(req_teid->teid); |
| 871 |
enb = gtp_find_node(&sgw_self()->enb_s1u_list, req_teid); |
| 872 |
if (!enb) |
| 873 |
{ |
| 874 |
enb = gtp_add_node_with_teid( |
| 875 |
&sgw_self()->enb_s1u_list, req_teid, |
| 876 |
sgw_self()->gtpu_port, |
| 877 |
context_self()->parameter.no_ipv4, |
| 878 |
context_self()->parameter.no_ipv6, |
| 879 |
context_self()->parameter.prefer_ipv4); |
| 880 |
d_assert(enb, return,); |
| 881 |
|
| 882 |
rv = gtp_client(enb); |
| 883 |
d_assert(rv == CORE_OK, return,); |
| 884 |
} |
| 885 |
/* Setup GTP Node */ |
| 886 |
SETUP_GTP_NODE(tunnel, enb); |
| 887 |
|
| 888 |
memset(&rsp_ul_teid[i], 0, sizeof(gtp_f_teid_t)); |
| 889 |
rsp_ul_teid[i].teid = htonl(tunnel->local_teid); |
| 890 |
rsp_ul_teid[i].interface_type = tunnel->interface_type; |
| 891 |
rv = gtp_sockaddr_to_f_teid(sgw_self()->gtpu_addr, |
| 892 |
sgw_self()->gtpu_addr6, &rsp_ul_teid[i], &len); |
| 893 |
d_assert(rv == CORE_OK, return,); |
| 894 |
rsp_bearers[i]->s2b_u_epdg_f_teid_5.presence = 1; |
| 895 |
rsp_bearers[i]->s2b_u_epdg_f_teid_5.data = &rsp_ul_teid[i]; |
| 896 |
rsp_bearers[i]->s2b_u_epdg_f_teid_5.len = len; |
| 897 |
d_trace(5, " SGW_UL_TEID[%d] ENB_UL_TEID[%d]\n", |
| 898 |
tunnel->local_teid, tunnel->remote_teid); |
| 899 |
} |
| 900 |
|
| 901 |
if (req_bearers[i]->s1_u_enodeb_f_teid.presence || |
| 902 |
req_bearers[i]->s12_rnc_f_teid.presence) |
| 903 |
{ |
| 904 |
rsp_bearers[i]->presence = 1; |
| 905 |
rsp_bearers[i]->eps_bearer_id.presence = 1; |
| 906 |
rsp_bearers[i]->eps_bearer_id.u8 = bearer->ebi; |
| 907 |
} |
| 908 |
} |
| 909 |
|
| 910 |
gtp_message.h.type = |
| 911 |
GTP_CREATE_INDIRECT_DATA_FORWARDING_TUNNEL_RESPONSE_TYPE; |
| 912 |
gtp_message.h.teid = sgw_ue->mme_s11_teid; |
| 913 |
|
| 914 |
rv = gtp_build_msg(&pkbuf, >p_message); |
| 915 |
d_assert(rv == CORE_OK, return, "gtp build failed"); |
| 916 |
|
| 917 |
rv = gtp_xact_update_tx(s11_xact, >p_message.h, pkbuf); |
| 918 |
d_assert(rv == CORE_OK, return, "gtp_xact_update_tx error"); |
| 919 |
|
| 920 |
rv = gtp_xact_commit(s11_xact); |
| 921 |
d_assert(rv == CORE_OK, return, "xact_commit error"); |
| 922 |
} |
| 923 |
|
| 924 |
void sgw_s11_handle_delete_indirect_data_forwarding_tunnel_request( |
| 925 |
gtp_xact_t *s11_xact, sgw_ue_t *sgw_ue) |
| 926 |
{ |
| 927 |
status_t rv; |
| 928 |
gtp_delete_indirect_data_forwarding_tunnel_response_t *rsp = NULL; |
| 929 |
pkbuf_t *pkbuf = NULL; |
| 930 |
gtp_message_t gtp_message; |
| 931 |
|
| 932 |
sgw_sess_t *sess = NULL; |
| 933 |
sgw_bearer_t *bearer = NULL; |
| 934 |
sgw_tunnel_t *tunnel = NULL, *next_tunnel; |
| 935 |
|
| 936 |
gtp_cause_t cause; |
| 937 |
|
| 938 |
d_assert(sgw_ue, return, "Null param"); |
| 939 |
d_assert(s11_xact, return, "Null param"); |
| 940 |
|
| 941 |
d_trace(3, "[SGW] Delete Indirect Data Forwarding Tunnel Request\n"); |
| 942 |
d_trace(5, " MME_S11_TEID[%d] SGW_S11_TEID[%d]\n", |
| 943 |
sgw_ue->mme_s11_teid, sgw_ue->sgw_s11_teid); |
| 944 |
|
| 945 |
/* Delete Indirect Tunnel */ |
| 946 |
sess = sgw_sess_first(sgw_ue); |
| 947 |
while (sess) |
| 948 |
{ |
| 949 |
bearer = sgw_bearer_first(sess); |
| 950 |
while (bearer) |
| 951 |
{ |
| 952 |
tunnel = sgw_tunnel_first(bearer); |
| 953 |
while(tunnel) |
| 954 |
{ |
| 955 |
next_tunnel = sgw_tunnel_next(tunnel); |
| 956 |
|
| 957 |
if (tunnel->interface_type == |
| 958 |
GTP_F_TEID_SGW_GTP_U_FOR_DL_DATA_FORWARDING || |
| 959 |
tunnel->interface_type == |
| 960 |
GTP_F_TEID_SGW_GTP_U_FOR_UL_DATA_FORWARDING) |
| 961 |
sgw_tunnel_remove(tunnel); |
| 962 |
|
| 963 |
tunnel = next_tunnel; |
| 964 |
} |
| 965 |
|
| 966 |
|
| 967 |
bearer = sgw_bearer_next(bearer); |
| 968 |
} |
| 969 |
|
| 970 |
sess = sgw_sess_next(sess); |
| 971 |
} |
| 972 |
|
| 973 |
rsp = >p_message.delete_indirect_data_forwarding_tunnel_response; |
| 974 |
memset(>p_message, 0, sizeof(gtp_message_t)); |
| 975 |
|
| 976 |
memset(&cause, 0, sizeof(cause)); |
| 977 |
cause.value = GTP_CAUSE_REQUEST_ACCEPTED; |
| 978 |
|
| 979 |
rsp->cause.presence = 1; |
| 980 |
rsp->cause.data = &cause; |
| 981 |
rsp->cause.len = sizeof(cause); |
| 982 |
|
| 983 |
gtp_message.h.type = |
| 984 |
GTP_DELETE_INDIRECT_DATA_FORWARDING_TUNNEL_RESPONSE_TYPE; |
| 985 |
gtp_message.h.teid = sgw_ue->mme_s11_teid; |
| 986 |
|
| 987 |
rv = gtp_build_msg(&pkbuf, >p_message); |
| 988 |
d_assert(rv == CORE_OK, return, "gtp build failed"); |
| 989 |
|
| 990 |
rv = gtp_xact_update_tx(s11_xact, >p_message.h, pkbuf); |
| 991 |
d_assert(rv == CORE_OK, return, "gtp_xact_update_tx error"); |
| 992 |
|
| 993 |
rv = gtp_xact_commit(s11_xact); |
| 994 |
d_assert(rv == CORE_OK, return, "xact_commit error"); |
| 995 |
} |