Setting D-Link DIR-505 (AR9330) USB to Device Mode

Hi, im trying to set this device USB (with latest OpenWRT) to device mode, so i can use it as ethernet device via USB ( USB Ethernet Gadget)

i saw other devices that uses the same chip, that a resistor needs to be removed to change from host mode to device mode

anyones have experience or did this chage? is there a specific GPIO to change that? or can be done in software?

Thanks in advance!

It is not 9330, check dmesg for any mentions of OTG
Cutting wire will not install gadget support for certain. Can you provide source suggesting altering radio hardware?

Please connect to your OpenWrt device using ssh and copy the output of the following commands and post it here using the "Preformatted text </> " button:
grafik
Remember to redact passwords, MAC addresses and any public IP addresses you may have:

ubus call system board
cat /etc/config/network
cat /etc/config/wireless
cat /etc/config/dhcp
cat /etc/config/firewall

here one source:
https://neykov.name/posts/ar933x-usb-device-driver/

i also found other devices that also show removing resistors or pulling up GPIO's for the same objective, like this one:

the usb works great in host mode, i have another dir-505 with a usb hub, card reader, etc, that i use as a wifi usb/card reader for file transfer

i got another one of this devices to try using it on "gadget mode", making the usb as a ethernet device instead of host


        "kernel": "5.15.167",
        "hostname": "OpenWrt",
        "system": "Atheros AR9330 rev 1",
        "model": "D-Link DIR-505",
        "board_name": "dlink,dir-505",
        "rootfs_type": "squashfs",
        "release": {
                "distribution": "OpenWrt",
                "version": "23.05.5",
                "revision": "r24106-10cc5fcd00",
                "target": "ath79/generic",
                "description": "OpenWrt 23.05.5 r24106-10cc5fcd00"

dmesg:

[    0.000000] Linux version 5.15.167 (builder@buildhost) (mips-openwrt-linux-musl-gcc (OpenWrt GCC 12.3.0 r24106-10cc5fcd00) 12.3.0, GNU ld (GNU Binutils) 2.40.0) #0 Mon Sep 23 12:34:46 2024
[    0.000000] printk: bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 00019374 (MIPS 24Kc)
[    0.000000] MIPS: machine is D-Link DIR-505
[    0.000000] SoC: Atheros AR9330 rev 1
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 bytes
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x0000000003ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000003ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000003ffffff]
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 16240
[    0.000000] Kernel command line: console=ttyATH0,115200 rootfstype=squashfs,jffs2
[    0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
[    0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes, linear)
[    0.000000] Writing ErrCtl register=00000000
[    0.000000] Readback ErrCtl register=00000000
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 55916K/65536K available (6100K kernel code, 599K rwdata, 784K rodata, 1212K init, 216K bss, 9620K reserved, 0K cma-reserved)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 51
[    0.000000] CPU clock: 400.000 MHz
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 9556302233 ns
[    0.000002] sched_clock: 32 bits at 200MHz, resolution 5ns, wraps every 10737418237ns
[    0.007702] Calibrating delay loop... 265.42 BogoMIPS (lpj=1327104)
[    0.092269] pid_max: default: 32768 minimum: 301
[    0.098339] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.103979] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.121168] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.129306] futex hash table entries: 256 (order: -1, 3072 bytes, linear)
[    0.136051] pinctrl core: initialized pinctrl subsystem
[    0.143868] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.149199] thermal_sys: Registered thermal governor 'step_wise'
[    0.152813] gpio-1 (d-link:power:led): hogged as output/low
[    0.179280] clocksource: Switched to clocksource MIPS
[    0.185237] NET: Registered PF_INET protocol family
[    0.188957] IP idents hash table entries: 2048 (order: 2, 16384 bytes, linear)
[    0.197125] tcp_listen_portaddr_hash hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.203957] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.211300] TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.218604] TCP bind hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.225359] TCP: Hash tables configured (established 1024 bind 1024)
[    0.231676] UDP hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.237665] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.245046] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.249830] PCI: CLS 0 bytes, default 32
[    0.258923] workingset: timestamp_bits=14 max_order=14 bucket_order=0
[    0.273495] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.277721] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.289861] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)
[    0.299354] pinctrl-single 18040028.pinmux: 64 pins, size 8
[    0.305130] Serial: 8250/16550 driver, 16 ports, IRQ sharing enabled
[    0.314321] 18020000.uart: ttyATH0 at MMIO 0x18020000 (irq = 9, base_baud = 1562500) is a AR933X UART
[    0.322158] printk: console [ttyATH0] enabled
[    0.330482] printk: bootconsole [early0] disabled
[    0.367638] spi-nor spi0.0: mx25l6405d (8192 Kbytes)
[    0.371350] 6 fixed-partitions partitions found on MTD device spi0.0
[    0.377639] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.384212] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.391152] Creating 6 MTD partitions on "spi0.0":
[    0.395567] 0x000000000000-0x000000010000 : "u-boot"
[    0.407280] 0x000000010000-0x000000020000 : "art"
[    0.412331] 0x000000020000-0x000000030000 : "mac"
[    0.419977] 0x000000030000-0x000000040000 : "nvram"
[    0.425138] 0x000000040000-0x000000080000 : "language"
[    0.433014] 0x000000080000-0x000000800000 : "firmware"
[    0.438827] 2 uimage-fw partitions found on MTD device firmware
[    0.443419] Creating 2 MTD partitions on "firmware":
[    0.448340] 0x000000000000-0x000000240000 : "kernel"
[    0.457277] 0x000000240000-0x000000780000 : "rootfs"
[    0.462468] mtd: setting mtd7 (rootfs) as root device
[    0.467508] 1 squashfs-split partitions found on MTD device rootfs
[    0.472459] 0x0000005d0000-0x000000780000 : "rootfs_data"
[    0.836587] switch0: Atheros AR724X/AR933X built-in rev. 2 switch registered on mdio.0
[    0.885165] ag71xx 19000000.eth: invalid MAC address, using random address
[    1.309939] ag71xx 19000000.eth: connected to PHY at mdio.0:1f:04 [uid=004dd041, driver=Qualcomm Atheros AR9331 built-in PHY]
[    1.320962] eth0: Atheros AG71xx at 0xb9000000, irq 4, mode: mii
[    1.326546] i2c_dev: i2c /dev entries driver
[    1.334159] NET: Registered PF_INET6 protocol family
[    1.351968] Segment Routing with IPv6
[    1.354325] In-situ OAM (IOAM) with IPv6
[    1.358333] NET: Registered PF_PACKET protocol family
[    1.363359] bridge: filtering via arp/ip/ip6tables is no longer available by default. Update your scripts to load br_netfilter if you need this.
[    1.376848] 8021q: 802.1Q VLAN Support v1.8
[    1.384847] clk: Disabling unused clocks
[    1.399632] VFS: Mounted root (squashfs filesystem) readonly on device 31:7.
[    1.414490] Freeing unused kernel image (initmem) memory: 1212K
[    1.418964] This architecture does not have kernel memory protection.
[    1.425445] Run /sbin/init as init process
[    1.429482]   with arguments:
[    1.429491]     /sbin/init
[    1.429500]   with environment:
[    1.429508]     HOME=/
[    1.429517]     TERM=linux
[    2.330035] init: Console is alive
[    2.332861] init: - watchdog -
[    4.073223] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    4.190699] usbcore: registered new interface driver usbfs
[    4.194844] usbcore: registered new interface driver hub
[    4.200247] usbcore: registered new device driver usb
[    4.224801] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    4.250566] ci_hdrc ci_hdrc.0: EHCI Host Controller
[    4.254076] ci_hdrc ci_hdrc.0: new USB bus registered, assigned bus number 1
[    4.289291] ci_hdrc ci_hdrc.0: USB 2.0 started, EHCI 1.00
[    4.294792] hub 1-0:1.0: USB hub found
[    4.298346] hub 1-0:1.0: 1 port detected
[    4.307323] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    4.324538] init: - preinit -
[    6.347592] random: jshn: uninitialized urandom read (4 bytes read)
[    6.932419] random: jshn: uninitialized urandom read (4 bytes read)
[    7.078642] random: jshn: uninitialized urandom read (4 bytes read)
[    7.379560] random: jshn: uninitialized urandom read (4 bytes read)
[    7.500947] random: procd: uninitialized urandom read (4 bytes read)
[    9.541080] eth0: link up (100Mbps/Full duplex)
[    9.544238] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    9.901976] jffs2: notice: (429) jffs2_build_xattr_subsystem: complete building xattr subsystem, 25 of xdatum (18 unchecked, 4 orphan) and 31 of xref (4 dead, 0 orphan) found.
[    9.922484] mount_root: switching to jffs2 overlay
[    9.944036] overlayfs: upper fs does not support tmpfile.
[    9.963101] urandom-seed: Seeding with /etc/urandom.seed
[   10.173620] eth0: link down
[   10.198813] procd: - early -
[   10.200937] procd: - watchdog -
[   11.031844] random: jshn: uninitialized urandom read (4 bytes read)
[   11.186810] procd: - watchdog -
[   11.191129] procd: - ubus -
[   11.423443] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.433310] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.453433] procd: - init -
[   12.118770] random: jshn: uninitialized urandom read (4 bytes read)
[   12.142862] random: ubusd: uninitialized urandom read (4 bytes read)
[   13.356592] kmodloader: loading kernel modules from /etc/modules.d/*
[   14.535591] Loading modules backported from Linux version v6.1.110-0-g5f55cad62cc9d
[   14.541903] Backport generated by backports.git v6.1.110-1-0-g965f73fc
[   15.485986] PPP generic driver version 2.4.2
[   15.501039] NET: Registered PF_PPPOX protocol family
[   15.656130] ath: EEPROM regdomain: 0x0
[   15.656173] ath: EEPROM indicates default country code should be used
[   15.656184] ath: doing EEPROM country->regdmn map search
[   15.656205] ath: country maps to regdmn code: 0x3a
[   15.656218] ath: Country alpha2 being used: US
[   15.656230] ath: Regpair used: 0x3a
[   15.670991] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
[   15.674925] ieee80211 phy0: Atheros AR9330 Rev:1 mem=0x(ptrval), irq=2
[   15.750010] kmodloader: done loading kernel modules from /etc/modules.d/*
[   21.020122] urngd: v1.0.2 started.
[   27.478423] random: crng init done
[   27.480508] random: 73 urandom warning(s) missed due to ratelimiting
[   47.680215] br-lan: port 1(eth0) entered blocking state
[   47.684032] br-lan: port 1(eth0) entered disabled state
[   47.689808] device eth0 entered promiscuous mode
[   50.821212] eth0: link up (100Mbps/Full duplex)
[   50.824387] br-lan: port 1(eth0) entered blocking state
[   50.829592] br-lan: port 1(eth0) entered forwarding state
[   50.869560] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready
[   55.590376] br-lan: port 2(phy0-ap0) entered blocking state
[   55.594533] br-lan: port 2(phy0-ap0) entered disabled state
[   55.600655] device phy0-ap0 entered promiscuous mode
[   56.298791] IPv6: ADDRCONF(NETDEV_CHANGE): phy0-ap0: link becomes ready
[   56.304387] br-lan: port 2(phy0-ap0) entered blocking state
[   56.309626] br-lan: port 2(phy0-ap0) entered forwarding state

/etc/config/network

config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd3d:cf7e:42a4::/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0'

config device
        option name 'eth0'
        option macaddr '6c:19:8f:ee:3e:48'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option ipaddr '192.168.92.254'
        option netmask '255.255.255.0'
        option ip6assign '60'
        option gateway '192.168.92.2'
        list dns '8.8.8.8'

/etc/config/wireless

config wifi-device 'radio0'
        option type 'mac80211'
        option path 'platform/ahb/18100000.wmac'
        option channel '1'
        option band '2g'
        option htmode 'HT20'
        option cell_density '0'
        option txpower '17'

config wifi-iface 'default_radio0'
        option device 'radio0'
        option network 'lan'
        option mode 'ap'
        option ssid 'Bridge'
        option encryption 'psk2'
        option key 'XXX'

/etc/config/dhcp

config dnsmasq
        option domainneeded '1'
        option boguspriv '1'
        option filterwin2k '0'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        option expandhosts '1'
        option nonegcache '0'
        option cachesize '1000'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.d/resolv.conf.auto'
        option nonwildcard '1'
        option localservice '1'
        option ednspacket_max '1232'
        option filter_aaaa '0'
        option filter_a '0'

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option dhcpv4 'server'
        option dhcpv6 'server'
        option ra 'server'
        list ra_flags 'managed-config'
        list ra_flags 'other-config'

config dhcp 'wan'
        option interface 'wan'
        option ignore '1'

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'
        option loglevel '4'


/etc/config/firewall
config defaults
        option syn_flood        1
        option input            REJECT
        option output           ACCEPT
        option forward          REJECT
# Uncomment this line to disable ipv6 rules
#       option disable_ipv6     1

config zone
        option name             lan
        list   network          'lan'
        option input            ACCEPT
        option output           ACCEPT
        option forward          ACCEPT

config zone
        option name             wan
        list   network          'wan'
        list   network          'wan6'
        option input            REJECT
        option output           ACCEPT
        option forward          REJECT
        option masq             1
        option mtu_fix          1

config forwarding
        option src              lan
        option dest             wan

# We need to accept udp packets on port 68,
# see https://dev.openwrt.org/ticket/4108
config rule
        option name             Allow-DHCP-Renew
        option src              wan
        option proto            udp
        option dest_port        68
        option target           ACCEPT
        option family           ipv4

# Allow IPv4 ping
config rule
        option name             Allow-Ping
        option src              wan
        option proto            icmp
        option icmp_type        echo-request
        option family           ipv4
        option target           ACCEPT

config rule
        option name             Allow-IGMP
        option src              wan
        option proto            igmp
        option family           ipv4
        option target           ACCEPT

# Allow DHCPv6 replies
# see https://github.com/openwrt/openwrt/issues/5066
config rule
        option name             Allow-DHCPv6
        option src              wan
        option proto            udp
        option dest_port        546
        option family           ipv6
        option target           ACCEPT

config rule
        option name             Allow-MLD
        option src              wan
        option proto            icmp
        option src_ip           fe80::/10
        list icmp_type          '130/0'
        list icmp_type          '131/0'
        list icmp_type          '132/0'
        list icmp_type          '143/0'
        option family           ipv6
        option target           ACCEPT

# Allow essential incoming IPv6 ICMP traffic
config rule
        option name             Allow-ICMPv6-Input
        option src              wan
        option proto    icmp
        list icmp_type          echo-request
        list icmp_type          echo-reply
        list icmp_type          destination-unreachable
        list icmp_type          packet-too-big
        list icmp_type          time-exceeded
        list icmp_type          bad-header
        list icmp_type          unknown-header-type
        list icmp_type          router-solicitation
        list icmp_type          neighbour-solicitation
        list icmp_type          router-advertisement
        list icmp_type          neighbour-advertisement
        option limit            1000/sec
        option family           ipv6
        option target           ACCEPT

# Allow essential forwarded IPv6 ICMP traffic
config rule
        option name             Allow-ICMPv6-Forward
        option src              wan
        option dest             *
        option proto            icmp
        list icmp_type          echo-request
        list icmp_type          echo-reply
        list icmp_type          destination-unreachable
        list icmp_type          packet-too-big
        list icmp_type          time-exceeded
        list icmp_type          bad-header
        list icmp_type          unknown-header-type
        option limit            1000/sec
        option family           ipv6
        option target           ACCEPT

config rule
        option name             Allow-IPSec-ESP
        option src              wan
        option dest             lan
        option proto            esp
        option target           ACCEPT

config rule
        option name             Allow-ISAKMP
        option src              wan
        option dest             lan
        option dest_port        500
        option proto            udp
        option target           ACCEPT


### EXAMPLE CONFIG SECTIONS
# do not allow a specific ip to access wan
#config rule
#       option src              lan
#       option src_ip   192.168.45.2
#       option dest             wan
#       option proto    tcp
#       option target   REJECT

# block a specific mac on wan
#config rule
#       option dest             wan
#       option src_mac  00:11:22:33:44:66
#       option target   REJECT

# block incoming ICMP traffic on a zone
#config rule
#       option src              lan
#       option proto    ICMP
#       option target   DROP

# port redirect port coming in on wan to lan
#config redirect
#       option src                      wan
#       option src_dport        80
#       option dest                     lan
#       option dest_ip          192.168.16.235
#       option dest_port        80
#       option proto            tcp

# port redirect of remapped ssh port (22001) on wan
#config redirect
#       option src              wan
#       option src_dport        22001
#       option dest             lan
#       option dest_port        22
#       option proto            tcp

### FULL CONFIG SECTIONS
#config rule
#       option src              lan
#       option src_ip   192.168.45.2
#       option src_mac  00:11:22:33:44:55
#       option src_port 80
#       option dest             wan
#       option dest_ip  194.25.2.129
#       option dest_port        120
#       option proto    tcp
#       option target   REJECT

#config redirect
#       option src              lan
#       option src_ip   192.168.45.2
#       option src_mac  00:11:22:33:44:55
#       option src_port         1024
#       option src_dport        80
#       option dest_ip  194.25.2.129
#       option dest_port        120
#       option proto    tcp

ehci_hcd does nt support usb-otg on its own.

apparently, docs and some forums show it uses GPIO 13 to set usb mode (mode 0=device, 1=host) at boot, so modify the hardware is necessary

will try to find GPIO 13 on the board to set value