Skip to content

Commit

Permalink
generic: platform/mikrotik: add wlan lz77 decompress
Browse files Browse the repository at this point in the history
A number of new (or with recently updated caldata)
Mikrotik devices are using LZ77 magic for wlan tag hard_config data.
New devices include the Chateau LTE12 [1], and ax devices [2]
Newly factory flashed devices may include the hap ac3 [3]

This can be seen in decoded OEM supout [4] dmesg:
"radio data lz77 decompressed from"…

Investigating an arm RouterOS flash.ko module, and supplied example
hard_config dumps, the format was guessed via decompilation and live
debugging [5].

debug prints can be enabled in a DYNAMIC_DEBUG kernel build via the
kernel cmdline:

        chosen {
-               bootargs = "console=ttyS0,115200";
+               bootargs = "console=ttyS0,115200 dyndbg=\"file drivers/platform/mikrotik/* +p\"";
        };

[1]: https://forum.openwrt.org/t/no-wireless-mikrotik-rbd53ig-5hacd2hnd/157763/4
[2]: https://forum.openwrt.org/t/mikrotik-routeros-v7-x-and-openwrt-sysupgrade/148072/17
[3]: https://forum.openwrt.org/t/adding-support-for-mikrotik-hap-ax2/133715/47
[4]: https://github.com/farseeker/go-mikrotik-rif
[5]: https://github.com/john-tho/routeros-wlan-lz77-decode

Signed-off-by: John Thomson <[email protected]>
  • Loading branch information
john-tho committed Jun 25, 2024
1 parent 6e5b571 commit 9eb2a75
Show file tree
Hide file tree
Showing 9 changed files with 548 additions and 2 deletions.
1 change: 1 addition & 0 deletions target/linux/ath79/mikrotik/config-default
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CONFIG_MFD_RB4XX_CPLD=y
CONFIG_MIKROTIK=y
CONFIG_MIKROTIK_RB_SYSFS=y
CONFIG_MIKROTIK_WLAN_DECOMPRESS=y
CONFIG_MIKROTIK_WLAN_DECOMPRESS_LZ77=y
CONFIG_MTD_NAND_AR934X=y
CONFIG_MTD_NAND_CORE=y
CONFIG_MTD_NAND_ECC=y
Expand Down
7 changes: 7 additions & 0 deletions target/linux/generic/files/drivers/platform/mikrotik/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ config MIKROTIK_WLAN_DECOMPRESS
Allow Mikrotik factory flashed Wi-Fi claibration data to
be decompressed from Mikrotik specific formats

config MIKROTIK_WLAN_DECOMPRESS_LZ77
tristate "Mikrotik factory Wi-Fi caldata LZ77 decompression support"
depends on MIKROTIK_WLAN_DECOMPRESS
help
Allow Mikrotik LZ77 factory flashed Wi-Fi calibration data to be
decompressed

endif # MIKROTIK
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
obj-$(CONFIG_MIKROTIK_RB_SYSFS) += routerboot.o rb_hardconfig.o rb_softconfig.o
obj-$(CONFIG_NVMEM_LAYOUT_MIKROTIK) += rb_nvmem.o
obj-$(CONFIG_MIKROTIK_WLAN_DECOMPRESS) += mikrotik_wlan.o
obj-$(CONFIG_MIKROTIK_WLAN_DECOMPRESS_LZ77) += mikrotik_wlan_lz77.o
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int mikrotik_wlan_lzor_prefixed_decompress(const u8 *inbuf, size_t inlen,
int mikrotik_wlan_rle_decompress(const u8 *in, size_t inlen,
u8 *out, size_t *outlen);

#else
#else /* CONFIG_MIKROTIK_WLAN_DECODE */

static inline int mikrotik_wlan_lzor_prefixed_decompress(const u8 *inbuf,
size_t inlen,
Expand All @@ -59,5 +59,35 @@ static inline int mikrotik_wlan_rle_decompress(const u8 *in, size_t inlen,
{
return -EOPNOTSUPP;
}

#endif /* CONFIG_MIKROTIK_WLAN_DECOMPRESS */

#ifdef CONFIG_MIKROTIK_WLAN_DECOMPRESS_LZ77
/**
* mikrotik_wlan_lz77_decompress
*
* @in: compressed data ptr
* @in_len: length of compressed data
* @out: buffer ptr to decompress into
* @out_len: length of decompressed buffer in input,
* length of decompressed data in success
*
* Returns 0 on success, or negative error
*/
int mikrotik_wlan_lz77_decompress(const unsigned char *in,
const size_t in_len,
unsigned char *out,
size_t *out_len);

#else /* CONFIG_MIKROTIK_WLAN_DECOMPRESS_LZ77 */

static inline int mikrotik_wlan_lz77_decompress(const unsigned char *in,
const size_t in_len,
unsigned char *out,
size_t *out_len)
{
return -EOPNOTSUPP;
}

#endif /* CONFIG_MIKROTIK_WLAN_DECOMPRESS_LZ77 */
#endif /* __MIKROTIK_WLAN_H__ */
Loading

0 comments on commit 9eb2a75

Please sign in to comment.