mirror of
https://github.com/Ysurac/openmptcprouter.git
synced 2025-02-14 12:21:53 +00:00
Replace mnfinfo binary by a bash script
This commit is contained in:
parent
6e44fda94f
commit
9a296c1588
17 changed files with 10 additions and 335 deletions
|
@ -15,4 +15,3 @@ CONFIG_TARGET_SQUASHFS_BLOCK_SIZE=64
|
|||
CONFIG_KERNEL_SWAP=y
|
||||
CONFIG_PREINITOPT=y
|
||||
CONFIG_PACKAGE_kmod-r2ec=y
|
||||
CONFIG_PACKAGE_mnfinfo=y
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2020 Teltonika
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
include $(INCLUDE_DIR)/download.mk
|
||||
|
||||
PKG_NAME:=mnfinfo
|
||||
PKG_VERSION:=1
|
||||
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/mnfinfo
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
TITLE:=Device mnf-info command line interface
|
||||
DEPENDS:=+libpthread +libmnfinfo
|
||||
endef
|
||||
|
||||
define Package/libmnfinfo
|
||||
SECTION:=libs
|
||||
CATEGORY:=Libraries
|
||||
TITLE:=Device mnf-info API library
|
||||
endef
|
||||
|
||||
define Package/rpcd-mod-mnfinfo
|
||||
SECTION:=libs
|
||||
CATEGORY:=Libraries
|
||||
TITLE:=mnfinfo rpcd module
|
||||
DEPENDS:=+rpcd +libmnfinfo
|
||||
endef
|
||||
|
||||
define Build/InstallDev
|
||||
$(INSTALL_DIR) $(STAGING_DIR)/usr/lib $(STAGING_DIR)/usr/include/libmnfinfo
|
||||
$(CP) $(PKG_BUILD_DIR)/*.so $(STAGING_DIR)/usr/lib/
|
||||
$(CP) $(PKG_BUILD_DIR)/src/include/*.h $(STAGING_DIR)/usr/include/libmnfinfo/
|
||||
endef
|
||||
|
||||
define Package/mnfinfo/install
|
||||
$(INSTALL_DIR) $(1)/sbin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/mnf_info $(1)/sbin/mnf_info
|
||||
endef
|
||||
|
||||
define Package/libmnfinfo/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(PKG_BUILD_DIR)/libmnfinfo.so $(1)/usr/lib/
|
||||
endef
|
||||
|
||||
define Package/rpcd-mod-mnfinfo/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib/rpcd
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/mnfinfo.so $(1)/usr/lib/rpcd/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,mnfinfo))
|
||||
$(eval $(call BuildPackage,libmnfinfo))
|
||||
$(eval $(call BuildPackage,rpcd-mod-mnfinfo))
|
|
@ -1,35 +0,0 @@
|
|||
MNF_SOURCES = src/mnf_info.c
|
||||
MNF_OBJS = $(MNF_SOURCES:.c=.o)
|
||||
MNF_TARGET = mnf_info
|
||||
|
||||
MNF_RPC_SOURCES = src/mnf_rpc.c
|
||||
MNF_RPC_OBJS = $(MNF_RPC_SOURCES:.c=.o)
|
||||
MNF_RPC_TARGET = mnfinfo.so
|
||||
|
||||
LIB_SOURCES = src/libmnfinfo.c
|
||||
LIB_OBJS = $(LIB_SOURCES:.c=.o)
|
||||
LIB_TARGET = libmnfinfo.so
|
||||
|
||||
CFLAGS += -Wall -Wextra -Wpedantic -Werror -Wno-missing-braces -Wno-unused-function -Wno-unused-parameter -fPIC -I src/include
|
||||
LDFLAGS += -L.
|
||||
|
||||
MNF_LDFLAGS =
|
||||
MNF_RPC_LDFLAGS = -lmnfinfo
|
||||
|
||||
RM = rm -f
|
||||
|
||||
all: $(LIB_TARGET) $(MNF_RPC_TARGET) $(MNF_TARGET)
|
||||
|
||||
$(LIB_TARGET): $(LIB_OBJS)
|
||||
$(CC) $(LDFLAGS) -shared -o $@ $^
|
||||
|
||||
$(MNF_RPC_TARGET): $(MNF_RPC_OBJS) $(LIB_TARGET)
|
||||
$(CC) $(LDFLAGS) $(MNF_RPC_LDFLAGS) -shared -o $@ $^
|
||||
|
||||
$(MNF_TARGET): $(MNF_OBJS) $(LIB_OBJS)
|
||||
$(CC) $(LDFLAGS) $(MNF_LDFLAGS) -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) $(LIB_OBJS) $(LIB_TARGET)
|
||||
$(RM) $(MNF_RPC_OBJS) $(MNF_RPC_TARGET)
|
||||
$(RM) $(MNF_OBJS) $(MNF_TARGET)
|
|
@ -1,25 +0,0 @@
|
|||
# libmnfinfo
|
||||
|
||||
How it works: depending on the platform, selected in the menuconfig, a different platform flag is defined during compilation. Depending on that flag, a header file with platform-specific MTD field defines is included. Here are all the defines, (currently) used for these headers:
|
||||
|
||||
* `MAX_SIM_ID` - maximum allowed SIM index on the platform.
|
||||
* `MTD_CONFIG_RO` - absolute path of a read-only MTD partition. Used for most field reads.
|
||||
* `MTD_CONFIG_RW` - absolute path of a read/write MTD partition. Used for SIM PIN value reads/writes.
|
||||
* `MAC_OFFSET` - MAC field offset in the `MTD_CONFIG_RO` partition.
|
||||
* `MAC_LENGTH` - MAC field length in the `MTD_CONFIG_RO` partition.
|
||||
* `NAME_OFFSET` - product name field offset in the `MTD_CONFIG_RO` partition.
|
||||
* `NAME_LENGTH` - product name field length in the `MTD_CONFIG_RO` partition.
|
||||
* `WPS_OFFSET` - WPS field offset in the `MTD_CONFIG_RO` partition.
|
||||
* `WPS_LENGTH` - WPS field length in the `MTD_CONFIG_RO` partition.
|
||||
* `SERIAL_OFFSET` - product serial code field offset in the `MTD_CONFIG_RO` partition.
|
||||
* `SERIAL_LENGTH` - product serial code field length in the `MTD_CONFIG_RO` partition.
|
||||
* `BATCH_OFFSET` - batch index field offset in the `MTD_CONFIG_RO` partition.
|
||||
* `BATCH_LENGTH` - batch index field length in the `MTD_CONFIG_RO` partition.
|
||||
* `HWVER_OFFSET` - hardware version index field offset in the `MTD_CONFIG_RO` partition.
|
||||
* `HWVER_LENGTH` - hardware version index field length in the `MTD_CONFIG_RO` partition.
|
||||
* `SIMPIN_OFFSET` - SIM card PIN code field offset in the `MTD_CONFIG_RW` partition.
|
||||
* `SIMPIN_LENGTH` - SIM card PIN code field length in the `MTD_CONFIG_RW` partition.
|
||||
* `WIFI_OFFSET` - Wi-Fi password field offset in the `MTD_CONFIG_RO` partition.
|
||||
* `WIFI_LENGTH` - Wi-Fi password field length in the `MTD_CONFIG_RO` partition.
|
||||
|
||||
Only defines with actual values should be written. All other defines should be removed from the platform-specific header file.
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,115 +0,0 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define STRING_NA(a) do { (a)[0] = 'N'; (a)[1] = '/'; (a)[2] = 'A'; (a)[3] = 0; } while(0)
|
||||
#define STRING_NA_LENGTH 3
|
||||
|
||||
#define PARTITION_SIZE 0xA0
|
||||
#define SECTION_SIZE 0x10
|
||||
|
||||
#if defined(RUTX_PLATFORM)
|
||||
#include "rutx.h"
|
||||
#elif defined(TRB1_PLATFORM)
|
||||
#include "trb1.h"
|
||||
#elif defined(TRB2_PLATFORM)
|
||||
#include "trb2.h"
|
||||
#elif defined(RUT2_PLATFORM)
|
||||
#include "rut2.h"
|
||||
#elif defined(RUT300_PLATFORM) || defined(RUT360_PLATFORM)
|
||||
#include "rut3.h"
|
||||
#else
|
||||
#error Platform not recognized!
|
||||
#endif
|
||||
|
||||
#if !(defined(MAC_OFFSET) && defined(MAC_LENGTH))
|
||||
#undef MAC_OFFSET
|
||||
#undef MAC_LENGTH
|
||||
#define MAC_OFFSET 0
|
||||
#define MAC_LENGTH STRING_NA_LENGTH
|
||||
#else
|
||||
#define MAC_ENABLED
|
||||
#endif
|
||||
|
||||
#if !(defined(NAME_OFFSET) && defined(NAME_LENGTH))
|
||||
#undef NAME_OFFSET
|
||||
#undef NAME_LENGTH
|
||||
#define NAME_OFFSET 0
|
||||
#define NAME_LENGTH STRING_NA_LENGTH
|
||||
#else
|
||||
#define NAME_ENABLED
|
||||
#endif
|
||||
|
||||
#if !(defined(WPS_OFFSET) && defined(WPS_LENGTH))
|
||||
#undef WPS_OFFSET
|
||||
#undef WPS_LENGTH
|
||||
#define WPS_OFFSET 0
|
||||
#define WPS_LENGTH STRING_NA_LENGTH
|
||||
#else
|
||||
#define WPS_ENABLED
|
||||
#endif
|
||||
|
||||
#if !(defined(SERIAL_OFFSET) && defined(SERIAL_LENGTH))
|
||||
#undef SERIAL_OFFSET
|
||||
#undef SERIAL_LENGTH
|
||||
#define SERIAL_OFFSET 0
|
||||
#define SERIAL_LENGTH STRING_NA_LENGTH
|
||||
#else
|
||||
#define SERIAL_ENABLED
|
||||
#endif
|
||||
|
||||
#if !(defined(BATCH_OFFSET) && defined(BATCH_LENGTH))
|
||||
#undef BATCH_OFFSET
|
||||
#undef BATCH_LENGTH
|
||||
#define BATCH_OFFSET 0
|
||||
#define BATCH_LENGTH STRING_NA_LENGTH
|
||||
#else
|
||||
#define BATCH_ENABLED
|
||||
#endif
|
||||
|
||||
#if !(defined(HWVER_OFFSET) && defined(HWVER_LENGTH))
|
||||
#undef HWVER_OFFSET
|
||||
#undef HWVER_LENGTH
|
||||
#define HWVER_OFFSET 0
|
||||
#define HWVER_LENGTH STRING_NA_LENGTH
|
||||
#else
|
||||
#define HWVER_ENABLED
|
||||
#endif
|
||||
|
||||
#if !(defined(SIMPIN_OFFSET) && defined(SIMPIN_LENGTH))
|
||||
#undef SIMPIN_OFFSET
|
||||
#undef SIMPIN_LENGTH
|
||||
#define SIMPIN_OFFSET 0
|
||||
#define SIMPIN_LENGTH STRING_NA_LENGTH
|
||||
#else
|
||||
#define SIMPIN_ENABLED
|
||||
#endif
|
||||
|
||||
#if !(defined(WIFI_OFFSET) && defined(WIFI_LENGTH))
|
||||
#undef WIFI_OFFSET
|
||||
#undef WIFI_LENGTH
|
||||
#define WIFI_OFFSET 0
|
||||
#define WIFI_LENGTH STRING_NA_LENGTH
|
||||
#else
|
||||
#define WIFI_ENABLED
|
||||
#endif
|
||||
|
||||
/*
|
||||
* mnfinfo_get_*() functions return ptr to static memory, which is not to be free()d!
|
||||
* the returned memory ptr is safely accessible throughout the using program's runtime
|
||||
* bad: free(mnfinfo_get_mac());
|
||||
*
|
||||
* returns NULL on /dev/mtdX reading failure, "N/A" if the particular device
|
||||
* doesn't support the field, or a dummy string if the mtdblock space contains garbage
|
||||
*/
|
||||
char* mnfinfo_get_mac(void);
|
||||
char* mnfinfo_get_name(void);
|
||||
char* mnfinfo_get_maceth(void);
|
||||
char* mnfinfo_get_sn(void);
|
||||
char* mnfinfo_get_hwver(void);
|
||||
char* mnfinfo_get_batch(void);
|
||||
char* mnfinfo_get_wps(void);
|
||||
char* mnfinfo_get_wifi_pw(void);
|
||||
char* mnfinfo_get_sim_pin(uint8_t sim_id);
|
||||
|
||||
// returns true on success
|
||||
bool mnfinfo_set_sim_pin(uint8_t sim_id, const char *pin);
|
|
@ -1,21 +0,0 @@
|
|||
#define MAX_SIM_ID 1
|
||||
|
||||
#define MTD_CONFIG_RO "/dev/mtd1"
|
||||
#define MTD_CONFIG_RW "/dev/mtd1"
|
||||
|
||||
#define MAC_OFFSET 0x00
|
||||
#define MAC_LENGTH 6
|
||||
#define NAME_OFFSET 0x10
|
||||
#define NAME_LENGTH 12
|
||||
#define WPS_OFFSET 0x20
|
||||
#define WPS_LENGTH 8
|
||||
#define SERIAL_OFFSET 0x30
|
||||
#define SERIAL_LENGTH 10
|
||||
#define BATCH_OFFSET 0x40
|
||||
#define BATCH_LENGTH 4
|
||||
#define HWVER_OFFSET 0x50
|
||||
#define HWVER_LENGTH 4
|
||||
#define SIMPIN_OFFSET 0x70
|
||||
#define SIMPIN_LENGTH 4
|
||||
#define WIFI_OFFSET 0x90
|
||||
#define WIFI_LENGTH 16
|
|
@ -1,21 +0,0 @@
|
|||
#define MAX_SIM_ID 1
|
||||
|
||||
#define MTD_CONFIG_RO "/dev/mtd1"
|
||||
#define MTD_CONFIG_RW "/dev/mtd1"
|
||||
|
||||
#define MAC_OFFSET 0x00
|
||||
#define MAC_LENGTH 6
|
||||
#define NAME_OFFSET 0x10
|
||||
#define NAME_LENGTH 12
|
||||
#define WPS_OFFSET 0x20
|
||||
#define WPS_LENGTH 8
|
||||
#define SERIAL_OFFSET 0x30
|
||||
#define SERIAL_LENGTH 10
|
||||
#define BATCH_OFFSET 0x40
|
||||
#define BATCH_LENGTH 4
|
||||
#define HWVER_OFFSET 0x50
|
||||
#define HWVER_LENGTH 4
|
||||
#define SIMPIN_OFFSET 0x70
|
||||
#define SIMPIN_LENGTH 4
|
||||
#define WIFI_OFFSET 0x90
|
||||
#define WIFI_LENGTH 16
|
|
@ -1,21 +0,0 @@
|
|||
#define MAX_SIM_ID 4
|
||||
|
||||
#define MTD_CONFIG_RO "/dev/mtd13"
|
||||
#define MTD_CONFIG_RW "/dev/mtd14"
|
||||
|
||||
#define MAC_OFFSET 0x00
|
||||
#define MAC_LENGTH 6
|
||||
#define NAME_OFFSET 0x10
|
||||
#define NAME_LENGTH 12
|
||||
#define WPS_OFFSET 0x20
|
||||
#define WPS_LENGTH 8
|
||||
#define SERIAL_OFFSET 0x30
|
||||
#define SERIAL_LENGTH 10
|
||||
#define BATCH_OFFSET 0x40
|
||||
#define BATCH_LENGTH 4
|
||||
#define HWVER_OFFSET 0x50
|
||||
#define HWVER_LENGTH 4
|
||||
#define SIMPIN_OFFSET 0x00
|
||||
#define SIMPIN_LENGTH 4
|
||||
#define WIFI_OFFSET 0x90
|
||||
#define WIFI_LENGTH 16
|
|
@ -1,17 +0,0 @@
|
|||
#define MAX_SIM_ID 1
|
||||
|
||||
#define MTD_CONFIG_RO "/dev/mtd7"
|
||||
#define MTD_CONFIG_RW "/dev/mtd7"
|
||||
|
||||
#define MAC_OFFSET 0x50
|
||||
#define MAC_LENGTH 12
|
||||
#define NAME_OFFSET 0x20
|
||||
#define NAME_LENGTH 12
|
||||
#define SERIAL_OFFSET 0x10
|
||||
#define SERIAL_LENGTH 10
|
||||
#define BATCH_OFFSET 0x40
|
||||
#define BATCH_LENGTH 3
|
||||
#define HWVER_OFFSET 0x30
|
||||
#define HWVER_LENGTH 4
|
||||
#define SIMPIN_LENGTH 4
|
||||
#define SIMPIN_OFFSET 0x70
|
|
@ -1,21 +0,0 @@
|
|||
#define MAX_SIM_ID 2
|
||||
|
||||
#define MTD_CONFIG_RO "/dev/mtd1"
|
||||
#define MTD_CONFIG_RW "/dev/mtd1"
|
||||
|
||||
#define MAC_OFFSET 0x00
|
||||
#define MAC_LENGTH 6
|
||||
#define NAME_OFFSET 0x10
|
||||
#define NAME_LENGTH 12
|
||||
#define WPS_OFFSET 0x20
|
||||
#define WPS_LENGTH 8
|
||||
#define SERIAL_OFFSET 0x30
|
||||
#define SERIAL_LENGTH 10
|
||||
#define BATCH_OFFSET 0x40
|
||||
#define BATCH_LENGTH 4
|
||||
#define HWVER_OFFSET 0x50
|
||||
#define HWVER_LENGTH 4
|
||||
#define SIMPIN_OFFSET 0x70
|
||||
#define SIMPIN_LENGTH 4
|
||||
#define WIFI_OFFSET 0x90
|
||||
#define WIFI_LENGTH 16
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
10
root/target/linux/ipq40xx/base-files/sbin/mnf_info
Executable file
10
root/target/linux/ipq40xx/base-files/sbin/mnf_info
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-n|--name)
|
||||
echo $(dd if=/dev/mtd13 bs=1 count=12 skip=16 2>/dev/null)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
Loading…
Reference in a new issue