# 高等計算機網絡
[TOC]
---
## 期中論文整理(Passive Wi-Fi: Bringing Low Power to Wi-Fi Transmissions, NSDI 2016)
### Introduction
- Observation:
- Wi-Fi transmissions on sensors and mobile devices still consume hundreds of milliwatts of power
- This paper proposes backscatter communication to directly generate Wi-Fi transmissions that can be decoded on any of the billions of existing devices with a Wi-Fi chipset.
- A Passive Wi-Fi that demonstrates for the first time that one can generate 802.11b transmissions using backscatter communication, while consuming 4–5 orders of magnitude lower power than existing Wi-Fi chipsets.
- because passive wifi devices have no analog components (consume many power)

- Proposed Architecure:
- The passive Wi-Fi devices perform digital baseband operations like coding and modulation, while the power-consuming RF components such as frequency synthesizers and power amplifiers are delegated to a single plugged-in device in the network.
### Three main challenges to backscatter WiFi signal
1. How can Wi-Fi receivers decode in the presence of interference from the plugged-in device?
- Traditional backscatter systems use a full-duplex radio to cancel this strong interfering signal, which is not possible on existing Wi-Fi devices.
2. How can we create 802.11b transmissions using backscatter?
- To synthesize Wi-Fi transmissions, paper leverages that 802.11b uses DSSS and CCK encoding on top of DBPSK and DQPSK modulation
3. How do passive Wi-Fi devices share the Wi-Fi network? (collision problem)
- Motivation: Traditional Wi-Fi shares the network using carrier sense (CSMA). However, this requires a Wi-Fi receiver that is ON before every transmission, which require power-consuming RF components such as ADCs and frequency synthesizers
- Solution: delegate all the power-consuming task of carrier sense to the plugged-in device plug-in device and also be used to arbitrate the channel between multiple passive Wi-Fi devices and address other link-layer issues including ACKs and retransmission
### Section 2 Passive Wifi Design
- Our design has two main actors: a plugged-in device and passive Wi-Fi devices
- The former contains power consuming RF components including frequency synthesizer and power amplifier and emits a single tone RF carrier. It also performs carrier sense on behalf of the passive Wi- Fi device and helps coordinate medium access control across multiple passive Wi-Fi devices
- The passive Wi- Fi device backscatters the tone emitted by the plugged-in device to synthesize 802.11b transmissions that can be decoded on any device that has a Wi-Fi chipset.
#### Section 2.1 Primer for 802.11b Transmissions
- 802.11b requires generating the coded bits using either DSSS or CCK and then modulating these bits with DBPSK or DQPSK.

- 802.11b 提供兩種傳輸功能 ( 4 種傳輸速率:1 Mbps、2 Mbps、5.5 Mbps、以及 11 Mbps)
1. HR/DSSS (High Rate DSSS, 高速直接展頻) 模式,可提供 5.5 Mbps 與 11 Mbps 的傳輸速率;
2. 802.11 DSSS 模式,可提供 1 Mbps 和 2 Mbps 的速率
- 其中 1 Mbps 採用 DBPSK(Differential Binary Phase Shift Keying)調變技術,2 Mbps 採用 DQPSK(Differential Quadrature Phase Shift Keying, 這兩種都採用 11-chip 的展頻碼。優點是抗干擾、防竊聽
- 至於高速傳輸模組(HR/DSSS)(5.5 Mbps 與 11 Mbps) 是採用 CCK 調變方式,展頻碼長度為 8,而且建構於互補碼(Complementary Code)的機制下,這種展頻碼隨時間展開而形成一種複數型態的 8-chip 記號。HR/DSSS 是利用每個符號週期(Symbol Period)傳送的資料,來區別 5.5 Mbps 或 11 Mbps,在 5.5 Mbps 的傳輸模式下,每個符號週期傳送 4 個位元;而在 11 Mbps 的模式下,每個符號週期是傳送 8 個位元。
#### Section 2.2 Backscatter Communication Primer
- A device that can switch the impedance of its antenna between two states (一種可以在兩種狀態之間切換其天線阻抗的設備 (雷達橫切面?天線?),他可以反射信號,讓訊號隨著阻抗的改變而改變, 1 和 0 之間)
#### Section 2.3 802.11b using passive Wi-Fi (Generating a Wi-Fi packet using backscatter)
- Challenges:
1. Backscatter signal is much weaker than the tone transmitted by the plugged-in device. A Wi-Fi receiver would suffer significant in-band interference from this tone preventing it from decoding. (如何在有干擾的情況下進行辨識和解碼)
2. Second, the passive Wi-Fi device has a single digital switch that toggles between two impedance states, resulting in a binary signal. It is unclear how one may generate Wi-Fi transmissions using such a binary system. (backscattering 的技術會產生 1 和 0,兩種狀態,但是目前還沒有研究說明如何產生 wifi signal)
- Transmissions at the plugged-in device:
- Step 1, Shifting the tone from the plugged-in device using backscatter)
- 利用頻率為 $\Delta f$ 下的方波將兩個正弦信號相乘,產生移動頻率 (根據三角函數...)
- 
- 
- 前提: 要求 802.11b 接收器能夠在相鄰 band 中的干擾比 in-band 信號大 35 dB 的情況下將靈敏度降低至不超過 6 dB (因為轉換之後的信號比較弱)
- Step 2, Synthesizing 802.11b transmissions using backscatter
- 調整天線的橫切面?以$\Delta$f 的頻率調製天線,讓輸入信號產生頻移(相位差調變)。(一個叫 cross section 的技術)
- 使用 DBPSK 或 DQPSK 對 802.11b 中的所有 bit rates 進行相位差調變 (分別可以產生 00 01 10 11 四個訊號)
- 
- 
#### Section 2.4 Analyzing Passive Wi-Fi’s Range
- In passive Wi-Fi, the communication range depends on two parameters:
1. the distance between the plugged-in device and the passive Wi-Fi transmitter
2. the distance between the passive Wi-Fi transmitter and the Wi-Fi receiver.



### Section 3 Passive Wi-Fi Network Stack Design
Describe how passive Wi-Fi devices share the ISM band (collison problem)
- Same as CSMA (carrier sense), detect and transmit only when the channel is are found free
- All detection work are delegate to pulg-in devices
- Requires a Wi-Fi receiver that is ON before every transmission (power consumption)
- Solution: use a passive energy detector with analog components and a comparator to distinguish between the presence and absence of energy

### References
- [CCK Modulation](http://wshnt.kuas.edu.tw/network/n5/%E8%A8%88%E7%AE%97%E6%A9%9F%E7%B6%B2%E8%B7%AF2098304106%E9%AD%8F%E7%A2%A9%E5%AE%8F.htm)
- [BDPSK & DQPSK](https://www.techbang.com/posts/15863-introduction-to-network-infrastructure-5-80211-and-80211a?page=2)
## Discussion
- 只能對單一種類的 plugin devices
- 一對一的devices
- receiver 的 power consumption
- sender 只發送,不接收?
---
整理(目的: 如何產生一個 WiFi 訊號,如何處理訊號碰撞的問題):
1. Backscaterring 的訊號比一個場域中的 plugin devices 發出的訊號弱,為了避免被干擾
---
## CHP7: Wireless and Mobile Network
- 重點/挑戰 (本章節會討論到的):
1. (Wireless) 無線的特性,既傳遞資料的方式
2. (Mobility) 移動中如何上網
### Wireless

- Element of Wireless Network
1. 特點: “蜂巢式” 形狀(只是大家講好的,真正的不一定是這樣的)
2. 中間的基地台(也有 AP,access point),會因為功率不一樣,範圍不一樣)
3. 在行動網絡下,基地台的重疊是必要的,因為需要一個連結轉移的緩衝 (提供 mobility)
4. 基地台有些是無線的(毫米微波,非常高頻,但是穿透率低,例如 5G 目前正在往這個方向發展,好處是部署方便)
5. 無線的環境中其中一個挑戰是衝突 (collision), 在同一個基地台範圍內同時有一個以上的人連結一個基地台 -> multiple access protocol
6. 每一個(廠商)基地台有不一樣頻段(越高越快但越短),例如大家搶5G,是因為衝突和供應商的問題
- 兩種傳輸模式
1. infrastructure mode: 從基地台到另一個基地台 (hand-off)
- 又分為 single-hop (例如 wifi ?) 和 multi-ple hop (例如利用基地台幫助很遠的基地台進行傳輸,也叫 mesh network)
2. ad-hoc mode: 既然每一個電腦可以傳輸,每一個電腦(node),都可以彼此傳輸,以後可能常用的是車的網絡
- 分為 single-hop (例如藍芽) 和 multi-ple hop (例如車聯網)
### Wireless Characteristic
- 三大(跟有線網絡不同的地方)
1. decreased signal strength: 強度隨著距離減弱
2. interference from other sources:每一種功能會有獨立的頻段,防止干擾
3. multipath propagation:訊號能夠反射,到達目的地的路徑會有很多個,會有時間差的挑戰

- 基本概念 SNR(Signal-to-Noise Ratio),能夠傳輸的 data 小,但是比較不會出錯,能量消耗小 (不同的技術)
- SNR 和 BER (bit-error-rate) 有關
- 利用 ECC (Error Correction Code)

- Hidden Terminal Problem (資料衝突或碰撞問題),如果 A C 不能夠做 communication 的話,就不知道誰應該先後傳給 B
- 在行動電話網絡裡面使用 CDMA (之前是 TDMA 和 FDMA)
- CDMA 是 Code Division Multiple Access (4G沒有用CDMA,是因為高通擁有大部分的專利,大家就不用...)
- CDMA 主要是讓把疊加的碰撞讓接受端能夠分別出來
- 用 encoding 和 decoding 的方法
- 如下圖: 每一個人有一個獨立的 code (條件是 code 必須是 orthogonal 的)
- 最重要最大的問題,就是兩個 sender 的 poewr 必須是一致的,不然在做疊加的時候會不平均... (接受端受到的音量一樣,發送端必須一直做溝通)
- code 越短,速度越快

### 802.11 Wireless LAN

- 特性 (b 最基礎,頻率是 2.4 到 2.5)
- 全部都用 CDMA/CA (multiple access) 和 ad-hoc version
- 沒有基地台
- AP 涵蓋的範圍是 BSS (Basic Service Set)
- 被分割成 11 個 channel,一開始在選 wifi 的 AP 的時候就需要選擇 channel(手動和自動)
- 自動會自動 scan,然後選擇不要跟附近一樣的 channel (比較快) (因為 802.11b 在分割 channel 的時候頻率沒有分很開,會有干擾)
- 一個 AP 會固定在一個 channel 上
- 所有的 host 在連上 AP 是要先跟 AP 有溝通先 (association)
- 步驟: scan channels (AP 會定期發送 beacon frames,告訴要連結的人這個 channel 有沒有別的 AP 在附近)
- 在 802.11 裡面的 scan 分為兩種
- 被動和主動,主動是如果一定的時間沒有受到 beacon 就會發送 request 給附近的 AP
- 802.11 的 multiple access protocol (避免兩個以上的 AP 的碰撞)
- 之前是 CSMA: 在傳送之前偵測 (有線網絡的時候是一面送一面做 collision detection,但是 802.11 是沒有的,單一天線沒辦法做到)
- 所以一開始的時候是在做 collision avoiding (資料碰撞的時候接受端無法分辨,只有一根天線,沒有辦法知道自己傳送的時候是碰撞的)
- 兩根天線就是 collision detection
- CSMA/CA 步驟 (一個 channel 同時只有一個 AP 在做事):
1. (sender) 先聽一段時間,沒有人傳自己再傳
2. (sender) 如果是 busy 的,那麼就會倒數一個 backoff time
1. (receiver) 沒有 collision 就回傳 ACK

- 另外,也有避免送很長的 data (因為長時間如果都撞到那麼就會浪費很長的時間)
- receive 發送 CTS 去告訴別人有人已經搶到了 (包含接下來的時間)
- 所以步驟是:
1. sender 送 RTS
2. AP 送 CTS
3. 拿到的人 send DATA
- 802.11 和 CDMA 的差別是 CDMA 不需要做 sync,802.11 全部是 sender 自己就可以完成 (浪費資源,但硬體需求少)
- 802.11 的 frame: addressing (4個)
1. AP (中間)
2. Sender
3. Receiver
4. ...
- 802.11 中 mobility 的 issue
- 從 BSS1 到 BSS2 的轉換
- 兩個 AP 需要一樣的 IP 才可以支援 mobility
- 轉到不一樣的 BBS 的時候,有一個問題: 下行的 data 怎麼知道要從另一個 AP 傳給我? switch 有 self-learning,是 switch 有 table 紀錄,當 switch 發現你的 H1 在的 host 改變了 (但是只有上行的時候才會知道,這是一個缺點)
- 802.11 的 advance capabilities
- 會自動去選擇 protocol (SNR 和 BER),host比較靠近AP的時候選擇比較強的
- 802.11 的 power management (省電)
- node-to-AP: node 沒有事情的時候會睡覺,每一次定時醒來問 AP 有沒有東西要送給我 (AP 透過 beacon frame 告訴 node 有什麼資訊要送) (下)
- 上(up-link)的時候就是不會睡覺,會醒來並且去競爭 channel
- 802.15 (bluetooth):personal area network
- 目的是 cable-less,是方便
- ad-hoc mode,配對的時候會決定 master 和 slave,先的人是 slave
---
### Cellular Network (行動電話網絡)

- 特性:交換機需要知道 user location (在哪裡) (哪一個基地台的範圍)
- MSC (交換機)(mobile switching center):location,connection,call setup
- 兩個傳輸方式
1. FDMA 和 TDMA
2. CDMA
### 發展
- 2G: GSM 系統,主要是打電話,SIM 卡的設計 (FDMA / TDMA)
- 有 4 層,目的是簡化 BSC 的功能,讓他專心在做 location detection
- 3G:
- 用 CDMA
- 頻寬變大,目的是 data 的傳輸
- data 是走 IP 的方式,voice 和 data 是分開和平行的,只有前端是共用 (public telephone network 和 public network)
- 4G:
- 巨大的改變:沒有 voice 了,全部都用 data
- 但是現在的 4G 在打電話還是用 3G,因為原本的設備很浪費
- 全部都是 IP core
- 5G: IoT
- 有很多不一樣的類型
- 很多 access 的點
- 不一樣的類型不一樣的需求
- 例如:車聯網 需要超級可靠的,超級低延遲的,但是可能不需要大量的 data
- ultra low latency: 因為大家都用 cloud,所以有 edge devices (fog computing) 的產生 (但是越來越快不就是要全部都cloud 嗎?), 儲存的資料也可以部分 local
### Mobility
- 你原本在的叫 home network,需要有一個 permanent address,通過 home agent 跟外面的人做溝通,在外面的 address 是 care-of-address
- 移動到的地方是 visited network,處理你位置的叫 foreign agent
- correpondent 在找你,你會跑來跑去 (mobility 的 issue)
- Mobility 的作法有兩種:
1. 讓一個強大的 router 去 handle: 你去哪裡他都找得到你
2. (現在都用這個)讓 end-systems 去 handle: 分為
- Indirect routing: 讓別人跟媽媽聯絡,媽媽 forward 給你 (你要去哪裡,你必須要對 home agent 做 register 的動作,home network) (三角傳輸),送回去的時候是直接送到目的地,不用轉 (home agent 和 foreign agent 幫忙轉訊息)
- Direct routing: 你去哪裡都跟別人講一下 (直接問 home agent 你的位置在哪裡,知道之後直接傳給你) (但是如果你的位置改變了,就 gg 了,所以一直都要跟你的 home agent 問你的問題) (correpondence 需要 aware-of 你的位置,但是 indirect 就不用)
### Vocabulary
- 到現在都沒有辦法解決的問題,是當你的 IP 換了之後,連線依然不會中斷 (例如在 A 地點看 youtube,走到 B 地點,會斷)
- 這是因為現在的 TCP ,TCP 是綁定 IP 的,換IP就要重新 handshake
- 要解決就是你的 IP 永遠都不會換
- 最簡單的作法就是每一個人都有一個 permenant address (IP 不夠用)
### Mobile IP (沒有被實現?)
- 三個標準
1. indirect routing
2. agent discovery
3. registration with home agent
- 到每一個基地台,基地台都會告訴(advertisement)你到了新的位置,你就要做 register
### 行動電話的 Network Architecture (GSM)

- correspond -> network -> WSC(交換機) -> 基地台 -> 我
- 行動電話也有 home network ,就是電信商,別人打給你就是打給你的電信商的 homne network,你的 home agent 把東西傳給你 (他知道你的位置)
- GSM Handoff (轉換基地台) (基地台強迫或我們主動)
- 路徑一直增加,好處連線不會斷,壞處是 anchor 可能會很長 (實務上不太會)


---
## Chapter 8: Network Security
### Introduction
- 網絡安全三個原則(要求):
1. Confidentiality: 防止別人知道信息內容,方法為加解密
2. Authentication: 確認對方是我想的那個人,驗證
3. Message Integrity: 防止信息被篡改,驗證
4. Access and Availability: 能夠 access 雙方的連結也是一個手段和網絡安全領域需要注意的議題 (但相對比較次要?)
- 網絡安全中的攻擊類型:
1. Eavesdrop 偷聽
2. Insert Fake Message 加入非原始信息
3. Impresonation 假冒身分 (Spoofing)
4. Hijacking 做 “man in the middle”
5. Denail of Service 讓網絡或服務器的 services 中斷
- 加密方法主要分為兩大類
1. Symmetric Key,最大的挑戰是如果交換 key,後如何知道要用哪一把 key (key cycling),例如: DES, AES (私鑰)
2. Asymmetric Key, 也叫 public key (公開金鑰) (有交換率)
- 有兩個 key,一個是 private,一個是 public (public key 做加密,private key 做解密)
- 挑戰就是 encrytion algorithm 可以同時被兩個 key 加解密,並且兩個是不能被逆推的
- 例如,RSA,RSA 的缺點是時間長,所以有 3
3. Session Key: 1 和 2 合併,用 2 把 1 的 shared key 做安全的交換,那麼之後的交換都是安全的了 (沒有人知道 shared key 是什麼)
### Message Integrity 和 Authentication
- Authentication 中比較常見的是 playback attack (中間者竊取A的資料,並且假裝成A與B對話)
- 解決方法: 利用 nonce (once-in-a-lifetime)
- 缺點: 如果T能夠早一步的擷取並回應,就會成功 (這邊最簡單的方式就是加密,因為通常認為解密是需要時間的,會比AB對話來得慢)
- 其中 ap4.0 用 shared symmetric key,ap5.0 用 nonce + public key
- 如果 T 能夠全程偷聽,就能夠一直扮演 AB 的角色 (必須每一個信息都攔截)(public key 的缺點),這就是 man in the middle attack
### Ditigal Signature 數位簽章
- 目的就是確保文件擁有者是那個人 (法律上,商業上等等)
- Main idea 是用 private key 加密 M,傳送 E(M) + M 給對方,對方用 public key 解密得到 M',如果 M' = M,那麼就可以認為這個是對方簽名的信息
- 缺點:時間很長
### Message Digest
- 解決上面時間很長的問題,利用 hash function
- 這裡的 Hash funtion 的條件是:
1. many-to-one
2. fixed finger-print (msg digest)
3. 不能被逆推
- 例如,internet checksum (在 IP protocol 有用)
- 缺點是容易找到一樣的 hash value (簽帳對比是對比 hash)
- sender 送 E(H(M)) 和 M
- receiver 解密 E(H(m)) 並且對 M 做 hash 看是不是一樣
- 常用的 hash 是 SHA-1 和 MD5
### Public Key 的 Certification
- 防止T全程偷聽,所以我們應該要有一個平台去拿到公平的 public key (而不是跟對方拿)
- CA (Certification Auhorithy): 管理PK的平台(就是管理憑證),平台會去 sign public key(兩層防護)
### Securing Email
### SSL (Secure Socket Layer)
- 同時能保證 Confidentiality,Authentication,Message Integrity
- 主要是用在長時間的傳輸 (byte streams 和 interactive data)
- 因為類似傳統的方法在長時間的傳輸上只利用一個 key,給攻擊者更過時間和機會破解,所以 SSL 在整個長時間的 connection 都會被一組會持續產生的 key 保護 (key derivation)
- 想要交換 certificate (方法: Handshake)
- MAC = Integrity
- Handshake + Enceytion = Confidentiality
- Certification with CA = Authentication 身分的正確性
#### Toy SSL (SSL 必要的功能)
- 步驟包含:
1. Handshake
2. Key Derivation
3. Data Transfer
4. Connection Closure

- **Handshake**: A 先跟 B 請求 public key,B 把 public key 和 certificate 一起傳給 A,A 在驗證 B 是 B 之後就用剛剛得到的 public key 加密 master key (用來產生之後的所有的 key)
- **Key Derivation**: 一共 4 把,MAC 和 data 各各1把
- 避免用同一把key做長時間的加密容易被破解
- **Data records**: 原始的TCP並沒有信息長度的明確定義(一個長度 M ),TCP 可能是在很多segment之後,在最後一個segment才檢查是不是正確的,在很長的 stream 下更嚴重
- SSL 每一個 record 都有 MAC 確保正確性
- **其他**:
1. TCP 容易被 re-order attack,造成重組的問題,方法:sequence number 加在 MAC 裡面 (什麼東西都放進去 MAC 裡面)
2. 攻擊者可能會使用 replay attack,方法:nonce
3. Truncation attack: 去關閉與 server 的 connection?方法:type 會放在 MAC 裡面
MAC (用 shared secret key 做加密,目的是在同時擁有 secret key 的情況下,digest 的 內容還受到一定程度的保護,確保 integrity 和 authentication)

### Real SSL
1. 定義欄位和長度
2. 加解密演算法的選擇 (也有的會使用 multiple algoeithm 的)
#### Handshake
- 目的:
1. server authentication
2. Negotiation: agree on crypto algorithms
3. Establish keys (交換 master ket)
4. Client authentication (optional)
- 步驟:
1. A send 演算法給 B 選擇 (+nonce, 防止 T replay attack)
2. B send 演算法 + public key certificate + nonce (certificate 是跟 CA 申請的)
3. A 解密檢查 B 是不是 B,是的話就拿這個解密得到的 public key,並且產生一個 pre-master secret (shared key),把這個送給 B
4. 然後就可以開始 communication 了
5. A 把 1234 再加密送給 B
6. B 把 1234 再加密送給 A
- 56 是確保 1 到 4 有沒有被別人篡改 (例如,刪掉某些很難的演算法),是不是跟一開始一樣

### SSL 細節
- SSL record protocol (SSL 的 format)
- data -> 很多 data fragment -> 每一個會再加一段 MAC -> 用 shared generated key 加密 -> 最後在前面加一些資訊
- 圖在選擇 algorithm 是在後面,但是沒有差別
- key derivation (一般 4 把,因為特定的演算法需要另外的 key 所以有 6)