2016年1月30日 星期六

LAPD

ISDN 的 datalink 層是 Q.921,也就是 LAPD (Link Access Procedure on the D-channel),是 HDLC 的 close cousin。

在 frame 之間及閒置時送 Flag (0x7E, 01111110b),而原本 0x7E 的資料為避免和 Flag 混淆,使用了 bit stuffing 機制,也就是資料在傳送端會每遇到 5 個連續 1 會插入一個 0,接收端再移除。如果出現連續 7 個以上的 1,則視為 abort 而忽略收到的資料。

LAPD 格式
AddressControlInformationFCS
21~20~2

LAPD 運作在 Asynchronous Balanced Mode (ABM),也就是兩端是對等的、沒有主從之分,雙向各自獨立運作。2-byte FCS 檢查資料有沒有錯誤,通常用硬體計算,以下說明省略。重送時,每個 octet 的 bit 1 先送。

Address:2-byte
87654321octet
SAPIC/REA
0
1
TEIEA
1
2
  • EA:Address field extension bit,0 表示有下個 byte、1 則沒有。由於固定 2-byte,所以第一個 EA 為 0,第二個 EA 為 1。
  • C/R:0 表示用戶端是發出的指令及網路端的回覆,1 則表示網路端發出的指令及用戶端的回覆。
  • SAPI:Service Access Point Identifier
    • 0:上層是 Q.931 呼叫控制 (GR303 TMC call proc)
    • 1:I.451 封包模式的呼叫控制 (GR303 EOC, TMC switching)
    • 12:teleaction
    • 16:X.25 level 3 封包
    • 63:自己本身 Layer 2 管理
  • TEI:Terminal End Indentifier,在 SAPI = 0 時
    • 0~63:用於非自動指定 TEI 的設備,PRI 使用 0
    • 64~126:用於自動指定 TEI 的設備
    • 127:廣播給所有 Terminal Endpoints
PRI 和點對點 BRI 使用 SAPI 0 TEI 0,點對多點 BRI 使用 SAPI 63 TEI 127。

Control 欄位包括 Q.921 的 frame type、序號等。
Control87654321octet
I FrameN(S)01Information Frame:連線狀態正常及序號正確後往上層丟
N(R)P2

S Frame0000SS011Supervisory Frame:datalink 本身 supervisory 用,看 SS 2-bit
N(R)P/F2

U FrameMMMP/FMM111Unnumbered Frame:Unnumbered 就是沒序號,看 MMM 及 MM 共 5-bit

P/F 在 command 是 poll,在 response 是 final。

IN(S)0I-Frame,有 Information 欄位
S00000001RR (Receive Ready):I Frame 的 acknowledgement,可以再收。
00000101RNR:Indicates a state of temporary occupation of station (e.g., window full)
00001001REJ:重傳給定的序號之後
U000x0011UI (Unnumbered Information),有 Information 欄位 => Q.931。P/F = 0 [Q.921 5.1.1]
010P0011DISC (Disconnect command)
011F0011UA (Unnumbered Acknowledgement response)
100Fx0111FRMR (Framer reject response)
000F1111DM (Disconnected Mode response)
101P/F1111XID (eXchange IDentification):不支援?
011P1111SABME (Set Asynchronous Balanced Mode Extended):command。在連線初始化時決定 window 大小,最大是 128,也就是可以有 128 個 frame 未完成 ACK。由 Address 的 C/R 可看出遠端是 Network 端還是 User 端


window size:modulo 8 待 acknowledge 的 outstanding frames
extended window size:modulo 128,使用不同的 link initialization frame type,frame type 名稱再加上 E,例如 SABM 變成 SABME。

範例:02 01 7f
  • 02 01 (Address):C/R = 1 = network command 或 user response,SAPI = 0 = Q.931,TEI = 0 = PRI or PTP
  • 7F (Control):U frame SABME,P/F = 1
範例:02 01 01 03:RR for Q.931

範例:FC FF 03 0F 5D 72 01 FF F7 6E:TEI Request
  • FC FF (Address):C/R = 0 = user command 或 network response,SAPI = 63 = Layer 2 Management,TEI = 127 = Broadcast connection for all TEs
  • 03 (Control):UI,P/F = 0
  • 0F (Management entity identifier):固定為 0x0F。
  • 5D 72 (Ri):Request number,一個亂數
  • 01 (message type = REQUEST):請求 64 ~ 126 的 TEI,成功的話回覆 2 = ASSIGNED,失敗的話回覆 3 = DENIED。另外還有 4 = CHECK_REQUEST、5 = CHECK_RESPONSE、6 = REMOVE、7 = VERIFY。
  • FF (Ai 及 E-bit):bit 1 為 E-bit,Ai 欄位的 externsion。剩下 7-bit 為 Ai = Action Indicator = 127 = 任何 TEI。
  • F7 6E (FCS)

沒其他訊息時,每 10 秒送 RR 等回應。沒回應,每秒重送最多共四次,之後改送 SABME,也是每秒重送,直到收到 UA。

MDL-ERROR() 錯誤表

Error CodeError ConditionActionError Type
ASupervisory (F=1)Error LogReceipt of unsolicited response
BDM (F=1)Error LogReceipt of unsolicited response
CUA (F=1)TEI removal procedure or 
TEI check procedure, then if TEI:

free: remove TEI
single: no action
multiple: TEI removal procedure

Receipt of unsolicited response
DUA (F=0)TEI removal procedure or 
TEI check procedure, then if TEI:

free: remove TEI
single: no action
multiple: TEI removal procedure

Receipt of unsolicited response
EDM (F=0)Error LogReceipt of unsolicited response
FSABMEError LogPeer initiated re-establish.
GSABMETEI check procedure, then if TEI:

free: remove TEI
single: no action
multiple: TEI removal procedure

Unsuccessful retransmission (N200 times)
HDISCTEI check procedure, then if TEI:

free: remove TEI
single: no action
multiple: TEI removal procedure

Unsuccessful retransmission (N200 times)
IStatus EnquiryError LogUnsuccessful retransmission (N200 times)
JN(R) errorError LogOther
KReceipt of FRMRError LogOther
LReceipt of frame with undefined control fieldError LogOther
MReceipt of I field not permittedError LogOther
NReceipt of frame with wrong sizeError LogOther
ON201 errorError LogOther

參考

  1. Q.921 ISDN user-network interface – Data link layer specification
  2. http://www.freesoft.org/CIE/Topics/125.htm
  • ISDN Q.921-User Adaptation (IUA):透過 IP 傳送 ISDN Q.921 訊息

台灣電信網路編碼計畫

電信網路編碼計畫 (Numbering Plan)

0[01][1-9].國際冠碼 + 國碼 + 區域號碼 + 客戶電話號碼
0[1-8]0X.智慧虛擬碼撥接服務
0[2-8][2-9]XXXXXXX.長途電話
09[0-8]XXXXXXX行動通訊服務
1[0-7]X服務電話
18XXX.撥號選接服務網路識別碼
19XX非營利服務電話
[2-9]X.市話服務 (局碼 + )
X 代表 0 ~ 9

參考來源:
  1. 電信網路編碼計畫
  2. https://en.wikipedia.org/wiki/Telephone_numbers_in_Taiwan
  3. 中華民國長途電話區號表

Q.931 訊息格式

Q.931 格式的基本欄位包括 Protocol Discriminator、Call Reference、及 Message Type,之後的欄位依據 Message Type 的需要而加,稱為 Information Element (IE)。

87654321Octet
Protocol Discriminator1
Call Reference2~
0Message Type
Information Elements as required

Protocol Discriminator 辨別是什麼協定,Q.931 用的值是 0x08,不過還有其它協定:
  • 0x08:Q.931
  • 0x4F:GR303
  • 0x03 或 0x43:維護用
Call Reference 是用在 user-network 界面的通話參考編號,用戶 (user) 端和網路 (network) 端各自獨立編號,由通話建立端決定。

87654321Octet
0000 Call Reference Length1
Flag
2
Call Referenceetc.
  • Call Reference Length:Call Reference 的長度,可能 0 ~ 3
  • Flag:此 call 建立端設為 0,受話端使用時設為 1

Message Type
  • 0000000
  • 00-----:建立通話
    • 0x01 ALERTING
    • 0x02 CALL PROCEEDING
    • 0x07 CONNECT
    • 0x0F CONNECT ACKNOWLEDGE
    • 0x03 PROGRESS
    • 0x05 SETUP:建立通話
    • 0x0D SETUP ACKNOWLEDGE
  • 01-----:通話中
    • 0x26 RESUME
    • 0x2E RESUME ACKNOWLEDGE
    • 0x22 RESUME REJECT
    • 0x25 SUSPEND
    • 0x2D SUSPEND ACKNOWLEDGE
    • 0x21 SUSPEND REJECT
    • 0x20 USER INFORMATION
  • 10-----:掛斷通話
    • 0x45 DISCONNECT
    • 0x4E RELEASE
    • 0x5A RELEASE COMPLETE
    • 0x46 RESTART
    • 0x4E RESTART ACKNOWLEDGE
  • 11-----:其它
    • 0x60 SEGMENT
    • 0x79 CONGESTION CONTROL
    • 0x7B INFORMATION:提供額外資訊,如 overlap sending。
    • 0x6E NOTIFY
    • 0x7D STATUS
    • 0x75 STATUS ENQUIRY
Information Element (IE) 都會有 IE identifier 辨別哪種 IE,有三種格式,前兩種為單一 byte,bit 8 為 1。第三種可變長度,有長度欄位決定內容長度。
type87654321Octet
a1Information element identifierContents of Information element1

b1Information element identifier1

c0Information element identifier1
Length of contents of information element2
Contents of information element3~

IE identifier

10100001Sending complete
0000
1000Cause
00011000Channel Identification:可重複
01110000Called party number
參考
  1. Q.931
  2. LAPD
  3. Q.931 over IP
  4. Q-Interface Signaling (QSIG)
    • 同樣基於 Q.921/Q.931 的一種 D-channel voice signaling 變形,作為 PBX 間溝通用的標準協定,用來建立通話和管理 PBX 間的 QSIG supplementary service,如 Multiple Subscriber Number、Call Waiting、Calling-Line Identification Presentation (CLIP)、Calling-Line Identification Restriction (CLIR)、Connected-Line Identification Presentation (COLP)、Connected-Line Identification Restriction (COLR)、Malicious Call Identification、Call Hold、Advice of Charge、Three-Way Conference、Call Diversion、CFU Supplementary Service、Path Replacement (ANF-PR)、Call Transfer by Join (SS-CT)、Call Completion to Busy Subscriber (CCBS)、和 Explicit Call Transfer。
    • 呼叫來自 private integrated services network exchange (PINX) 再繞到其它 PINX 設備。
    • Tunneling over H.323:H.323 基於 Q.931,旗下包含基本的 H.225.0 和 H.245,和 supplementary services H.450.1。H.323 Annex-M1 有規範 Tunneling QSIG over H.323,但 Cisco 使用 ISDN Generic Transparency Descriptor (GTD) 在對應的 H.225 訊息不變地傳送 QSIG 訊息。沒對應的,則 tunneled 在 H.225.0 FACILITY 訊息。
    • Tunneling over SIP:在 SIP 指示「Content-Type: application/QSIG」、「Content-Disposition: signal; handling=optional」放在 MIME 信體。非 QSIG 的 Q.931 訊息用「Content-Type: application/x-q931」。
    • https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/voice/cube_sip/configuration/15-mt/cube-sip-15-mt-book/voi-sip-trans-tun.pdf
    • https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/voice/sip/configuration/15-mt/sip-config-15-mt-book/voi-sip-tdm.pdf
  • Calling-Line Identification Presentation (CLIP):來電時提供主叫號碼給被叫。
  • Calling-Line Identification Restriction (CLIR):主叫限制提供主叫號碼給被叫。Calling-Line Identification Restriction Ignore:忽略主叫限制提供主叫號碼給被叫,例如撥緊急電話,即使主叫限制提供主叫號碼還是會提供。
  • Connected-Line Identification Presentation (COLP):接通時提供真正的被叫號碼給主叫。
  • Connected-Line Identification Restriction (COLR):被叫限制接通時提供真正的被叫號碼給主叫。
  • http://shannon.cm.nctu.edu.tw/netexp/isdn03.pdf 整體數位服務網路簡介

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...