---
# System prepended metadata

title: Build 5G-EmPOWER Agent
tags: [EmPOWER]

---

---
tags: EmPOWER
---
# Build 5G-EmPOWER Agent

## OS Requirements

Basically, it can be built in Ubuntu version after 16.04. Following we use Ubuntu 20.04.

## Setting up WTP

Here WTP means wireless access point (AP). 

```shell=
## First clone two repo on empower github.
## At home directory
git clone https://github.com/5g-empower/empower-openwrt.git
git clone https://github.com/5g-empower/empower-configs.git

cd empower-openwrt

./scripts/feeds update -a
## If there are error messages like "CAfile: none CRLfile: none",
## then try "sudo apt install ca-certificates"

./scripts/feeds install -a

## Link the empower configuration file to the AP model you need, modify it if necessary.
ln -s ../empower-configs/empower-files-wdr4300/ files

## Copy the openwrt configuration file to empower-openwrt
cp ../empower-configs/wdr4300.config ./

## There are two files need to be modified.
## 1.
## Modify the "option master_ip" in /empower-files-wdr4300/etc/config/empower
## to the controller's IP address
## 2. (Optional)
## The channel in /empower-files-wdr4300/etc/config/wireless can be modified
```
- Edit the config file
  Following we use wdr4300.config as example.
  19.07 is the recommended OpenWrt version https://downloads.openwrt.org/releases/19.07.9/targets/ar71xx/generic/tl-wdr4300-v1-squashfs-factory.bin
  In the above website we can observe that
  - Target should be ar71xx
  - Subtarget should be generic
  - Target profile should be tl-wdr4300-v1

  Thus we need to modify the `wdr4300.config` file. However, using `make menuconfig` then load `wdr4300.config` and modify the config will greatly change its default config. So we directly modify the file by vim.
  ```shell=
  vim wdr4300.config
  ```
  The following options should be on:
  - CONFIG_TARGET_ar71xx=y
  - CONFIG_TARGET_ar71xx_generic=y
  - CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wdr4300-v1=y

  Then we can using `make menuconfig` and load `wdr4300.config` to check whether the config is correctly modified.
  **Make sure that `empower-lvap-agent` in `Network` is on.**

- Save the config file
  If all config are correct, we can save it to `.config` as default config.
  `make menuconfig` again to check if it is correctly saved as default config.

- Cross compile
  If everything is OK, we can begin cross compile. It may take several minutes.
  If run in VM, remember to change the number of processors in VM setting.
  ```shell=
  make -j 4
  ```
  
## System Upgrade

After `make -j 4`, copy `./bin/targets/ar71xx/generic/openwrt-ar71xx-generic-tl-wdr4300-v1-squashfs-factory.bin` to the `/tmp` folder of the AP.
Next, upgrade the firmware, `sysupgrade -v -n ./openwrt-ar71xx-generic-tl-wdr4300-v1-squashfs-factory.bin`

- Connect to the AP
  - If the AP's firmware is not empower's, then we should connect by the AP's LAN port. We can update the firmware through the webpage at `192.168.1.1`
  - Otherwise, we should connect by the AP's WAN port. Then find the AP's IP address by checking the webpage of `192.168.1.1`
  - Following we use `192.168.1.112` as the AP's IP address

- Copy the firmware to AP
  On the home directory
  ```shell=
  scp empower-openwrt/bin/targets/ar71xx/generic/openwrt-ar71xx-generic-tl-wdr4300-v1-squashfs-factory.bin root@192.168.1.112:/tmp
  ```
  
- Upgrade the system
  On the AP directory `/tmp`
  ```shell=
  sysupgrade -v -n ./openwrt-ar71xx-generic-tl-wdr4300-v1-squashfs-factory.bin
  ```


## Network Topology

```
Gateway AP
    - (LAN1) ---- (Eth) Ubuntu PC
                        - (bridge) -- EmPOWER controller
    - (LAN2) ---- (WAN) EmPOWER agent 112
    - (LAN3) ---- (WAN) EmPOWER agent 142
```

## (Optional) Print Log File to `/tmp`

Modify `/etc/init.d/empower` line $130$, change `/dev/null` to `/tmp/mylog`, and click will print out logfile to `/tmp/mulog`

## Reference

* https://github.com/5g-empower/5g-empower.github.io/wiki/Setting-up-the-WTP
* https://openwrt.org/docs/guide-developer/toolchain/install-buildsystem
* https://github.com/Wi5/odin-wi5/wiki/Create-OpenWRT-bin-image-including-openvswitch-and-the-ath9k-patch?fbclid=IwAR1HiQ39yu62v-vn1oLUEQMbviUOL9iP7RxPXUzf_jeXWG9WYBBeM6ttGNU