Skip to content

Commit

Permalink
Fixing SD card simuation issue on v3 4.36.0.252 firwmare.
Browse files Browse the repository at this point in the history
  • Loading branch information
HclX committed Feb 21, 2021
1 parent 2364df8 commit 986a47f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 31 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ functions:
6. Automatically archive the recordings.

# Release notes
## 0.5.03:
* Fixing broken SD card simuation on latest v3 firmware (4.36.0.252)

## 0.5.02:
* Fixing an install issue with RTSP firmware.
* Fixing an issue with NFS connectivity detection.
Expand Down
Binary file added release/wyze_hacks_0_5_03.zip
Binary file not shown.
45 changes: 24 additions & 21 deletions src/utils/libhacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@
#define HACKDATA_MAGIC 0xDEADBEEF
#define MAX_PATH 255

#define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])

const char* const mmc_gpio_paths[] = {
// 4.36.0.228 and older use GPIO50 to detect MMC insertion.
"/sys/class/gpio/gpio50/value",
// 4.36.0.252 and later uses GPIO62 to detect MMC insertion.
"/sys/class/gpio/gpio62/value"
};

typedef struct {
uint32_t magic;
uint32_t nfs_mounted;
char mmc_gpio_path_orig[MAX_PATH];
char mmc_gpio_path_redir[MAX_PATH];
char mmc_gpio_redir[MAX_PATH];
} hackdata_t;

hackdata_t* g_hackdata;
Expand Down Expand Up @@ -162,33 +170,28 @@ int open(char * file, int oflag) {
typedef int (*PFN_open)(const char*, int);
DLSYM(open);

if (strcmp(file, g_hackdata->mmc_gpio_path_orig) == 0) {
// TODO: Replace hardcoded wyzehack path
return s_pfn(g_hackdata->mmc_gpio_path_redir, oflag);
} else {
return s_pfn(file, oflag);
if (g_hackdata->mmc_gpio_redir[0]) {
for (int i = 0; i < ARRAY_SIZE(mmc_gpio_paths); i ++) {
if (strcmp(file, mmc_gpio_paths[i]) == 0) {
printf("Redirecting access to %s to %s\n",
file, g_hackdata->mmc_gpio_redir);
return s_pfn(g_hackdata->mmc_gpio_redir, oflag);
}
}
}
return s_pfn(file, oflag);
}

int hack_init() {
if (g_hackdata->magic != HACKDATA_MAGIC) {
return -1;
}

snprintf(
g_hackdata->mmc_gpio_path_orig,
sizeof(g_hackdata->mmc_gpio_path_orig),
"/sys/class/gpio/gpio%s/value", getenv("MMC_GPIO"));

snprintf(
g_hackdata->mmc_gpio_path_redir,
sizeof(g_hackdata->mmc_gpio_path_redir),
"%s/mmc_gpio_value.txt", getenv("WYZEHACK_DIR"));

printf(
"Access to %s will be redirected to %s\n",
g_hackdata->mmc_gpio_path_orig, g_hackdata->mmc_gpio_path_redir);

const char* p = getenv("MMC_GPIO_REDIR");
if (p) {
strncpy(g_hackdata->mmc_gpio_redir, p,
sizeof(g_hackdata->mmc_gpio_redir));
}
return 0;
}

Expand Down
Binary file modified src/utils/libhacks.so
Binary file not shown.
2 changes: 1 addition & 1 deletion wyze_hack/hack_ver.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export WYZEHACK_VER=0.5.02
export WYZEHACK_VER=0.5.03
16 changes: 7 additions & 9 deletions wyze_hack/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,49 @@ case $WYZEAPP_VER in
export DEVICE_ID=$(grep -oE "NETRELATED_MAC=[A-F0-9]{12}" /params/config/.product_config | sed 's/NETRELATED_MAC=//g')
export DEVICE_MODEL="V1"
export SPEAKER_GPIO=63
export MMC_GPIO=50
;;

4.9.*)
# Cam V2
export DEVICE_ID=$(grep -oE "NETRELATED_MAC=[A-F0-9]{12}" /params/config/.product_config | sed 's/NETRELATED_MAC=//g')
export DEVICE_MODEL="V2"
export SPEAKER_GPIO=63
export MMC_GPIO=50
;;

4.28.*)
# Cam V2 RTSP
export DEVICE_ID=$(grep -oE "NETRELATED_MAC=[A-F0-9]{12}" /params/config/.product_config | sed 's/NETRELATED_MAC=//g')
export DEVICE_MODEL="V2"
export SPEAKER_GPIO=63
export MMC_GPIO=50
;;

4.10.*)
# Cam PAN
export DEVICE_ID=$(grep -oE "NETRELATED_MAC=[A-F0-9]{12}" /params/config/.product_config | sed 's/NETRELATED_MAC=//g')
export DEVICE_MODEL="PAN"
export SPEAKER_GPIO=63
export MMC_GPIO=50
;;

4.29.*)
# Cam PAN RTSP
export DEVICE_ID=$(grep -oE "NETRELATED_MAC=[A-F0-9]{12}" /params/config/.product_config | sed 's/NETRELATED_MAC=//g')
export DEVICE_MODEL="PAN"
export SPEAKER_GPIO=63
export MMC_GPIO=50
;;

4.25.*)
# Doorbell
export DEVICE_ID=$(grep -E -o CONFIG_INFO=[0-9A-F]+ /params/config/.product_config | cut -c 13-24)
export DEVICE_MODEL="DB"
export SPEAKER_GPIO=63
export MMC_GPIO=50
;;

4.36.*)
# Cam V3
export DEVICE_ID=$(grep -E -o CONFIG_INFO=[0-9A-F]+ /configs/.product_config | cut -c 13-24)
export DEVICE_MODEL="V3"
export SPEAKER_GPIO=63
export MMC_GPIO=50
export MMC_GPIO_REDIR="$WYZEHACK_DIR/mmc_gpio_value.txt"
;;

*)
Expand Down Expand Up @@ -382,7 +376,9 @@ mount_nfs() {
done

echo "WyzeHack: Notifying iCamera about SD card insertion event..."
echo "0" > $WYZEHACK_DIR/mmc_gpio_value.txt
if [ ! -z $MMC_GPIO_REDIR ]; then
echo "0" > $MMC_GPIO_REDIR
fi
$WYZEHACK_DIR/bin/hackutils mmc_insert

# Mark this directory for this camera
Expand Down Expand Up @@ -525,7 +521,9 @@ cmd_run() {
# MMC detection hook init
export PATH=$WYZEHACK_DIR/bin:$PATH
export LD_LIBRARY_PATH=$WYZEHACK_DIR/bin:$LD_LIBRARY_PATH
echo "1" > $WYZEHACK_DIR/mmc_gpio_value.txt
if [ ! -z $MMC_GPIO_REDIR ];then
echo "1" > $MMC_GPIO_REDIR
fi
$WYZEHACK_DIR/bin/hackutils init

export WYZEINIT_MD5=$(md5sum $WYZEINIT_SCRIPT| grep -oE "^[0-9a-f]*")
Expand Down

0 comments on commit 986a47f

Please sign in to comment.