|Design| Benefits of using Macro

What is the Macro?
If you write as “#define” in your code, that is “Macro” .

Macro will handle by the preprocessor.
You can think Macro as a method to replace the String which appears in you code..

pros:
– run faster than writing as function

cons:
– occupy memories

concepts:
– there is no the concept of pointer in macro.
just “replacing the string”

An question:
What is the output of the following code?

#define macro_to_func(pp) ({printf("in Macro ...\n"); minus ;})

void do_something(int *a, int *b){
    printf("do_something\n");
    int c;
    c = *a + *b;
    printf("do_something %d \n", c);
}

int minus(int *a, int *b){
    printf("minus\n");
    int c;
    c = *a - *b +1;
    printf("minus a = %d \n", *a);
    printf("minus b = %d \n", *b);
    printf("minus %d \n", c);
    return c;
}

int main()
{
    int (*do_something)(int* c, int* d);
    //printf("fptr 1 do_something %p\n", &do_something);

    int m = -1;
    int n = 7;

    printf("do_something = macro_to_func\n");
    do_something = macro_to_func(pp);
    //printf("fptr minus %p\n", &minus);
    //printf("fptr 2 do_something %p\n", &do_something);
    if(do_something){
        printf("in IF!!\n");
        do_something(&m, &n); --------------------------->???
    }
    return 0;
}

Answer:

do_something = macro_to_func
in Macro …
in IF!!
minus
minus a = -1
minus b = 7
minus -7

Explanation:
“int (*do_something)” is a local function pointer.
In the macro, the macro_to_func will be replaced as “minus”, but do_something !!!

|Code| LLVM initial

One day, if you want to implement a module on the platform x86_64 for arm64, you will need to know the tool chain, “cross compiler”.
The famous modern compiler is LLVM.

Why should we understand the compiler?
– build for multi-platform
– improve the efficiency of your code
– …..

I have a conclusion for the developer whose library is under the user space.
Use suitable optimization provided by LLVM, and make your code readable.
Dazzle coding is meaningless.

你所不知道的 C 語言:編譯器和最佳化原理篇
[共筆] 不深不淺,帶你認識 LLVM
“編譯器 LLVM 淺淺玩” by Pokai Chang

|Jobs| Who is worthy of being called “Engineer” ?

The core competencies of engineer are
– never complain
– segmenting problems
hands-on problem solving
– not defeatist

You can win if you want.

If I am an interviewer, I just want to know ……
Will he/she want to solve problems?
Is he/she a defeatism?
Will he/she look down on other fields?
I don’t like whom disregard others.
It means he/she ignore details in him/her life.

|LTE| 開啟行動上網 ……

這篇會走一趟整個使用行動上網的流程,以及封包如何出去。
若想知道更多,可利用 > 後的關鍵字去做搜尋。

我們一開機,不是在飛航模式 ……
– UE 會向 NW 做 “initial attach”
包含:
> RRC connection (手機告訴網路說:我想要連線啦~基地台快醒來服務我)
> Attach request (我要送東西ㄛ~大概是一個包裹的大小,
         請幫忙聯絡車車來送貨)
> EMM 通知後端網路及認證 (電信商的櫃台忙著聯絡服務中心)
> RRC reconfiguration (開始配送貨車來服務客人送貨)

詳細流程可參考:
一分鐘快速了解手機如何傳送檔案


– Initial attach 之後,表示 UE 已經向網路拿到派發的 IP
– 這時候手機裡的 data service 會向 modem 取得 IP address
– 設定 Linux 裡的 “rmnet_data”、”DNS” ……
到此時,手機端的設定準備好了,建立連線完成。
但還沒有要送封包出去哦 ……

開始要送封包 ……
封包從 APP 開始,會經過:
– TCP
– IP
– MAC
– rmnet driver 走出去到網路端啦~
The packet flow, from userspace to kernel driver in Linux network stack

接下來就上到電信商給的車車載走囉!

LTE initial attach

|Jobs| How can operators detect tethering?

出國玩,買 SIM卡 一定要注意,這張卡是否能夠當作 WiFi hotspot 分享給別人,

有的卡是不行的哦!!

在某次出差 (2017),我發現,電信業者是有能力知道這張 SIM卡是否有能力 WiFi hotspot,並且禁止這張卡做分享。

我一直以為是 framework 的行為(軟體端去擋),但是我做了一些實驗,發現電信商是可以控制的。(最近的新案子也有談到類似的東西)

表示在卡號之外,你這張卡是否有分享給別人,或者,
別支手機是否透過分享上網的,這兩個一定有其中一個資訊會被電信商知道。

稍微上網查了一下,電信商可以偵測到以下資訊,推斷出
你是否正在分享給別人/你是否是透過不能分享的網路上網

How can phone companies detect tethering (incl. Wifi hotspot)

  1. Your phone tells your network that you are tethering
  2. Inspecting the network packets for their TTL (time to live)
  3. MAC address inspection
  4. TCP/IP Stack Fingerprinting
  5. Looking at the Destination IP/URL

(補充)

電信商可以利用Tether Guard的機制來得知。基本上,你要用APN:dun建立連線才能 tethering給別人,

如果成功,表示電信商允許你分享!

特別是去英國或美國,要查一下你的卡哦!

Tethering on UK Networks: Which Mobile Networks Allow You To Tether?