
Random Access Procedure

RRC Connection Establishment

Attach and Authentication
Địa chỉ IP một số thành phần mạng lõi để tham khảo từ wireshark capture (File capture từ Open5Gs)
MongoDB = 127.0.0.1 (subscriber data) - http://localhost:3000
MME-s1ap = 127.0.0.2 :36412 for S1-MME
MME-gtpc = 127.0.0.2 :2123 for S11
MME-frDi = 127.0.0.2 :3868 for S6a
SGWC-gtpc = 127.0.0.3 :2123 for S11
SGWC-pfcp = 127.0.0.3 :8805 for Sxa
SMF-gtpc = 127.0.0.4 :2123 for S5c, N11
SMF-gtpu = 127.0.0.4 :2152 for N4u (Sxu)
SMF-pfcp = 127.0.0.4 :8805 for N4 (Sxb)
SMF-frDi = 127.0.0.4 :3868 for Gx auth
SMF-sbi = 127.0.0.4 :7777 for 5G SBI (N7,N10,N11)
AMF-ngap = 127.0.0.5 :38412 for N2
AMF-sbi = 127.0.0.5 :7777 for 5G SBI (N8,N12,N11)
SGWU-pfcp = 127.0.0.6 :8805 for Sxa
SGWU-gtpu = 127.0.0.6 :2152 for S1-U, S5u
UPF-pfcp = 127.0.0.7 :8805 for N4 (Sxb)
UPF-gtpu = 127.0.0.7 :2152 for S5u, N3, N4u (Sxu)
HSS-frDi = 127.0.0.8 :3868 for S6a, Cx
PCRF-frDi = 127.0.0.9 :3868 for Gx
NRF-sbi = 127.0.0.10:7777 for 5G SBI
AUSF-sbi = 127.0.0.11:7777 for 5G SBI
UDM-sbi = 127.0.0.12:7777 for 5G SBI
PCF-sbi = 127.0.0.13:7777 for 5G SBI
NSSF-sbi = 127.0.0.14:7777 for 5G SBI
BSF-sbi = 127.0.0.15:7777 for 5G SBI
UDR-sbi = 127.0.0.20:7777 for 5G SBI
S1AP Inital UE Message (Attach request + PDN connectivity request)
Authenticaion Info Request (AIR)

Trong connection, data có chứa những AVP (Attribute Value Pair, định dạng dữ liệu tên-giá trị như JSON hoặc dictionary trong Python)
Trong request, có một số AVP bắt buộc phải có như Session-Id
, Auth-Session-State
, Origin-Host
, Origin-Realm
& Destination-Realm
Một số trường khác có trong request, gồm User-Name, giá trị của trường có cấu trúc: MCC+MNC+… Trong hình dưới đây, giá trị đó chính là IMSI

Requested-EUTRAN-Authentication-Info AVP chứa thông tin liên quan đến xác thực mà MME yêu cầu từ subcriber. Trong AVP này có các AVP con như
- Number-Of-Requested-Vectors: giá trị là số lượng các vector (authentication vector) mà MME sẵn sàng nhận
- Immediatate-Response-Preferred: AVP mang ý nghĩa MME có cần phản hồi ngay lập tức hay không
- Trong một số trường hợp, còn có 1 AVP nữa là Re-Synchronization-Info if the subscriber is re-resyncing the SQN will include a Re-Synchronization-Info AVP (AVP 1411)

Visited-PLMN-Id AVP chứa thông tin về PLMN trong mạng radio mà UE đang kết nối tới, PLMN ID=MCC+MNC

Authentication Info Answer (AIA)
AIA vẫn chứa các AVP bắt buộc phải có như AIR, có thêm một số trường quan trọng, điển hình như Result-Code: như tên của nó, cho biết request có thành công hay không

Tiếp nữa là Authentication-Info: result của request trước, vì trong ảnh trên, phần Number-Of-Requested-Vectors chỉ yêu cầu 1 vector nên response chỉ trả về 1 vector theo yêu cầu. Vector này có những AVP con: RAND, XRES, AUTN, KASME

- RAND: Giá trị random 16 bytes
- XRES (Expected user response): được tạo từ Milenage algorithm, ngoài XRES còn có Anonymity Key (AK), Cipher Key (CK), Integrity Key (IK)
- AUTN = (SQN XOR AK) || AMF || MAC
- Another set of algorithms use the generated AK, CK, IK from the Milenage algorithm to compute KASME.
MME đóng vai trò như một ASME (Access Security Management Entity), và KASME như một chìa khóa để trao đổi dữ liệu giữa UE và MME, là chìa khóa chung
Milenage algorithm gồm 1 loạt các function gồm f1, f2, f3, f4, f5 được định nghĩa bởi 3GPP

Authentication request and response
The MME removes the XRES from the AIA request and packages the the (AUTN, RAND, KASME nhưng không được gửi đi do đó là chìa khóa chung, KASME sẽ được tạo từ AUTN và RAND) into an authentication vector and sends an Authentication Request to the UE.

The UE knows the SQN value to use and contains the corresponding Key (K), OPc values in the USIM and executes the Milenage algorithm using the RAND value that has been provided.
The UE computes a new AUTN value and compares it to the value that has been provided in an effort to authenticate the network to the UE. Once the UE successfully validates the network it is communicating with, it generates a RES which is sent as an Authentication Response to the MME. The MME validates if the response provided RES matches the expected response XRES and sends a successful/unsuccessful authentication message to the UE. The UE is now authenticated and attached to the network.

The UE further computes the Kasme values to compute the necessary AK, CK, IK keys used for encryption and integrity checks in further communications.
More info:
- https://nickvsnetworking.com/diameter-dispatches-s6a-authentication-information-request-answer
- https://medium.com/uw-ictd/lte-authentication-2d0810a061ec
Security mode command
Mục đích: để thiết lập môi trường truyền thông tin bảo mật hơn giữa UE và MME
Security mode command giao tiếp giữa UE và MME, trung gian là eNB nên trong đây sẽ chia ra thành 2 phần nữa
RRC : Downlink Information Transfer + NAS : Security Mode Command

NAS PDU lúc này không được mã hóa do UE chưa có cipher key giải mã, nhưng được integrity, và đính kèm MAC (Message authentication code)
NAS PDU trong Security mode command sẽ chứa thông tin giải thuật mã hóa cho cipher và integrity, giải thuật này sẽ được sử dùng để giao tiếp với UE

Với ciphering, các mode mã hóa gồm có
Identifier | Type | Description |
0000 | 128-EEA0 | Null ciphering algo |
0001 | 128-EEA1 | SNOW 3G |
0010 | 128-EEA2 | AES |
Với integrity:
Identifier | Type | Description |
0001 | 128-EIA1 | SNOW 3G |
0010 | 128-EIA2 | AES |
Security mode command còn chứa những method security mà UE hỗ trợ, nội dung này đã được UE gửi trong Initial UE Message, Security mode command phát lại phần thông tin này.

Trong request này, MME còn có thể yêu cầu IMEISV. IMEISV là MEID của điện thoại nhưng được thêm 2 chữ số cuối để chỉ phiên bản.

If, during an ongoing attach or tracking area updating procedure, the SECURITY MODE COMMAND message includes a HASHMME, the UE shall compare HASHMME with a hash value locally calculated as described in 3GPP TS 33.401 [19] from the entire plain ATTACH REQUEST or TRACKING AREA UPDATE REQUEST message that the UE had sent to initiate the procedure. If HASHMME and the locally calculated hash value are different, the UE shall include the complete ATTACH REQUEST or TRACKING AREA UPDATE REQUEST message which the UE had previously sent in the Replayed NAS message container IE of the SECURITY MODE COMPLETE message.

Security mode complete
Sau khi gửi SECURITY MODE COMMAND, nếu UE thích hợp với những method cipher/integrity như đã gửi ở SECURITY MODE COMMAND, UE sẽ gửi lại response Security mode complete, nếu không sẽ gửi tin nhắn SECURITY MODE REJECT.
Trong tin nhắn có chứa IMSISV nếu như MME yêu cầu.
Trong tin nhắn này, UE sẽ cipher tin nhắn với cipher key được tính từ Kasme đã tính từ bước Authentication request

Update location request
Request được gửi từ MME lên HSS

Request chứa thông tin định danh của UE gửi tới HSS, và một số thông tin khác của UE như Terminal Information,…
Một số thông tin được thêm vào request ngoài những trường buộc phải có đã nêu ở phần Authentication-Info-Request/Answer
- Terminal-Infomation: chứa IMEI và phiên bản phần mềm Software-Version

- URL Flags: Chứa một số flags của UE

- Visited-PLMN-Id: chứa MCC và MNC của nhà mạng
- RAT-Type: chứa thông tin loại mạng radio mà UE đang kết nối tới

Update Location Answer
Gồm các AVP:
- UFA-Flags: bitmask được include khi Result-Code là DIAMETER_SUCCESS
- Subscription-Data: Toàn bộ thông tin subscription profile của UE
Các AVP tiêu biểu trong Subscription-Data:
- Access-Restriction-Data: Bitmask cho phép UE được/không được làm gì
- Subscriber-Status: cho biết Subscriber được cấp phép hay không
- APN-Configuration-Profile: chứa toàn bộ profile APN, có những AVP tiêu biểu
- PDN-Type: Chỉ IP version của APN
- Service-Selection: lựa chọn dịch vụ, theo tôi hiểu là giá trị của APN
- EPS-Subscribed-QoS-Profile: đến đây QoS được cho EPS Bearer được đặt
- AMBR (Argregate Maximum Bit Rate): Có 2 AVP con là tốc độ tối đa uplink và tối đa downlink (bits/second)


ESM information request
Trong luồng attach trên ảnh đầu không có ESM Infomation Request/Answer, trong tài liệu 3GPP 24.301-h50 trang 338, thủ tục này thuộc phần Miscellaneous procedure (linh tinh). ESM Infomation Request/Answer được thực thi khi trong PDN Connectivity request yêu cầu thông tin ESM phải được bảo mật
The ESM information request procedure is used by the network to retrieve ESM information, i.e. protocol configuration options, APN, or both from the UE during the attach procedure if the UE indicated in the PDN CONNECTIVITY REQUEST message that it has ESM information that needs to be sent security protected. The purpose of this procedure is to provide privacy for the ESM information if ciphering is enabled in the network.
3GPP 24.301-h50 trang 338


UE sẽ gửi lại ESM info response bao gồm APN và Protocol Config Option

Thắc mắc: Tại sao không phải MME gửi IP, DNS cho UE mà UE lại gửi thông tin đó cho MME? Rõ ràng là MME cấp cho UE khả năng truy cập internet mà.
(còn tiếp…)