[Dissecting OpenWRT]#2: netifd – main()

netifd is an RPC-capable daemon written in C for better access to kernel APIs with the ability to listen on netlink events.

In this series serveral articles will be written introduce the internal of netifd which is a core componet of OpenWRT/LEDE system for network management and its support for 802.11. As a normal Linux program, standing at main() function as a start point is a good choice.

The main() function of netidf is rather short and simple. It hides all the details in functions

int main(int argc, char **argv)
    const char *socket = NULL;
    int ch;

    global_argv = argv;

    while ((ch = getopt(argc, argv, "d:s:p:c:h:r:l:S")) != -1) {
        switch(ch) {
        case 'd':
            debug_mask = strtoul(optarg, NULL, 0);
        case 's':
            socket = optarg;
        case 'p':
            main_path = optarg;
        case 'c':
            config_path = optarg;
        case 'h':
            hotplug_cmd_path = optarg;
        case 'r':
            resolv_conf = optarg;
        case 'l':
            log_level = atoi(optarg);
            if (log_level >= ARRAY_SIZE(log_class))
                log_level = ARRAY_SIZE(log_class) - 1;
#ifndef DUMMY_MODE
        case 'S':
            use_syslog = false;
            return usage(argv[0]);

    if (use_syslog)
        openlog("netifd", 0, LOG_DAEMON);

    if (netifd_ubus_init(socket) < 0) {
        fprintf(stderr, "Failed to connect to ubus\n");
        return 1;


    if (system_init()) {
        fprintf(stderr, "Failed to initialize system control\n");
        return 1;




    if (use_syslog)

    return 0;

A brief flow chart is shown below

netifd main function


Posted in 未分类 | Leave a comment

Semtech LoRa packages for OpenWRT/LEDE

This article is still under construction

Recently I made a repo for latest Semtech Lora packages.


A donation of SX1301 gateway board is appreciate. With this I could do further development of UCI and Luci for Lora.

2. https://github.com/JiapengLi/OpenWrt-lora.git

Posted in LEDE, LoRa, OpenWRT | Leave a comment

[Dissecting OpenWRT]#1: Preface

From today I would like to start a new series (挖坑) called “Dissecting OpenWRT” (深入浅出 OpenWRT). Unlike other tutorials about OpenWRT, this new series will try to dissect OpenWRT from a developer’s point of view. It will focus on the implementation of OpenWRT core components, such as ubus, procd, netifd and luci. I hope that with the help of this new series, people will not only understand the insider but also know how to extend OpenWRT.

1. https://clockworkbird9.wordpress.com/2016/09/29/openwrtlede-system-boot-sequence/

1. https://clockworkbird9.wordpress.com/2017/02/05/openwrtlede-wifi-statup-process/

Posted in OpenWRT | Leave a comment

WPAN support for netifd

netifd is an RPC-capable daemon written in C for better access to kernel APIs with the ability to listen on netlink events. Netifd has replaced the old OpenWrt-network configuration scripts, the actual scripts that configured the network e.g.,


The WPAN support is now a simple clone of 802.11 support which include C code for netifd and Ash scripts to handle wpan interface.

The hardware platform I use is ci40 from Imagination, which has ca2810 802.15.4 radio chip. For most router without 802.15.4 hardware chips, fakelb is a good choice for testing. here is a simple tutorial how to setup a 6lowpan test network.

The OpenWRT source code is here

Posted in 6lowpan for linux, 802.15.4, Ci40, netifd, OpenWRT | Leave a comment

OpenWRT/LEDE WiFi Statup Process

This article will briefly introduse the WiFi startup process of OpenWRT/LEDE system.
The analysis will start from boot script which is located in /etc/initi.d/


Posted in 6lowpan for linux, 802.15.4, LEDE, Linux, OpenWRT | Leave a comment

iwpaninfo: Bring 802.15.4 into OpenWRT/LEDE

During last few days I have worked on a new project called iwpaninfo. It is a “clone” project from iwinfo and designed for 802.15.4 protocol. It is a wrap program like wpan-tools but it only read 802.15.4 device information via nl802154 interface. It also provides Lua bindings.

WIth the help of this project the intergration of 802.15.4 into OpenWRT/LEDE project will become easier.


Posted in 6lowpan for linux, 802.15.4, LEDE, OpenWRT | Leave a comment

[802.15.4 Linux] Add BEE click board support for Ci40

This post will briefly introduces how to add support of BEE click board for IMG ci40 board.

BEE Click is an accessory board in mikroBUS form factor. It features 2.4 GHz IEEE 802.15.4 radio transceiver module MRF24J40MA. This module includes an integrated PCB antenna and matching circuitry and is connected to the microcontroller via a SPI interface. As such, this module is an ideal solution for wireless networks, smart home automation, building automation and other electronic applications that need wireless communication. Board is designed to use 3.3V power supply only.

ci40 Linux kernel (4.4.14) has already driver support for MRF24J40. What we should do is adding device tree config for it, like

    mrf24j40ma@0 {
        compatible = "microchip,mrf24j40ma", "microchip,mrf24j40";
        spi-max-frequency = <4000000>;
        reg = <2>;
        interrupt-parent = <&gpio1>;
        interrupts = <5 GPIO_ACTIVE_HIGH>;

Or you can find the patch here.

It is noted that current driver has no support for reset and wake pin. And a pending patch is not merged. Since ci40 board has already 802.15.4 support via ca8210. mrf24j40 driver will be not automatically activated but explicitly loaded mrf24j40 driver via modprobe or insmod.


Posted in 6lowpan for linux, 802.15.4, Ci40 | Leave a comment