2013年10月25日 星期五

上網費

客服來電推銷升級 6M,因為原本上傳速度慢了些,所以有點心動,但最後還是維持 4M,Wi-Fi 目前也用不用。

2013/10/26

下載/上傳合計Hinet 上網費電路費老客戶八五折
ADSL4M/128K473269
(原價 299)
204427=254+173
ADSL5M/384K526296
(原價 329)
230476=280+196
光世代
VDSL + Wi-Fi
6M/2M699341
358499 綁約 2 年
註:ADSL 上網費好像有特別降價,但老客戶還是以原價來打折

2013年8月27日 星期二

Ralink Ethernet Driver

OpenWrt 有 Ralink Ethernet Driver

module init
  • debugfs 初始化 (選擇性)
  • esw 初始化
  • 註冊 platform driver:登記 probe 及 remove 函數
platform driver 的 probe 函數
  • get memory base
  • alloc ether net dev
  • get irq
  • 登記 net dev ops:包括 init, uninit, open, stop, start_xmit, tx_timeout, ... 等函數
  • 設定 net dev priv data
  • 註冊 net dev
net dev 的 init 函數
  • ...
  • hardware init
    • request irq
    • alloc 256 rx_info, 256 tx_dma, 256 rx_dma, one skb per rx_info
    • 初始化 tx_dma, 初始化 rx_info dma_addr (來自 skb), 初始化 rx_dma
    • set macaddr to SoC
    • 初始化 SoC tx_dma, rx_dma
    • set sys_freq to SoC
    • tasklet init: tx & rx
    • other SoC init
net dev 的 open 函數
  • ...
net dev 的 start_xmit 函數
  • ...
net dev 的 tx_timeout 函數
  • ...
封包接收
  • ...
硬體加速
  • Hardware NAT, QoS, TCP/UDP/IP checksum offloading
延伸閱讀

2013年8月21日 星期三

Linux bridge

將電腦當作 Ethernet Switch 使用,除了原有的 Ethernet 介面外,需要再多一個 Ethernet 介面,例如用 USB Ethernet,方便第三者抓封包 (註:用既有的 Ethernet Switch 搭配 ettercap 也可以抓封包,參照《第三者 Ethernet 抓封包》)。

Ethernet Switch 的工具軟體在 bridge-utils
sudo apt-get install bridge-utils

軟體 Ethernet Switch 設定
sudo ifconfig eth0 0.0.0.0
sudo ifconfig eth1 0.0.0.0
sudo brctl addbr br0
sudo brctl addif br0 eth0
sudo brctl addif br0 eth1
sudo dhclient br0

設定在 /etc/network/interfaces 的話,新增
auto br0
iface br0 inet dhcp
然後
sudo vi /etc/network/interfaces
sync && sudo init 6

參考:
  1. http://www.linuxfoundation.org/collaborate/workgroups/networking/bridge
  2. Ubuntu 12.04 & 12.10 調校備忘 的 Network bridge
延伸閱讀

寫程式用字型

下載字型檔會開啟「字型檢視程式」,然後按「安裝」就可以使用。
或者放到 ~/.local/share/fonts/,執行 fc-cache -f -v。

Monaco (來自 Apple Inc.)
Consolas (來自 Microsoft)
  • 搜尋「Consolas.ttf」可以找到
設定
cp /etc/fonts/conf.d/69-language-selector-zh-tw.conf ~/.config/fontconfig/fonts.conf
vi ~/.config/fontconfig/fonts.conf # 修改 monospace 那段如下方
fc-cache -f -v
修改內容,只保留
 <?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <!-- Set fonts selection for zh-tw monospace -->
    <match target="pattern">
        <test qual="any" name="family">
            <string>monospace</string>
        </test>
        <test name="lang">
            <string>zh-tw</string>
        </test>
        <edit name="family" mode="prepend" binding="strong">
            <string>Monaco</string>
            <!--string>Microsoft JhengHei</string-->
        </edit>
    </match>
</fontconfig>

註:放字型的目錄
  • ~/.local/share/fonts/
  • /usr/share/fonts/
註:字型相關程式:fc-cache, fc-list 等

參考文章:
  1. Programmer 專用最佳字型 - Monaco font
  2. Monaco + LiHei 字型優化 on Ubuntu 10.04+
  3. Linux 安裝與使用
  4. 電腦漢字體
  5. Ubuntu 14.04 LTS 中文修正 (刪除不需要的設定檔,修改設定檔) 

2013年8月20日 星期二

OpenWrt 套件定義的 KCONFIG

OpenWrt 套件都要定義
define Package/套件名

define KernelPackage/套件名
裡面的一些參數,例如 TITLE:= 是填顯示的標題名稱。

其中有一項是 KCONFIG:=,預設是空的,可用來增加 Kernel 的設定,例如 package/hostap-driver/Makefile 的 define KernelPackage/hostap,就有設定
KCONFIG:=CONFIG_HOSTAP CONFIG_HOSTAP_FIRMWARE=y CONFIG_HOSTAP_FIRMWARE_NVRAM=y
,如果選了 hostap 套件,Kernel 設定就會增加

CONFIG_HOSTAP=m
CONFIG_HOSTAP_FIRMWARE=y
CONFIG_HOSTAP_FIRMWARE_NVRAM=y
,對應到 Kernel 程式,包括外部模組,就會有

#define CONFIG_HOSTAP_MODULE
#define CONFIG_HOSTAP_FIRMWARE
#define CONFIG_HOSTAP_FIRMWARE_NVRAM

的定義。

套件額外的選單設定 define Package/套件名/config 只影響 OpenWrt 的設定,且不會有對應的程式碼定義。

2013年8月17日 星期六

OpenWrt Unified Configuration Interface

Unified Configuration Interface (UCI) 是 OpenWrt 的設定環境,大部分的設定都使用 UCI,然而還有一些設定並不在 UCI

使用 UCI 的設定檔是文字檔,放在 /etc/config/ 目錄下,可以用文字編輯器編譯,也可以透過 uci 指令存取,或者其它程式 API 存取,例如 shell script 的 /lib/config/uci.sh、C library /lib/libuci.so、lua library /usr/lib/lua/uci.so 等,適合用於資源有限不好執行一個資料庫的環境。

uci 設定檔有三層架構
  1. <config>:/etc/config/ 下的設定檔檔名
  2. <section>、<section-type>:每個設定檔內容分成許多 config 開始的 section,section 有 <section-type>。格式是:
    config <section-type> [<section>]
    <section> 是 section 的名稱,可有可無。沒有 section 名稱時用 @<section-type>[index] 的方式存取。
  3. <option>、<value>:每個 section 有 option 或 list。
uci 設定檔格式
config section-type section-name
config section-type
option option-name option-value
list option-name option-value
# 開始為註解註界
config 表示一個 section 開始,type 是必要的,讓程式決定如何應用。可以沒有 name,稱為 anonymous section。
option 提供選項 name 到 value 的對應,list 單一 name 可以有多個 value。

檔案範例 /etc/config/foo
# cat /etc/config/foo

config bar first
        option name 'Mr. First'
config bar
        option name 'Mr. Second'
config bar third
        option name 'Mr. Third'
        list kid aaa
        list kid bbb
首先這裡存在 <config> 檔 foo,內容分成許多 config 開頭的 section,每個 section 有 option 或 list。範例裡 <section-type> 都是 bar。每個 option 定義一對<option> 及 <value>,而 list 讓一個 <option> 有許多 <value>。

<config>、<section>、<section-type>、<option>、<value>

uci 指令:
# uci
Usage: uci [<options>] <command> [<arguments>]

Commands:
        batch  
        export     [<config>]
        import     [<config>]
        changes    [<config>]
        commit     [<config>]
        add        <config> <section-type>
        add_list   <config>.<section>.<option>=<string>
        show       [<config>[.<section>[.<option>]]]
        get        <config>.<section>[.<option>]
        set        <config>.<section>[.<option>]=<value>
        delete     <config>[.<section[.<option>]]
        rename     <config>.<section>[.<option>]=<name>
        revert     <config>[.<section>[.<option>]]
        reorder    <config>.<section>=<position>

Options:
        -c <path>  set the search path for config files (default: /etc/config)
        -d <str>   set the delimiter for list values in uci show
         -f <file>  use <file> as input instead of stdin
        -L         do not load any plugins
        -m         when importing, merge data into an existing package
        -n         name unnamed sections on export (default)
        -N         don't name unnamed sections
        -p <path>  add a search path for config change files
        -P <path>  add a search path for config change files and use as default
        -q         quiet mode (don't print error messages)
        -s         force strict mode (stop on parser errors, default)
        -S         disable strict mode
        -X         do not use extended syntax on 'show'

透過 <config>.<section>.<option> 存取 <value>,而透過 <config>.<section> 取到的是 <section-type>。<section> 可用特定 <section-type> 的 index 表示法取代,index 從 0 開始,第一個是 @<section-type>[0]。也可以從後面數,此時 index 是負的,從 -1 開始,最後一個是 @<section-type>[-1]。
# uci get foo.first
bar
# uci get foo.first.name
Mr. First
# uci get foo.@bar[0].name
Mr. First
# uci get foo.@bar[1].name
Mr. Second
# uci get foo.@bar[-1].name
Mr. Third
# uci get foo.third.kid
aaa bbb
要注意的是 uci show [<config>] 時,會顯示所有的 <section-type> 及 <value>,<section-type> 的 index 不計有 <section> 的,所以可能會有所不同。
# uci show foo
foo.first=bar
foo.first.name=Mr. First
foo.@bar[0]=bar
foo.@bar[0].name=Mr. Second
foo.third=bar
foo.third.name=Mr. Third
foo.third.kid=aaa bbb


新增
uci add <config> <section-type>
uci set <config>.<section>=<section-type>

touch /etc/config/pbx
uci set pbx.201=user
uci set pbx.201.CFUC=202
uci commit pbx

參考:
  1. http://wiki.openwrt.org/doc/uci
  2. http://wiki.openwrt.org/doc/techref/uci
  3. Using UCI as stand alone (使用範例)
  4.  https://openwrt.org/docs/guide-user/base-system/uci
待續:
  • 設定/新增
    • uci  set <config>.<section>[.<option>]=<value>
    • uci add <config> <section-type>
    • uci add_list <config>.<section>.<option>=<string>
    • uci commit [<config>]
    • uci revert     <config>[.<section>[.<option>]]
  • 其它
    • uci batch
    • uci export [<config>]
    • import     [<config>]
    • changes    [<config>]
    • delete     <config>[.<section[.<option>]]
    • rename     <config>.<section>[.<option>]=<name>
    • reorder    <config>.<section>=<position>

2013年8月16日 星期五

Linux MODULE_LICENSE

MODULE_LICENSE("許可證") 會在產生 .ko 檔裡面的 .modinfo section 放 "lincense=許可證" 的資訊,可用 objdump 去看。

其中,只有許可證是 "GPL", "GPL v2", "GPL and additional rights", "Dual BSD/GPL", "Dual MIT/GPL", "Dual MPL/GPL" 之一,才認為是 GPL 相容。

如果不是 GPL 相容,有下列影響:
  • 關掉 debug_locks (作用不是很清楚),並顯示「Disabling lock debugging due to kernel taint」
  • 不能用 EXPORT_SYMBOL_GPL 的函數,這個應該是最大的限制
  • 污點 (存在 tainted_mask) 紀錄有使用非 GPL 相容的模組。其它污點有模組強迫載入等,只是除錯用的紀錄。

SIP header Via

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