2022年5月29日 星期日

USB Communication Device Class

Base Class 02h,通訊裝置包括電話、PSTN/DSL/Cable 數據機、ISDN、Ethernet/ATM/無線/行動網路。

Class CodeSubClass說明
02h 01hDirect Line Control Model[USBPSTN1.2]
02h 02h 00hAbstract Control Model (CDC-ACM)No Class Specified Protocol [USBPSTN1.2]
02h 02h 01hAT commands [V250] [USBPSTN1.2]
02h 03hTelephone Control Model[USBPSTN1.2]
02h 04hMulti-Channel Control Model[USBISDN1.2]
02h 05hCAPI Control Model[USBISDN1.2]
02h 06hEthernet Networking Control Model[USBECM1.2]
02h 07hATM Networking Control Model[USBATM1.2]
02h 08hWireless Handset Control Model[USBWMC1.1]
02h 09hDevice Management[USBWMC1.1]
02h 0AhMobile Direct Line Model[USBWMC1.1]
02h 0BhOBEX[USBWMC1.1]
02h 0ChEthernet Emulation Model[USBEEM1.0]
02h 0DhNetwork Control Model[USBNCM1.0]

一個 CDC 裝置必須支援兩個 Interface,一個描述所支援的功能,另一個描述資料傳輸的通道,透過 IAD (Interface Association Descriptor) 將兩者宣告屬於同一個 function。

RS232 over USB

Ethernet over USB:透過 USB 傳送 Ethernet frames,達到這的目的協定有 Microsoft 的 Remote Network Driver Interface Specification (RNDIS)、CDC Ethernet Control Model (ECM)、CDC Ethernet Emulation Model (EEM)、和 CDC Network Control Model (NCM)。

ECM 用在 USB full speed。

EEM is intended for use in communicating with devices, using Ethernet frames as the next layer of trans- port. It is not intended for use with routing or Internet connectivity devices, although this use is not pro- hibited.

NCM 改良 ECM 1.2 支援更高 data rates:單一 USB 傳送可送多個 Ethernet frames,並可指定偏好位置減少處理 overhead。NCM 定義兩種 encapsulating datagrams,一種長度可達 64KiB 可放 40 Ethernet frames,另一種達 4GiB 支援 High Speed 和 SuperSpeed data rates。一個 NCM function 包含一個 NCM Communications Interface 和一個 NCM Data Interface。NCM Communications Interface 用來設定和管理 the networking function。NCM Data Interface 使用定義的 endpoints 來傳送 data。

參考

  1. http://pollos-blog.blogspot.com/2014/10/rs232-over-usb.html
  2. https://en.wikipedia.org/wiki/Ethernet_over_USB
  3. https://www.usb.org/document-library/network-control-model-devices-specification-v10-and-errata-and-adopters-agreement
  • 比較:Video、MTP 傳送特定應用協定

2022年5月28日 星期六

USB Device Classes

USB 裝置提供 Class Code,讓來自不同製造商的裝置可使用通用驅動程式,資訊包括 3 bytes:Base Class、SubClass、和 Protocol,可用在 Device Descriptor 或 Interface Descriptors。

Base ClassDescriptor說明
00hDevice使用在 Interface Description 的 class 資訊。
01hInterfaceAudio
02hBothCommunications Device Class (CDC)
03hInterfaceHID (Human Interface Device)
05hInterfacePhysical
06hInterfaceImage (PTP/MTP)
07hInterfacePrinter
08hInterfaceMass Storage
09hDeviceHub
0AhInterfaceCDC-Data
0BhInterfaceSmart Card
0DhInterfaceContent Security
0EhInterfaceVideo (UVC)
0FhInterfacePersonal Healthcare
10hInterfaceAudio/Video Devices
11hDeviceBillboard Device Class
12hInterfaceUSB Type-C Bridge Class
3ChInterfaceI3C Device Class
DChBothDiagnostic Device
E0hInterfaceWireless Controller
EFhBothMiscellaneous
FEhInterfaceApplication Specific
FFhBothVendor Specific

http://www.howtogeek.com/192732/android-usb-connections-explained-mtp-ptp-and-usb-mass-storage/

USB Video Class (UVC)

USB Video Class (UVC)

http://pollos-blog.blogspot.com/2014/10/usb-video-class.html

USB MTP

MTP (Media Transfer Protocol) 是 PTP (Picture Transfer Protocol) 的擴充。PTP 設計只用來下載相片, MTP 可和行動裝置間雙向傳送 music files、media files、以及 personal information。

MTP 是 "Windows Media" 框架的一部分而和 Windows Media Player 關係密切。2008,MTP 成為標準 USB device class,擴充 PTP 並共用相同 class code。2011,成為和 Android 間傳送檔案的標準方式。

參考:

  1. https://en.wikipedia.org/wiki/Media_Transfer_Protocol
  • 相關

2022年5月27日 星期五

Remote Desktop

遠端桌面

Remote Desktop Protocol (RDP) 是 Microsoft proprietary protocol,只運作在 Windows,client 則不限。

Virtual Network Computing (VNC)

X11

NX

參考

2022年5月22日 星期日

Find Duplicate Files

檔案算 checksum -> checksum 排序找出相同的

以下待測試

find . ! -empty -type f -exec md5sum {} + | sort | uniq -w32 -dD
find . ! -type d -exec cksum {} ; | sort | tee /tmp/f.tmp | cut -f 1,2 -d ‘ ‘ | uniq -d | grep -hif – /tmp/f.tmp > duplicates.txt 

移除檔案

GUI

2022年5月20日 星期五

SSH 協定

SSH (Secure Shell) 協定提供安全的遠端登入和其它網路服務,主要由三層協定構成:

  1. 傳輸層 (Transport Layer) 協定:提供加密、伺服器認證、和完整性保護,也可提供壓縮。一般用在 TCP/IP ,server 通常在 port 22 等候連線,client 發起請求建立連線,然後雙方互送如下識別字串。
    SSH-2.0-softwareversion [SP comments] [CR] LF
    ...
  2. 用戶認證 (User Authentication) 協定 [SSH-USERAUTH] 在傳輸層協定連線建立後認證用戶帳號。
  3. 連線協定 [SSH-CONNECT] 在用戶認證後 multiplexes the encrypted tunnel into several logical channels,可作廣泛應用,例如 setting up secure interactive shell sessions、forwarding ("tunneling") 任意 TCP/IP port 和 X11 連線。

X11 Forwarding

在 *nux 採用 X 視窗系統,包括 X server 和 X clients 兩部分。X server 負責在螢幕上顯示,同時也接受使用者的輸入。X clients 則是一般圖形界面的應用程式,包括一個負責管理桌面的 window manager,為所有其他 X clients 的視窗加上外框。一般 X server 與所有的 X clients 都在同一部機器上執行,但兩者也可以分別位於網路的兩頭。參考:https://www.cyut.edu.tw/~ckhung/b/mi/xintro.php

SSH Server 設定

  • X11Forwarding yes
  • X11DisplayOffset 10 (給Xming用)
  • X11UseLocalhost yes (給Xming用)

開好 X Server,SSH client 啟用 X11 Forwarding 連到 SSH server,SSH server 端的應用程式 GUI 就會轉到 SSH client 端顯示。

Windows 的 X server:X-Win32、Exceed、ReflectionX、Xming、VNC Viewer、X-Deep

參考

  1. RFC 4251:SSH 協定架構
  2. RFC 4253:SSH 傳輸層協定

2022年5月14日 星期六

MAC filesystems

「磁碟工具程式」

APFS (Apple File System):macOS 10.13 或以上預設使用的檔案系統,針對 Flash/SSD 最佳化,也可搭配傳統硬碟 (HDD) 使用。

單一 APFS 容器 (分割區) 可包含多個卷宗。在電腦,macOS 安裝在名為卷宗群組的卷宗上。卷宗群組包含一個用於系統檔案的卷宗 -- Macintosh HD,以及另一個用於資料的卷宗 -- Macintosh HD - Data。容器的可用空間是卷宗共享的,視需要分配至任何個別卷宗。可以指定每個卷宗的保留和配額大小。

每個卷宗可以各自選擇是否加密、檔案名稱和目錄是否區分大小寫。提供空間共享、快照和快速調整目錄大小的功能,並且改進了檔案系統的基礎。

https://support.apple.com/zh-tw/guide/disk-utility/dsku19ed921c/mac

Virtual Network Computing

Virtual Network Computing (VNC) 是一種遠端桌面系統,包括在遠端的 VNC Server 和在近端的 VNC Client/Viewer,透過 Remote Frame Buffer (RFB) 協定更新遠端的桌面和傳送鍵盤滑鼠輸入到遠端來控制電腦。VNC 傳送 framebuffer 的 raw pixel,適用所有視窗系統,雖然可以壓縮,但效率通常比了解圖形如何 layout 的 X11 或 RDP 差。

預設 VNC Client/Viewer 用 TCP port 5900 連到 VNC server (or 5800 for browser access), but can also be set to use any other port。另外 VNC Viewer 也可以用「listening mode」,預設 5500,讓 VNC Server 連,方便 VNC Server 從內部網路出 firewall/NAT。

多個 client 可以同時連到一台 VNC server。

原始 VNC 原始碼和許多衍生 GPL open source,有一些提供額外特異功能,如對 Microsoft Windows 最佳化、提供檔案傳輸等,基本部份還是相容。但也有不相容的。

VNC 和 RFB 是 RealVNC Ltd 的註冊商標。

https://www.iana.org/assignments/rfb/rfb.xml

Sever 試過 UltraVNC 可用

參考

  1. https://en.wikipedia.org/wiki/Virtual_Network_Computing
  2. https://en.wikipedia.org/wiki/RFB_protocol
  • x11vnc 是 VNC Server,hosting an X Window session,顯示目前桌面。
  • novnc
  • 開啟新的桌面環境,而不是目前的桌面環境

2022年5月7日 星期六

RDP

Remote Desktop Protocol (RDP) 是微軟的遠端桌面,只運作在 Windows,client 則不限。

Windows 11 專業版 RDP Server

  • 檢查版本:[開始]→[設定]→[系統]→[關於]→[Windows 規格]→[版本]。家用版需升級至專業版。
  • 啟用:[開始]→[設定]→[系統]→[遠端桌面],將 [遠端桌面] 設定為 [開啟]→[確認]。記下 [電腦名稱],稍後需要。

Linux RDP Client

  • Remmina:支援 RDP、VNC、SPICE、NX、XDMCP、SSH、和 WWW 的 Client。
  • FreeRDP
  • rdesktop
  • Vinagre

Linux RDP Server:Xrdp

「Use all my monitors for the remote session」「將我的所有監視器用於遠端會話」

問題

  • 可以只連一個視窗嗎?好像不行。
  • 遠端有好幾個「桌面」,可以只連其中一個而不影響其它嗎?

2022年5月1日 星期日

SMTP

email 送信的網路協定是 SMTP (Simple Mail Transfer Protocol),在 1980 年代只有 ASCII 純文字,後續有 MIME、Secure STMP over TLS 等擴充,目前 RFC 是 RFC5321。

client ---TCP--> server

port 25、465、587 for TLS

是否加密可透過 negotiation 或 STARTTLS

使用 Gmail 帳號當 STMP server 為例

  • https://myaccount.google.com/lesssecureapps 啟用「less secure apps access」。(似乎不需要)
  • Mail Username: Gmail 帳號
  • Mail Password: 如果有啟用兩段式認證,需要到 https://myaccount.google.com/apppasswords 產生送信時認證用的密碼。
  • SMTP Server: smtp.gmail.com
  • Use STARTTLS: Checked (連線一開始用明文,然後轉換成加密)
  • SMTP Port: 587
  • From Email Address: Also my personal Gmail email address
  • To Address: My work email address

送信指令

  • swaks (Swiss Army Knife SMTP) 是 Perl 寫的指令行工具,支援 STARTTLS 及認證。
  • busybox sendmail
  • sendmail
  • mail
  • mutt
  • ssmtp
  • telnet
  • nc

https://www.netburner.com/learn/smtp-for-your-embedded-devices/

email 寄信整體流程
sending MUA –SMTP→ [ MSA → sending MTA] → receiving MTA] –SMTP→ MDA → Mailstore -POP/IMAP→ MUA

MUA: Message User Agent, 如
MSA: Message Submission Agent

SMTP (RFC 5321) 負責 message transport,只看信封或在上面加郵戳,不看信件內容。;而 RFC 5322 定義訊息內容本身。

SIP header Via

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