2025年5月25日 星期日

Linux user space delay

 #include <unistd.h>

usleep(100000); // 延遲 100,000 微秒 = 100 毫秒


---

#include <time.h>


struct timespec ts;

ts.tv_sec = 0;

ts.tv_nsec = 100 * 1000000L;  // 100 毫秒

nanosleep(&ts, NULL);

2025年5月11日 星期日

[網路] 如何判斷Bandwidth

 2.4G

HT Capabilities Bit 1(Supported Channel Width Set)

0: 20, 1: 20/40


如果Supported Channel Width Set,有可能是20或40

所以要再看Secondary Channel Offset


STA Channel Width   Secondary Channel Offset說明
0    0     使用 20 MHz
1    1(Above)     使用 40 MHz,副頻道在上面
1    3(Below)     使用 40 MHz,副頻道在下面

2024年12月14日 星期六

[Linux] hostapd create nelink socket和kernel driver溝通

1. static struct nl_sock * nl_create_handle(struct nl_cb *cb, const char *dbg)

2. struct nl_sock *nl_socket_alloc_cb(struct nl_cb *cb)
  a. calloc struct cb memory area
  b. 建立pid s_local.nl_pid = generate_local_port(); //取process id作為pid

3. 在此建立socket和bind
int genl_connect(struct nl_sock *sk)
  a. sk->s_fd = socket(AF_NETLINK, SOCK_RAW | flags, protocol);
  b. bind(sk->s_fd, (struct sockaddr*) &sk->s_local, sizeof(sk->s_local));

2024年10月22日 星期二

[網路] BSSID

BSSID: WiFi AP的MAC Address.

SSID: WiFi AP beacon發出來的名字,就是在wifi收尋選單看到的名字.

2024年8月19日 星期一

[網路] 如何判斷WPA3 SAE和WPA2 PSK/WPA3 SAE mix mode

主要是看beacon的RSN information tag


根據chatgpt解說

Identifying WPA2 vs. WPA3

  • WPA2: The AKM suite typically includes entries such as 00-0F-AC-1 (PSK) or 00-0F-AC-2 (802.1X).
  • WPA3: The AKM suite for WPA3 will include:
    • SAE (Simultaneous Authentication of Equals): 00-0F-AC-8, indicating WPA3-Personal.
    • Suite B: 00-0F-AC-9, indicating WPA3-Enterprise, often used with 192-bit cryptographic strength


2024年6月29日 星期六

[Linux] fclose close /proc下檔案導致當機

/proc is a virtual file system
 
//From chatgpt  
在 Linux 中,/proc 文件系統是一個虛擬文件系統,提供了訪問內核數據結構的接口,/proc 下的文件並不是真正的磁盤文件,而是由內核動態生成的,這些文件的行為可能與普通文件有所不同,尤其是在處理方式上.

在/proc除了是虛擬文件系統,裡面的檔案可能有其他process matain,也就是說有其他process 在操作此檔案,那fclose就可以free到錯誤的memory address

有時候在/proc的檔案大小還會是0






如果要讀取fopen /proc下檔案,把它導到 /tmp下再操作,即可避免當機問題.