[][atenl: add package]

[Description]
Add atenl package, a userspace daemon for mt76 testmode.
atenl acts as an intermediate for HQADLL command and mt76 testmode
(implemented with NL80211_CMD_TESTMODE), which provides transparency for
the usage of QA-tool and Litepoint on mt76.

[Release-log]
N/A

Change-Id: If11e67b36dd7c3ef9629e824bc26ed4f16f34dca
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/5553443
diff --git a/feed/atenl/src/util.c b/feed/atenl/src/util.c
new file mode 100644
index 0000000..1b10663
--- /dev/null
+++ b/feed/atenl/src/util.c
@@ -0,0 +1,105 @@
+/* Copyright (C) 2021-2022 Mediatek Inc. */
+
+#include "atenl.h"
+
+int atenl_reg_read(struct atenl *an, u32 offset, u32 *res)
+{
+	char dir[64], buf[16];
+	unsigned long val;
+	int fd, ret;
+
+	/* write offset into regidx */
+	ret = snprintf(dir, sizeof(dir),
+		       "/sys/kernel/debug/ieee80211/phy%d/mt76/regidx",
+		       get_band_val(an, 0, phy_idx));
+	if (snprintf_error(sizeof(dir), ret))
+		return ret;
+
+	fd = open(dir, O_WRONLY);
+	if (fd < 0)
+		return fd;
+
+	ret = snprintf(buf, sizeof(buf), "0x%x", offset);
+	if (snprintf_error(sizeof(buf), ret))
+		goto out;
+
+	lseek(fd, 0, SEEK_SET);
+	write(fd, buf, sizeof(buf));
+	close(fd);
+
+	/* read value from regval */
+	ret = snprintf(dir, sizeof(dir),
+		       "/sys/kernel/debug/ieee80211/phy%d/mt76/regval",
+		       get_band_val(an, 0, phy_idx));
+	if (snprintf_error(sizeof(dir), ret))
+		return ret;
+
+	fd = open(dir, O_RDONLY);
+	if (fd < 0)
+		return fd;
+
+	ret = read(fd, buf, sizeof(buf) - 1);
+	if (ret < 0)
+		goto out;
+	buf[ret] = 0;
+
+	val = strtoul(buf, NULL, 16);
+	if (val > (u32) -1)
+		return -EINVAL;
+
+	*res = val;
+	ret = 0;
+out:
+	close(fd);
+
+	return ret;
+}
+
+int atenl_reg_write(struct atenl *an, u32 offset, u32 val)
+{
+	char dir[64], buf[16];
+	int fd, ret;
+
+	/* write offset into regidx */
+	ret = snprintf(dir, sizeof(dir),
+		       "/sys/kernel/debug/ieee80211/phy%d/mt76/regidx",
+		       get_band_val(an, 0, phy_idx));
+	if (snprintf_error(sizeof(dir), ret))
+		return ret;
+
+	fd = open(dir, O_WRONLY);
+	if (fd < 0)
+		return fd;
+
+	ret = snprintf(buf, sizeof(buf), "0x%x", offset);
+	if (snprintf_error(sizeof(buf), ret))
+		goto out;
+
+	lseek(fd, 0, SEEK_SET);
+	write(fd, buf, sizeof(buf));
+	close(fd);
+
+	/* write value into regval */
+	ret = snprintf(dir, sizeof(dir),
+		       "/sys/kernel/debug/ieee80211/phy%d/mt76/regval",
+		       get_band_val(an, 0, phy_idx));
+	if (snprintf_error(sizeof(dir), ret))
+		return ret;
+
+	fd = open(dir, O_WRONLY);
+	if (fd < 0)
+		return fd;
+
+	ret = snprintf(buf, sizeof(buf), "0x%x", val);
+	if (snprintf_error(sizeof(buf), ret))
+		goto out;
+	buf[ret] = 0;
+
+	lseek(fd, 0, SEEK_SET);
+	write(fd, buf, sizeof(buf));
+	ret = 0;
+out:
+	close(fd);
+
+	return ret;
+}