Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangboyang committed Oct 21, 2021
1 parent 9c7ac18 commit c53f702
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 30 deletions.
37 changes: 32 additions & 5 deletions audio_crc32.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@
import zlib
import traceback
import gc
if os.name == 'nt':
import msvcrt
import win32gui
import win32con
import win32console
files = sys.argv[1:]
if not files:
try:
ret = win32gui.GetOpenFileNameW(
hwndOwner=win32console.GetConsoleWindow(),
MaxFile=1048576,
Flags=
win32con.OFN_ALLOWMULTISELECT |
win32con.OFN_PATHMUSTEXIST |
win32con.OFN_FILEMUSTEXIST |
win32con.OFN_HIDEREADONLY |
win32con.OFN_EXPLORER |
win32con.OFN_DONTADDTORECENT |
win32con.OFN_NOCHANGEDIR)
files = ret[0].split('\0')
if len(files) > 1:
files = [os.path.join(files[0], file) for file in files[1:]]
except win32gui.error:
files = []
else:
files = sys.argv[1:]

if getattr(sys, "frozen", False):
os.chdir(os.path.dirname(sys.executable))
Expand Down Expand Up @@ -94,15 +120,15 @@ def process(filename):
finally:
table.append(line)

for argv in sys.argv[1:]:
if os.path.isdir(argv):
for root, dirs, files in os.walk(argv):
for filepath in files:
if os.path.isdir(filepath):
for root, dirs, files in os.walk(filepath):
dirs.sort()
files.sort()
for name in files:
process(os.path.join(root, name))
else:
process(argv)
process(filepath)

print("--------------+-------------------------------------------+-----------------")
print(" TIME | S16LE S24_3LE S32LE | FILE")
Expand All @@ -111,4 +137,5 @@ def process(filename):
print("--------------+-------------------------------------------+-----------------")

if os.name == "nt":
os.system("pause")
print(" press any key to exit ... ", end='', file=sys.stderr, flush=True)
msvcrt.getch()
2 changes: 1 addition & 1 deletion llusbdac/llusbdac.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <linux/hrtimer.h>
#include <linux/ktime.h>

#define LLUSBDAC_VERSTRING "1.0"
#define LLUSBDAC_VERSTRING "1.1"
#define LLUSBDAC_IDVENDER 0x054C
#define LLUSBDAC_IDPRODUCT 0x0B8B
#define LLUSBDAC_NAME "LLUSBDAC (NW-ZX300A)"
Expand Down
40 changes: 29 additions & 11 deletions llusbdac/uac2.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,28 @@
#include "llusbdac.h"

// dirty things
#include <linux/irq.h>
#include <linux/irqdesc.h>
#include <linux/musb/musb_core.h>
#include <net/net_namespace.h>
#include <net/netlink.h>
static void (**p_pf_get_uac2_buf_status)(u32 *status);
#define pf_get_uac2_buf_status (*p_pf_get_uac2_buf_status)
static void (*p_uac2_netlink_rcv)(struct sk_buff *__skb);
#define uac2_netlink_rcv p_uac2_netlink_rcv
static struct sock * uac2_netlink_init(void)
{
struct sock *uac2sock;
struct netlink_kernel_cfg cfg = {
.input = uac2_netlink_rcv,
};
uac2sock = netlink_kernel_create(&init_net, NETLINK_UAC2, &cfg);
//printk("uac2sock=%p\n", uac2sock);
return uac2sock;
}
static void uac2_netlink_exit(struct sock *sock)
{
netlink_kernel_release(sock);
}


#ifndef __LITTLE_ENDIAN
#error
Expand Down Expand Up @@ -98,6 +115,8 @@ struct audio_dev {
struct usb_ep *fb_ep;
struct usb_function func;

struct sock *sock;

void *rbuf;
unsigned max_psize;
struct uac2_req ureq[USB_XFERS];
Expand All @@ -116,7 +135,7 @@ struct audio_dev *func_to_agdev(struct usb_function *f)
return container_of(f, struct audio_dev, func);
}

#define FEEDBACK_PERIOD 8 // xref: hs_epfb_desc.bInterval, do_dirty_musb_hook
#define FEEDBACK_PERIOD 8 // xref: hs_epfb_desc.bInterval
static unsigned fb_low_limit, fb_high_limit;
void set_feedback_limits_base10000(unsigned low_limit, unsigned high_limit)
{
Expand Down Expand Up @@ -442,7 +461,7 @@ struct usb_endpoint_descriptor hs_epfb_desc = {
.bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_USAGE_FEEDBACK,
.wMaxPacketSize = 512,
//.bInterval = 1,
.bInterval = 4, // xref: FEEDBACK_PERIOD, do_dirty_musb_hook
.bInterval = 4, // xref: FEEDBACK_PERIOD
};


Expand Down Expand Up @@ -561,6 +580,8 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
agdev->as_out_intf = ret;
agdev->as_out_alt = 0;

agdev->sock = uac2_netlink_init();

agdev->out_ep = usb_ep_autoconfig(gadget, &hs_epout_desc);
if (!agdev->out_ep) {
pr_err(
Expand Down Expand Up @@ -612,6 +633,8 @@ afunc_unbind(struct usb_configuration *cfg, struct usb_function *fn)
printk("afunc_unbind\n");
struct audio_dev *agdev = func_to_agdev(fn);

uac2_netlink_exit(agdev->sock);

usb_free_all_descriptors(fn);

if (agdev->out_ep)
Expand Down Expand Up @@ -915,7 +938,6 @@ afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr)
return value;
}

//static void do_dirty_musb_hook(int en, struct musb *musb);

int audio_bind_config(struct usb_configuration *cfg)
{
Expand Down Expand Up @@ -970,16 +992,13 @@ int audio_bind_config(struct usb_configuration *cfg)
kfree(agdev_g);

enable_gui(1);

//do_dirty_musb_hook(1, gadget_to_musb(cfg->cdev->gadget));

return res;
}

void uac2_unbind_config(struct usb_configuration *cfg)
{
printk("uac2_unbind_config\n");
//do_dirty_musb_hook(0, gadget_to_musb(cfg->cdev->gadget));
enable_gui(-1);

kfree(agdev_g);
Expand All @@ -996,9 +1015,8 @@ int gadget_enabled(void)
}




void uac2_init(void)
{
IMPORT_KALLSYMS(pf_get_uac2_buf_status);
}
IMPORT_KALLSYMS(uac2_netlink_rcv);
}
27 changes: 17 additions & 10 deletions llusbdac_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
import win32event
import wmi

try:
ctypes.windll.user32.SetProcessDPIAware()
except:
pass

def die(status):
win32api.TerminateProcess(win32api.GetCurrentProcess(), status)
def die_after(status, sec):
Expand All @@ -33,8 +28,13 @@ def die_fn():
die(status)
threading.Thread(target=die_fn).start()

try:
ctypes.windll.user32.SetProcessDPIAware()
except:
pass


llusbdac_ver = "v1.0"
llusbdac_ver = "v1.1"

if getattr(sys, "frozen", False):
safeloader_dir = sys._MEIPASS
Expand Down Expand Up @@ -127,6 +127,7 @@ class InstallerCorruptedError(Exception):
"START": "开始安装",
"LEAVE": "取消安装",
"MULTI_INST": "安装工具已经在运行中,请勿多开。",
"INFORM_RISK": "安装 LLUSBDAC 需要修改播放器的固件。\n修改固件具有一定危险性,可能会导致失去保修,甚至损坏设备。\n本软件作者对任何损坏或损失不承担任何责任。\n\n是否继续?",

"CANCEL": "取消",
"ERROR": "错误",
Expand All @@ -135,7 +136,7 @@ class InstallerCorruptedError(Exception):
"VERIFY_PACKAGE": "正在验证固件升级包",
"NO_PACKAGE": "未找到固件升级包,\n",
"BAD_PACKAGE": "固件升级包已损坏,\n",
"ASK_DOWNLOAD": "要立即从 SONY 服务器上下载吗?",
"ASK_DOWNLOAD": "要立即从 SONY 服务器上下载吗?\n\n注意:下载固件即表示您同意固件随附的条款与条件。",
"DOWNLOAD_PROGRESS": "已下载 %.0f%%",
"DOWNLOAD_ERROR": "下载过程中发生错误。",
"ERR_PACKAGE": "固件升级包验证失败,无法继续安装。",
Expand Down Expand Up @@ -169,6 +170,7 @@ class InstallerCorruptedError(Exception):
"START": "Start",
"LEAVE": "Cancel",
"MULTI_INST": "Installer is running. Please don't open multiple instances.",
"INFORM_RISK": "In order to install LLUSBDAC, installer will modify the firmware of your player.\nThis may void warranty or damage your device.\nPlease use at your own risk.\n\nContinue?",

"CANCEL": "Cancel",
"ERROR": "Error",
Expand All @@ -177,7 +179,7 @@ class InstallerCorruptedError(Exception):
"VERIFY_PACKAGE": "Verifying update package ...",
"NO_PACKAGE": "Update package not found.\n",
"BAD_PACKAGE": "Update package corrupted.\n",
"ASK_DOWNLOAD": "Download it from SONY server now?",
"ASK_DOWNLOAD": "Download it from SONY server now?\n\nNOTE: Downloading it means you agree its EULA.",
"DOWNLOAD_PROGRESS": "Download progress %.0f%% ...",
"DOWNLOAD_ERROR": "Download error:",
"ERR_PACKAGE": "Can't verify update package, installation aborted.",
Expand Down Expand Up @@ -246,17 +248,22 @@ def reporthook_fn(xferd, bs, count):
c = wmi.WMI()


# single instance
# allow only one instance
def single_instance():
mutex = win32event.CreateMutex(None, True, "LLUSBDAC_INSTALLER_MUTEX")
ret = win32event.WaitForSingleObject(mutex, 2000)
if ret != win32event.WAIT_OBJECT_0 and ret != win32event.WAIT_ABANDONED:
win32api.MessageBox(None, S["MULTI_INST"], S["TITLE"], win32con.MB_ICONERROR)
win32api.MessageBox(None, S["MULTI_INST"], S["TITLE"], win32con.MB_ICONERROR | win32con.MB_TOPMOST)
die(1)
mutex.Detach()
single_instance()


# inform user the risk
if win32api.MessageBox(None, S["INFORM_RISK"], S["TITLE"], win32con.MB_ICONWARNING | win32con.MB_YESNO | win32con.MB_TOPMOST) != win32con.IDYES:
die(1)


# ask user for installer options
def ask_options():
class InstallerOptionsDialog:
Expand Down
6 changes: 4 additions & 2 deletions userguide/USERGUIDE_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Installer only supports Windows operating system. However, after installation in

## Installation

Connect your device to a computer as "USB mass storage device". Then run `llusbdac_installer.exe` and follow instructions on screen.
1. Download `NW-ZX300_V2_02.exe` from [sony website](https://www.sony.com/electronics/support/digital-music-players-nw-nwz-zx-series/nw-zx300/downloads/00016328), put it along with `llusbdac_installer.exe`.
2. Connect your device to a computer as "USB mass storage device".
3. Run `llusbdac_installer.exe` and follow instructions on screen.

## Usage

Expand Down Expand Up @@ -57,4 +59,4 @@ Sample results:

## Source code

&emsp;&emsp;This program is released under GPLv2. You can get the source code from [GitHub](https://github.com/zhangboyang/llusbdac).
This program is released under GPLv2. You can get the source code from [GitHub](https://github.com/zhangboyang/llusbdac).
4 changes: 3 additions & 1 deletion userguide/USERGUIDE_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

## 安装方法

&emsp;&emsp;将设备以“USB 大容量存储”模式连接至计算机,运行 `llusbdac_installer.exe`,然后按屏幕指示操作即可。
1.[索尼网站](https://service.sony.com.cn/download/firm/00002817.html)上下载 `NW-ZX300_V2_02.exe`,将它与 `llusbdac_installer.exe` 放置于同一目录下;
2. 将设备以“USB 大容量存储”模式连接至计算机;
3. 运行 `llusbdac_installer.exe`,然后按屏幕指示操作即可。

## 使用方法

Expand Down

0 comments on commit c53f702

Please sign in to comment.