File size: 26,092 Bytes
258fb37 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 |
/*
* Copyright (C) 2019,2020 by Sukchan Lee <acetcom@gmail.com>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ngap-handler.h"
#include "sbi-path.h"
#include "pfcp-path.h"
#include "ngap-path.h"
int ngap_handle_pdu_session_resource_setup_response_transfer(
smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_pkbuf_t *pkbuf)
{
smf_ue_t *smf_ue = NULL;
int rv, i;
uint32_t gnb_n3_teid;
ogs_ip_t gnb_n3_ip;
bool far_update = false;
NGAP_PDUSessionResourceSetupResponseTransfer_t message;
NGAP_QosFlowPerTNLInformation_t *dLQosFlowPerTNLInformation = NULL;
NGAP_UPTransportLayerInformation_t *uPTransportLayerInformation = NULL;
NGAP_GTPTunnel_t *gTPTunnel = NULL;
NGAP_AssociatedQosFlowList_t *associatedQosFlowList = NULL;
ogs_assert(pkbuf);
ogs_assert(stream);
ogs_assert(sess);
smf_ue = smf_ue_find_by_id(sess->smf_ue_id);
ogs_assert(smf_ue);
ogs_debug("PDUSessionResourceSetupResponseTransfer");
rv = ogs_asn_decode(
&asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer,
&message, sizeof(message), pkbuf);
if (rv != OGS_OK) {
ogs_error("[%s:%d] Cannot decode NGAP message",
smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No N2 SM Info Type", smf_ue->supi);
goto cleanup;
}
rv = OGS_ERROR;
dLQosFlowPerTNLInformation = &message.dLQosFlowPerTNLInformation;
uPTransportLayerInformation =
&dLQosFlowPerTNLInformation->uPTransportLayerInformation;
if (uPTransportLayerInformation->present !=
NGAP_UPTransportLayerInformation_PR_gTPTunnel) {
ogs_error(
"[%s:%d] Unknown NGAP_UPTransportLayerInformation.present [%d]",
smf_ue->supi, sess->psi,
uPTransportLayerInformation->present);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"Unknown NGAP_UPTransportLayerInformation.present",
smf_ue->supi);
goto cleanup;
}
gTPTunnel = uPTransportLayerInformation->choice.gTPTunnel;
if (!gTPTunnel) {
ogs_error("[%s:%d] No GTPTunnel", smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No GTPTunnel", smf_ue->supi);
goto cleanup;
}
rv = ogs_asn_BIT_STRING_to_ip(
&gTPTunnel->transportLayerAddress, &gnb_n3_ip);
if (rv != OGS_OK) {
ogs_error("[%s:%d] No transportLayerAddress", smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No transportLayerAddress", smf_ue->supi);
goto cleanup;
}
ogs_asn_OCTET_STRING_to_uint32(&gTPTunnel->gTP_TEID, &gnb_n3_teid);
/* Need to Update? */
if (memcmp(&sess->gnb_n3_ip, &gnb_n3_ip, sizeof(sess->gnb_n3_ip)) != 0 ||
sess->gnb_n3_teid != gnb_n3_teid)
far_update = true;
/* Setup FAR */
memcpy(&sess->gnb_n3_ip, &gnb_n3_ip, sizeof(sess->gnb_n3_ip));
sess->gnb_n3_teid = gnb_n3_teid;
associatedQosFlowList = &dLQosFlowPerTNLInformation->associatedQosFlowList;
for (i = 0; i < associatedQosFlowList->list.count; i++) {
NGAP_AssociatedQosFlowItem_t *associatedQosFlowItem = NULL;
associatedQosFlowItem = (NGAP_AssociatedQosFlowItem_t *)
associatedQosFlowList->list.array[i];
if (associatedQosFlowItem) {
smf_bearer_t *qos_flow = smf_qos_flow_find_by_qfi(
sess, associatedQosFlowItem->qosFlowIdentifier);
if (qos_flow) {
ogs_pfcp_far_t *dl_far = qos_flow->dl_far;
ogs_assert(dl_far);
if (dl_far->apply_action != OGS_PFCP_APPLY_ACTION_FORW) {
far_update = true;
}
dl_far->apply_action = OGS_PFCP_APPLY_ACTION_FORW;
ogs_assert(OGS_OK ==
ogs_pfcp_ip_to_outer_header_creation(
&sess->gnb_n3_ip,
&dl_far->outer_header_creation,
&dl_far->outer_header_creation_len));
dl_far->outer_header_creation.teid = sess->gnb_n3_teid;
} else {
ogs_error("[%s:%d] No QoS flow", smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No QoS flow", smf_ue->supi);
goto cleanup;
}
}
}
if (far_update) {
ogs_assert(OGS_OK ==
smf_5gc_pfcp_send_all_pdr_modification_request(
sess, stream, OGS_PFCP_MODIFY_DL_ONLY|OGS_PFCP_MODIFY_ACTIVATE,
0));
} else {
#if 0 /* Modified by pull request #1729 */
/* ACTIVATED Is NOT Included in RESPONSE */
ogs_assert(true == ogs_sbi_send_http_status_no_content(stream));
#else
if (sess->up_cnx_state == OpenAPI_up_cnx_state_ACTIVATING) {
sess->up_cnx_state = OpenAPI_up_cnx_state_ACTIVATED;
smf_sbi_send_sm_context_updated_data_up_cnx_state(
sess, stream, OpenAPI_up_cnx_state_ACTIVATED);
} else {
ogs_assert(true == ogs_sbi_send_http_status_no_content(stream));
}
#endif
}
rv = OGS_OK;
cleanup:
ogs_asn_free(
&asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, &message);
return rv;
}
int ngap_handle_pdu_session_resource_setup_unsuccessful_transfer(
smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_pkbuf_t *pkbuf)
{
smf_ue_t *smf_ue = NULL;
int rv;
NGAP_PDUSessionResourceSetupUnsuccessfulTransfer_t message;
NGAP_Cause_t *Cause = NULL;
ogs_assert(pkbuf);
ogs_assert(stream);
ogs_assert(sess);
smf_ue = smf_ue_find_by_id(sess->smf_ue_id);
ogs_assert(smf_ue);
ogs_debug("PDUSessionResourceSetupUnsuccessfulTransfer");
rv = ogs_asn_decode(
&asn_DEF_NGAP_PDUSessionResourceSetupUnsuccessfulTransfer,
&message, sizeof(message), pkbuf);
if (rv != OGS_OK) {
ogs_error("[%s:%d] Cannot decode NGAP message",
smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No N2 SM Info Type", smf_ue->supi);
goto cleanup;
}
rv = OGS_ERROR;
Cause = &message.cause;
if (Cause->present == NGAP_Cause_PR_radioNetwork &&
Cause->choice.radioNetwork ==
NGAP_CauseRadioNetwork_multiple_PDU_session_ID_instances) {
ogs_warn(" Cause[Group:%d Cause:%d]",
Cause->present, (int)Cause->choice.radioNetwork);
} else {
ogs_error(" Cause[Group:%d Cause:%d]",
Cause->present, (int)Cause->choice.radioNetwork);
}
/*
* TS23.502
* 4.2.3 Service Request procedures
* 4.2.3.2 UE Triggered Service Request
*
* 15. ...
* If a PDU Session is rejected by the serving NG-RAN
* with an indication that the PDU Session was rejected
* because User Plane Security Enforcement is not supported
* in the serving NG-RAN and the User Plane Enforcement Policy
* indicates "Required" as described in clause 5.10.3
* of TS 23.501 [2], the SMF shall trigger the release
* of this PDU Session.
*
* In all other cases of PDU Session rejection,
* the SMF can decide whether to release the PDU Session
* or to deactivate the UP connection of this PDU Session.
*
*
* TS29.502
*
* 5.2.2.3.2
* Activation and Deactivation of the User Plane connection
* of a PDU session
* 5.2.2.3.2.2
* Activation of User Plane connectivity of a PDU session
*
* 3. ...
* N2 SM information received from the 5G-AN
* (see PDU Session Resource Setup Unsuccessful Transfer IE
* in clause 9.3.4.16 of 3GPP TS 38.413 [9]),
* including the Cause of the failure, if resources failed
* to be established for the PDU session.
*
* Upon receipt of this request, the SMF shall:
* - consider that the activation of the User Plane connection
* has failed and set the upCnxState attribute to DEACTIVATED"
* otherwise.
*/
ogs_assert(OGS_OK ==
smf_5gc_pfcp_send_all_pdr_modification_request(
sess, stream,
OGS_PFCP_MODIFY_DL_ONLY|OGS_PFCP_MODIFY_DEACTIVATE, 0));
rv = OGS_OK;
cleanup:
ogs_asn_free(
&asn_DEF_NGAP_PDUSessionResourceSetupUnsuccessfulTransfer, &message);
return rv;
}
int ngap_handle_pdu_session_resource_modify_response_transfer(
smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_pkbuf_t *pkbuf)
{
smf_ue_t *smf_ue = NULL;
smf_bearer_t *qos_flow = NULL;
int rv, i;
ogs_pfcp_far_t *dl_far = NULL;
NGAP_PDUSessionResourceModifyResponseTransfer_t message;
NGAP_QosFlowAddOrModifyResponseList_t *qosFlowAddOrModifyResponseList;
ogs_assert(pkbuf);
ogs_assert(stream);
ogs_assert(sess);
smf_ue = smf_ue_find_by_id(sess->smf_ue_id);
ogs_assert(smf_ue);
ogs_debug("PDUSessionResourceModifyResponseTransfer");
rv = ogs_asn_decode(
&asn_DEF_NGAP_PDUSessionResourceModifyResponseTransfer,
&message, sizeof(message), pkbuf);
if (rv != OGS_OK) {
ogs_error("[%s:%d] Cannot decode NGAP message",
smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No N2 SM Info Type", smf_ue->supi);
goto cleanup;
}
rv = OGS_ERROR;
qosFlowAddOrModifyResponseList = message.qosFlowAddOrModifyResponseList;
if (!qosFlowAddOrModifyResponseList) {
/* QosFlow Release */
rv = OGS_OK;
ogs_assert(true == ogs_sbi_send_http_status_no_content(stream));
goto cleanup;
}
ogs_list_init(&sess->qos_flow_to_modify_list);
if (qosFlowAddOrModifyResponseList) {
for (i = 0; i < qosFlowAddOrModifyResponseList->list.count; i++) {
NGAP_QosFlowAddOrModifyResponseItem_t
*qosFlowAddOrModifyResponseItem = NULL;
qosFlowAddOrModifyResponseItem =
(NGAP_QosFlowAddOrModifyResponseItem_t *)
qosFlowAddOrModifyResponseList->list.array[i];
if (qosFlowAddOrModifyResponseItem) {
qos_flow = smf_qos_flow_find_by_qfi(sess,
qosFlowAddOrModifyResponseItem->qosFlowIdentifier);
if (qos_flow) {
dl_far = qos_flow->dl_far;
ogs_assert(dl_far);
dl_far->apply_action = OGS_PFCP_APPLY_ACTION_FORW;
ogs_assert(OGS_OK ==
ogs_pfcp_ip_to_outer_header_creation(
&sess->gnb_n3_ip,
&dl_far->outer_header_creation,
&dl_far->outer_header_creation_len));
dl_far->outer_header_creation.teid = sess->gnb_n3_teid;
ogs_list_add(&sess->qos_flow_to_modify_list,
&qos_flow->to_modify_node);
}
}
}
}
if (ogs_list_count(&sess->qos_flow_to_modify_list) == 0) {
ogs_error("[%s:%d] No QoS flow", smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No QoS flow", smf_ue->supi);
goto cleanup;
}
ogs_assert(OGS_OK ==
smf_5gc_pfcp_send_qos_flow_list_modification_request(
sess, stream,
OGS_PFCP_MODIFY_DL_ONLY|OGS_PFCP_MODIFY_ACTIVATE, 0));
rv = OGS_OK;
cleanup:
ogs_asn_free(
&asn_DEF_NGAP_PDUSessionResourceModifyResponseTransfer, &message);
return rv;
}
int ngap_handle_path_switch_request_transfer(
smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_pkbuf_t *pkbuf)
{
smf_ue_t *smf_ue = NULL;
int rv, i;
uint32_t gnb_n3_teid;
ogs_ip_t gnb_n3_ip;
bool far_update = false;
NGAP_PathSwitchRequestTransfer_t message;
NGAP_UPTransportLayerInformation_t *dL_NGU_UP_TNLInformation = NULL;
NGAP_QosFlowAcceptedItem_t *acceptedQosFlowItem = NULL;
NGAP_GTPTunnel_t *gTPTunnel = NULL;
NGAP_QosFlowAcceptedList_t *qosFlowAcceptedList = NULL;
ogs_assert(pkbuf);
ogs_assert(stream);
ogs_assert(sess);
smf_ue = smf_ue_find_by_id(sess->smf_ue_id);
ogs_assert(smf_ue);
ogs_debug("PathSwitchRequestTransfer");
rv = ogs_asn_decode(&asn_DEF_NGAP_PathSwitchRequestTransfer,
&message, sizeof(message), pkbuf);
if (rv != OGS_OK) {
ogs_error("[%s:%d] Cannot decode NGAP message",
smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No N2 SM Info Type", smf_ue->supi);
goto cleanup;
}
rv = OGS_ERROR;
dL_NGU_UP_TNLInformation = &message.dL_NGU_UP_TNLInformation;
if (dL_NGU_UP_TNLInformation->present !=
NGAP_UPTransportLayerInformation_PR_gTPTunnel) {
ogs_error(
"[%s:%d] Unknown dL_NGU_UP_TNLInformation->present [%d]",
smf_ue->supi, sess->psi, dL_NGU_UP_TNLInformation->present);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"Unknown dL_NGU_UP_TNLInformation->present", smf_ue->supi);
goto cleanup;
}
gTPTunnel = dL_NGU_UP_TNLInformation->choice.gTPTunnel;
if (!gTPTunnel) {
ogs_error("[%s:%d] No GTPTunnel", smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No GTPTunnel", smf_ue->supi);
goto cleanup;
}
rv = ogs_asn_BIT_STRING_to_ip(
&gTPTunnel->transportLayerAddress, &gnb_n3_ip);
if (rv != OGS_OK) {
ogs_error("[%s:%d] No transportLayerAddress", smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No transportLayerAddress", smf_ue->supi);
goto cleanup;
}
ogs_asn_OCTET_STRING_to_uint32(&gTPTunnel->gTP_TEID, &gnb_n3_teid);
/* Need to Update? */
if (memcmp(&sess->gnb_n3_ip, &gnb_n3_ip, sizeof(sess->gnb_n3_ip)) != 0 ||
sess->gnb_n3_teid != gnb_n3_teid)
far_update = true;
/* Setup FAR */
memcpy(&sess->gnb_n3_ip, &gnb_n3_ip, sizeof(sess->gnb_n3_ip));
sess->gnb_n3_teid = gnb_n3_teid;
qosFlowAcceptedList = &message.qosFlowAcceptedList;
for (i = 0; i < qosFlowAcceptedList->list.count; i++) {
acceptedQosFlowItem = (NGAP_QosFlowAcceptedItem_t *)
qosFlowAcceptedList->list.array[i];
if (acceptedQosFlowItem) {
smf_bearer_t *qos_flow = smf_qos_flow_find_by_qfi(
sess, acceptedQosFlowItem->qosFlowIdentifier);
if (qos_flow) {
ogs_pfcp_far_t *dl_far = qos_flow->dl_far;
ogs_assert(dl_far);
if (dl_far->apply_action != OGS_PFCP_APPLY_ACTION_FORW) {
far_update = true;
}
dl_far->apply_action = OGS_PFCP_APPLY_ACTION_FORW;
ogs_assert(OGS_OK ==
ogs_pfcp_ip_to_outer_header_creation(
&sess->gnb_n3_ip,
&dl_far->outer_header_creation,
&dl_far->outer_header_creation_len));
dl_far->outer_header_creation.teid = sess->gnb_n3_teid;
} else {
ogs_error("[%s:%d] No QoS flow", smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No QoS flow", smf_ue->supi);
goto cleanup;
}
}
}
if (far_update) {
ogs_assert(OGS_OK ==
smf_5gc_pfcp_send_all_pdr_modification_request(
sess, stream,
OGS_PFCP_MODIFY_DL_ONLY|OGS_PFCP_MODIFY_ACTIVATE|
OGS_PFCP_MODIFY_XN_HANDOVER|OGS_PFCP_MODIFY_END_MARKER,
0));
} else {
/* ACTIVATED Is NOT Included in RESPONSE */
ogs_assert(true == ogs_sbi_send_http_status_no_content(stream));
}
rv = OGS_OK;
cleanup:
ogs_asn_free(&asn_DEF_NGAP_PathSwitchRequestTransfer, &message);
return rv;
}
int ngap_handle_handover_required_transfer(
smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_pkbuf_t *pkbuf)
{
smf_ue_t *smf_ue = NULL;
int rv;
NGAP_HandoverRequiredTransfer_t message;
NGAP_DirectForwardingPathAvailability_t
*directForwardingPathAvailability = NULL;
ogs_pkbuf_t *n2smbuf = NULL;
ogs_assert(pkbuf);
ogs_assert(stream);
ogs_assert(sess);
smf_ue = smf_ue_find_by_id(sess->smf_ue_id);
ogs_assert(smf_ue);
ogs_debug("HandoverRequiredTransfer");
rv = ogs_asn_decode(&asn_DEF_NGAP_HandoverRequiredTransfer,
&message, sizeof(message), pkbuf);
if (rv != OGS_OK) {
ogs_error("[%s:%d] Cannot decode NGAP message",
smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No N2 SM Info Type", smf_ue->supi);
goto cleanup;
}
directForwardingPathAvailability = message.directForwardingPathAvailability;
if (!directForwardingPathAvailability)
sess->handover.data_forwarding_not_possible = true;
n2smbuf = ngap_build_pdu_session_resource_setup_request_transfer(sess);
ogs_assert(n2smbuf);
smf_sbi_send_sm_context_updated_data(
sess, stream, 0, OpenAPI_ho_state_PREPARING,
NULL, OpenAPI_n2_sm_info_type_PDU_RES_SETUP_REQ, n2smbuf);
rv = OGS_OK;
cleanup:
ogs_asn_free(&asn_DEF_NGAP_HandoverRequiredTransfer, &message);
return rv;
}
int ngap_handle_handover_request_ack(
smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_pkbuf_t *pkbuf)
{
smf_ue_t *smf_ue = NULL;
int rv, i;
NGAP_HandoverRequestAcknowledgeTransfer_t message;
NGAP_UPTransportLayerInformation_t *dL_NGU_UP_TNLInformation = NULL;
NGAP_UPTransportLayerInformation_t *dLForwardingUP_TNLInformation = NULL;
NGAP_QosFlowListWithDataForwarding_t *qosFlowSetupResponseList = NULL;
NGAP_QosFlowItemWithDataForwarding_t *qosFlowSetupResponseItem = NULL;
NGAP_GTPTunnel_t *gTPTunnel = NULL;
ogs_assert(pkbuf);
ogs_assert(stream);
ogs_assert(sess);
smf_ue = smf_ue_find_by_id(sess->smf_ue_id);
ogs_assert(smf_ue);
ogs_debug("HandoverRequestAcknowledgeTransfer");
rv = ogs_asn_decode(&asn_DEF_NGAP_HandoverRequestAcknowledgeTransfer,
&message, sizeof(message), pkbuf);
if (rv != OGS_OK) {
ogs_error("[%s:%d] Cannot decode NGAP message",
smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No N2 SM Info Type", smf_ue->supi);
goto cleanup;
}
rv = OGS_ERROR;
dL_NGU_UP_TNLInformation = &message.dL_NGU_UP_TNLInformation;
if (dL_NGU_UP_TNLInformation->present !=
NGAP_UPTransportLayerInformation_PR_gTPTunnel) {
ogs_error(
"[%s:%d] Unknown dL_NGU_UP_TNLInformation->present [%d]",
smf_ue->supi, sess->psi, dL_NGU_UP_TNLInformation->present);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"Unknown dL_NGU_UP_TNLInformation->present", smf_ue->supi);
goto cleanup;
}
gTPTunnel = dL_NGU_UP_TNLInformation->choice.gTPTunnel;
if (!gTPTunnel) {
ogs_error("[%s:%d] No GTPTunnel", smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No GTPTunnel", smf_ue->supi);
goto cleanup;
}
rv = ogs_asn_BIT_STRING_to_ip(&gTPTunnel->transportLayerAddress,
&sess->handover.gnb_n3_ip);
if (rv != OGS_OK) {
ogs_error("[%s:%d] No transportLayerAddress", smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No transportLayerAddress", smf_ue->supi);
goto cleanup;
}
ogs_asn_OCTET_STRING_to_uint32(&gTPTunnel->gTP_TEID,
&sess->handover.gnb_n3_teid);
qosFlowSetupResponseList = &message.qosFlowSetupResponseList;
for (i = 0; i < qosFlowSetupResponseList->list.count; i++) {
qosFlowSetupResponseItem = (NGAP_QosFlowItemWithDataForwarding_t *)
qosFlowSetupResponseList->list.array[i];
if (qosFlowSetupResponseItem) {
smf_bearer_t *qos_flow = smf_qos_flow_find_by_qfi(
sess, qosFlowSetupResponseItem->qosFlowIdentifier);
if (qos_flow) {
ogs_pfcp_far_t *dl_far = qos_flow->dl_far;
ogs_assert(dl_far);
dl_far->handover.prepared = true;
} else {
ogs_error("[%s:%d] No QoS flow", smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No QoS flow", smf_ue->supi);
goto cleanup;
}
}
}
dLForwardingUP_TNLInformation = message.dLForwardingUP_TNLInformation;
if (dLForwardingUP_TNLInformation) {
if (dLForwardingUP_TNLInformation->present !=
NGAP_UPTransportLayerInformation_PR_gTPTunnel) {
ogs_error(
"[%s:%d] Unknown dLForwardingUP_TNLInformation->present [%d]",
smf_ue->supi, sess->psi, dL_NGU_UP_TNLInformation->present);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"Unknown dLForwardingUP_TNLInformation->present",
smf_ue->supi);
goto cleanup;
}
gTPTunnel = dLForwardingUP_TNLInformation->choice.gTPTunnel;
if (!gTPTunnel) {
ogs_error("[%s:%d] No GTPTunnel", smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No GTPTunnel", smf_ue->supi);
goto cleanup;
}
rv = ogs_asn_BIT_STRING_to_ip(&gTPTunnel->transportLayerAddress,
&sess->handover.gnb_dl_ip);
if (rv != OGS_OK) {
ogs_error("[%s:%d] No transportLayerAddress",
smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error_log(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No transportLayerAddress", smf_ue->supi);
goto cleanup;
}
ogs_asn_OCTET_STRING_to_uint32(&gTPTunnel->gTP_TEID,
&sess->handover.gnb_dl_teid);
sess->handover.indirect_data_forwarding = true;
}
sess->handover.prepared = true;
if (sess->handover.indirect_data_forwarding == true) {
if (smf_sess_have_indirect_data_forwarding(sess) == true) {
ogs_error("We found redundant INDIRECT Tunnel");
ogs_error("It will be automatically removed");
ogs_assert(OGS_OK ==
smf_5gc_pfcp_send_all_pdr_modification_request(
sess, stream,
OGS_PFCP_MODIFY_INDIRECT|
/*
* Firstly, OGS_PFCP_MODIFY_REMOVE is only appled.
* And then, after receiving PFCP response message,
* we can apply OGS_PFCP_MODIFY_CREATE.
*
* PFCP build is implemented as below.
*
* if OGS_PFCP_MODIFY_REMOVE
* else if OGS_PFCP_MODIFY_CREATE
* else if ..
* ...
*/
OGS_PFCP_MODIFY_REMOVE|OGS_PFCP_MODIFY_CREATE,
0));
} else {
smf_sess_create_indirect_data_forwarding(sess);
ogs_assert(OGS_OK ==
smf_5gc_pfcp_send_all_pdr_modification_request(
sess, stream,
OGS_PFCP_MODIFY_INDIRECT|OGS_PFCP_MODIFY_CREATE,
0));
}
} else {
ogs_pkbuf_t *n2smbuf = ngap_build_handover_command_transfer(sess);
ogs_assert(n2smbuf);
smf_sbi_send_sm_context_updated_data(
sess, stream, 0, OpenAPI_ho_state_PREPARED,
NULL, OpenAPI_n2_sm_info_type_HANDOVER_CMD, n2smbuf);
}
rv = OGS_OK;
cleanup:
ogs_asn_free(&asn_DEF_NGAP_HandoverRequestAcknowledgeTransfer, &message);
return rv;
}
|