Compare commits
7 Commits
main
...
driver_ray
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ca4a10aa4 | ||
|
|
46e2d50a55 | ||
|
|
95889d091c | ||
|
|
32c039da54 | ||
|
|
16119c5725 | ||
|
|
2931340eee | ||
|
|
aa29c8b2a5 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
|||||||
build
|
build
|
||||||
|
compile_commands.json
|
||||||
|
.module-commands.o
|
||||||
|
|||||||
BIN
.module-common.o
BIN
.module-common.o
Binary file not shown.
@@ -1,307 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"file": "src/ch349_driver.c",
|
|
||||||
"arguments": [
|
|
||||||
"gcc",
|
|
||||||
"-Wp,-MMD,src/.ch349_driver.o.d",
|
|
||||||
"-nostdinc",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/arch/x86/include",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/arch/x86/include/generated",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/include",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/include",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/arch/x86/include/uapi",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/arch/x86/include/generated/uapi",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/include/uapi",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/include/generated/uapi",
|
|
||||||
"-include",
|
|
||||||
"/usr/lib/modules/6.18.7-arch1-1/build/include/linux/compiler-version.h",
|
|
||||||
"-include",
|
|
||||||
"/usr/lib/modules/6.18.7-arch1-1/build/include/linux/kconfig.h",
|
|
||||||
"-include",
|
|
||||||
"/usr/lib/modules/6.18.7-arch1-1/build/include/linux/compiler_types.h",
|
|
||||||
"-D__KERNEL__",
|
|
||||||
"-std=gnu11",
|
|
||||||
"-fshort-wchar",
|
|
||||||
"-funsigned-char",
|
|
||||||
"-fno-common",
|
|
||||||
"-fno-PIE",
|
|
||||||
"-fno-strict-aliasing",
|
|
||||||
"-mno-sse",
|
|
||||||
"-mno-mmx",
|
|
||||||
"-mno-sse2",
|
|
||||||
"-mno-3dnow",
|
|
||||||
"-mno-avx",
|
|
||||||
"-mno-sse4a",
|
|
||||||
"-fcf-protection=branch",
|
|
||||||
"-fno-jump-tables",
|
|
||||||
"-m64",
|
|
||||||
"-falign-jumps=1",
|
|
||||||
"-falign-loops=1",
|
|
||||||
"-mno-80387",
|
|
||||||
"-mno-fp-ret-in-387",
|
|
||||||
"-mskip-rax-setup",
|
|
||||||
"-march=x86-64",
|
|
||||||
"-mtune=generic",
|
|
||||||
"-mno-red-zone",
|
|
||||||
"-mcmodel=kernel",
|
|
||||||
"-mstack-protector-guard-reg=gs",
|
|
||||||
"-mstack-protector-guard-symbol=__ref_stack_chk_guard",
|
|
||||||
"-Wno-sign-compare",
|
|
||||||
"-fno-asynchronous-unwind-tables",
|
|
||||||
"-mindirect-branch-cs-prefix",
|
|
||||||
"-mfunction-return=thunk-extern",
|
|
||||||
"-fno-jump-tables",
|
|
||||||
"-mharden-sls=all",
|
|
||||||
"-fpatchable-function-entry=16,16",
|
|
||||||
"-fno-delete-null-pointer-checks",
|
|
||||||
"-O2",
|
|
||||||
"-Wno-declaration-after-statement",
|
|
||||||
"-DMODULE",
|
|
||||||
"-DKBUILD_BASENAME=\"ch349_driver\"",
|
|
||||||
"-DKBUILD_MODNAME=\"ch349_driver\"",
|
|
||||||
"-D__KBUILD_MODNAME=kmod_ch349_driver",
|
|
||||||
"-c",
|
|
||||||
"-o",
|
|
||||||
"src/ch349_driver.o",
|
|
||||||
"src/ch349_driver.c"
|
|
||||||
],
|
|
||||||
"directory": "/home/bob/Projects/rj45toUSB_adapter/driver",
|
|
||||||
"output": "src/ch349_driver.o"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"file": "ch349_driver.mod.c",
|
|
||||||
"arguments": [
|
|
||||||
"gcc",
|
|
||||||
"-Wp,-MMD,./.ch349_driver.mod.o.d",
|
|
||||||
"-nostdinc",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/arch/x86/include",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/arch/x86/include/generated",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/include",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/include",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/arch/x86/include/uapi",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/arch/x86/include/generated/uapi",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/include/uapi",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/include/generated/uapi",
|
|
||||||
"-include",
|
|
||||||
"/usr/lib/modules/6.18.7-arch1-1/build/include/linux/compiler-version.h",
|
|
||||||
"-include",
|
|
||||||
"/usr/lib/modules/6.18.7-arch1-1/build/include/linux/kconfig.h",
|
|
||||||
"-include",
|
|
||||||
"/usr/lib/modules/6.18.7-arch1-1/build/include/linux/compiler_types.h",
|
|
||||||
"-D__KERNEL__",
|
|
||||||
"-std=gnu11",
|
|
||||||
"-fshort-wchar",
|
|
||||||
"-funsigned-char",
|
|
||||||
"-fno-common",
|
|
||||||
"-fno-PIE",
|
|
||||||
"-fno-strict-aliasing",
|
|
||||||
"-mno-sse",
|
|
||||||
"-mno-mmx",
|
|
||||||
"-mno-sse2",
|
|
||||||
"-mno-3dnow",
|
|
||||||
"-mno-avx",
|
|
||||||
"-mno-sse4a",
|
|
||||||
"-fcf-protection=branch",
|
|
||||||
"-fno-jump-tables",
|
|
||||||
"-m64",
|
|
||||||
"-falign-jumps=1",
|
|
||||||
"-falign-loops=1",
|
|
||||||
"-mno-80387",
|
|
||||||
"-mno-fp-ret-in-387",
|
|
||||||
"-mskip-rax-setup",
|
|
||||||
"-march=x86-64",
|
|
||||||
"-mtune=generic",
|
|
||||||
"-mno-red-zone",
|
|
||||||
"-mcmodel=kernel",
|
|
||||||
"-mstack-protector-guard-reg=gs",
|
|
||||||
"-mstack-protector-guard-symbol=__ref_stack_chk_guard",
|
|
||||||
"-Wno-sign-compare",
|
|
||||||
"-fno-asynchronous-unwind-tables",
|
|
||||||
"-mindirect-branch-cs-prefix",
|
|
||||||
"-mfunction-return=thunk-extern",
|
|
||||||
"-fno-jump-tables",
|
|
||||||
"-mharden-sls=all",
|
|
||||||
"-fpatchable-function-entry=16,16",
|
|
||||||
"-fno-delete-null-pointer-checks",
|
|
||||||
"-O2",
|
|
||||||
"-fstack-protector-strong",
|
|
||||||
"-fno-builtin-wcslen",
|
|
||||||
"-Wall",
|
|
||||||
"-Wextra",
|
|
||||||
"-Wundef",
|
|
||||||
"-Werror=implicit-function-declaration",
|
|
||||||
"-Werror=implicit-int",
|
|
||||||
"-Werror=return-type",
|
|
||||||
"-Werror=strict-prototypes",
|
|
||||||
"-Wno-format-security",
|
|
||||||
"-Wno-trigraphs",
|
|
||||||
"-Wno-frame-address",
|
|
||||||
"-Wno-address-of-packed-member",
|
|
||||||
"-Wmissing-declarations",
|
|
||||||
"-Wmissing-prototypes",
|
|
||||||
"-Wframe-larger-than=2048",
|
|
||||||
"-Wno-main",
|
|
||||||
"-Wno-dangling-pointer",
|
|
||||||
"-Wvla-larger-than=1",
|
|
||||||
"-Wno-pointer-sign",
|
|
||||||
"-Wcast-function-type",
|
|
||||||
"-Wno-unterminated-string-initialization",
|
|
||||||
"-Wno-array-bounds",
|
|
||||||
"-Wno-stringop-overflow",
|
|
||||||
"-Wno-alloc-size-larger-than",
|
|
||||||
"-Wimplicit-fallthrough=5",
|
|
||||||
"-Werror=date-time",
|
|
||||||
"-Werror=incompatible-pointer-types",
|
|
||||||
"-Werror=designated-init",
|
|
||||||
"-Wenum-conversion",
|
|
||||||
"-Wunused",
|
|
||||||
"-Wno-unused-but-set-variable",
|
|
||||||
"-Wno-unused-const-variable",
|
|
||||||
"-Wno-packed-not-aligned",
|
|
||||||
"-Wno-format-overflow",
|
|
||||||
"-Wno-format-truncation",
|
|
||||||
"-Wno-stringop-truncation",
|
|
||||||
"-Wno-override-init",
|
|
||||||
"-Wno-missing-field-initializers",
|
|
||||||
"-Wno-type-limits",
|
|
||||||
"-Wno-shift-negative-value",
|
|
||||||
"-Wno-maybe-uninitialized",
|
|
||||||
"-Wno-sign-compare",
|
|
||||||
"-Wno-unused-parameter",
|
|
||||||
"-g",
|
|
||||||
"-gdwarf-5",
|
|
||||||
"-DMODULE",
|
|
||||||
"-DKBUILD_BASENAME=\"ch349_driver.mod\"",
|
|
||||||
"-DKBUILD_MODNAME=\"ch349_driver\"",
|
|
||||||
"-D__KBUILD_MODNAME=kmod_ch349_driver",
|
|
||||||
"-c",
|
|
||||||
"-o",
|
|
||||||
"ch349_driver.mod.o",
|
|
||||||
"ch349_driver.mod.c"
|
|
||||||
],
|
|
||||||
"directory": "/home/bob/Projects/rj45toUSB_adapter/driver",
|
|
||||||
"output": "ch349_driver.mod.o"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"file": "/usr/lib/modules/6.18.7-arch1-1/build/scripts/module-common.c",
|
|
||||||
"arguments": [
|
|
||||||
"gcc",
|
|
||||||
"-Wp,-MMD,./..module-common.o.d",
|
|
||||||
"-nostdinc",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/arch/x86/include",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/arch/x86/include/generated",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/include",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/include",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/arch/x86/include/uapi",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/arch/x86/include/generated/uapi",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/include/uapi",
|
|
||||||
"-I/usr/lib/modules/6.18.7-arch1-1/build/include/generated/uapi",
|
|
||||||
"-include",
|
|
||||||
"/usr/lib/modules/6.18.7-arch1-1/build/include/linux/compiler-version.h",
|
|
||||||
"-include",
|
|
||||||
"/usr/lib/modules/6.18.7-arch1-1/build/include/linux/kconfig.h",
|
|
||||||
"-include",
|
|
||||||
"/usr/lib/modules/6.18.7-arch1-1/build/include/linux/compiler_types.h",
|
|
||||||
"-D__KERNEL__",
|
|
||||||
"-std=gnu11",
|
|
||||||
"-fshort-wchar",
|
|
||||||
"-funsigned-char",
|
|
||||||
"-fno-common",
|
|
||||||
"-fno-PIE",
|
|
||||||
"-fno-strict-aliasing",
|
|
||||||
"-mno-sse",
|
|
||||||
"-mno-mmx",
|
|
||||||
"-mno-sse2",
|
|
||||||
"-mno-3dnow",
|
|
||||||
"-mno-avx",
|
|
||||||
"-mno-sse4a",
|
|
||||||
"-fcf-protection=branch",
|
|
||||||
"-fno-jump-tables",
|
|
||||||
"-m64",
|
|
||||||
"-falign-jumps=1",
|
|
||||||
"-falign-loops=1",
|
|
||||||
"-mno-80387",
|
|
||||||
"-mno-fp-ret-in-387",
|
|
||||||
"-mskip-rax-setup",
|
|
||||||
"-march=x86-64",
|
|
||||||
"-mtune=generic",
|
|
||||||
"-mno-red-zone",
|
|
||||||
"-mcmodel=kernel",
|
|
||||||
"-mstack-protector-guard-reg=gs",
|
|
||||||
"-mstack-protector-guard-symbol=__ref_stack_chk_guard",
|
|
||||||
"-Wno-sign-compare",
|
|
||||||
"-fno-asynchronous-unwind-tables",
|
|
||||||
"-mindirect-branch-cs-prefix",
|
|
||||||
"-mfunction-return=thunk-extern",
|
|
||||||
"-fno-jump-tables",
|
|
||||||
"-mharden-sls=all",
|
|
||||||
"-fpatchable-function-entry=16,16",
|
|
||||||
"-fno-delete-null-pointer-checks",
|
|
||||||
"-O2",
|
|
||||||
"-fstack-protector-strong",
|
|
||||||
"-ftrivial-auto-var-init=zero",
|
|
||||||
"-fno-stack-clash-protection",
|
|
||||||
"-pg",
|
|
||||||
"-mfentry",
|
|
||||||
"-DCC_USING_FENTRY",
|
|
||||||
"-fstrict-flex-arrays=3",
|
|
||||||
"-fno-strict-overflow",
|
|
||||||
"-fno-stack-check",
|
|
||||||
"-fno-builtin-wcslen",
|
|
||||||
"-Wall",
|
|
||||||
"-Wextra",
|
|
||||||
"-Wundef",
|
|
||||||
"-Werror=implicit-function-declaration",
|
|
||||||
"-Werror=implicit-int",
|
|
||||||
"-Werror=return-type",
|
|
||||||
"-Werror=strict-prototypes",
|
|
||||||
"-Wno-format-security",
|
|
||||||
"-Wno-trigraphs",
|
|
||||||
"-Wno-frame-address",
|
|
||||||
"-Wno-address-of-packed-member",
|
|
||||||
"-Wmissing-declarations",
|
|
||||||
"-Wmissing-prototypes",
|
|
||||||
"-Wframe-larger-than=2048",
|
|
||||||
"-Wno-main",
|
|
||||||
"-Wno-dangling-pointer",
|
|
||||||
"-Wvla-larger-than=1",
|
|
||||||
"-Wno-pointer-sign",
|
|
||||||
"-Wcast-function-type",
|
|
||||||
"-Wno-unterminated-string-initialization",
|
|
||||||
"-Wno-array-bounds",
|
|
||||||
"-Wno-stringop-overflow",
|
|
||||||
"-Wno-alloc-size-larger-than",
|
|
||||||
"-Wimplicit-fallthrough=5",
|
|
||||||
"-Werror=date-time",
|
|
||||||
"-Werror=incompatible-pointer-types",
|
|
||||||
"-Werror=designated-init",
|
|
||||||
"-Wenum-conversion",
|
|
||||||
"-Wunused",
|
|
||||||
"-Wno-unused-but-set-variable",
|
|
||||||
"-Wno-unused-const-variable",
|
|
||||||
"-Wno-packed-not-aligned",
|
|
||||||
"-Wno-format-overflow",
|
|
||||||
"-Wno-format-truncation",
|
|
||||||
"-Wno-stringop-truncation",
|
|
||||||
"-Wno-override-init",
|
|
||||||
"-Wno-missing-field-initializers",
|
|
||||||
"-Wno-type-limits",
|
|
||||||
"-Wno-shift-negative-value",
|
|
||||||
"-Wno-maybe-uninitialized",
|
|
||||||
"-Wno-sign-compare",
|
|
||||||
"-Wno-unused-parameter",
|
|
||||||
"-g",
|
|
||||||
"-gdwarf-5",
|
|
||||||
"-DMODULE",
|
|
||||||
"-DKBUILD_BASENAME=\".module_common\"",
|
|
||||||
"-DKBUILD_MODNAME=\".module_common.o\"",
|
|
||||||
"-D__KBUILD_MODNAME=kmod_.module_common.o",
|
|
||||||
"-c",
|
|
||||||
"-o",
|
|
||||||
".module-common.o",
|
|
||||||
"/usr/lib/modules/6.18.7-arch1-1/build/scripts/module-common.c"
|
|
||||||
],
|
|
||||||
"directory": "/home/bob/Projects/rj45toUSB_adapter/driver",
|
|
||||||
"output": ".module-common.o"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
81
send_eth.c
Normal file
81
send_eth.c
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
// commande : sudo ./send_eth <ifname> <dst-mac> <src-mac> <ethertype(hex)> <payload-as-string>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <linux/if_packet.h>
|
||||||
|
#include <linux/if_ether.h>
|
||||||
|
#include <linux/if.h>
|
||||||
|
|
||||||
|
static int mac_from_str(const char *s, unsigned char *mac) {
|
||||||
|
int vals[6];
|
||||||
|
if (sscanf(s, "%x:%x:%x:%x:%x:%x",
|
||||||
|
&vals[0], &vals[1], &vals[2],
|
||||||
|
&vals[3], &vals[4], &vals[5]) != 6) return -1;
|
||||||
|
for (int i = 0; i < 6; ++i) mac[i] = (unsigned char)vals[i];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
if (argc < 6) {
|
||||||
|
fprintf(stderr, "Usage: %s <ifname> <dst-mac> <src-mac> <ethertype(hex)> <payload>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *ifname = argv[1];
|
||||||
|
unsigned char dst_mac[6], src_mac[6];
|
||||||
|
if (mac_from_str(argv[2], dst_mac) < 0) { fprintf(stderr, "Bad dst-mac\n"); return 1; }
|
||||||
|
if (mac_from_str(argv[3], src_mac) < 0) { fprintf(stderr, "Bad src-mac\n"); return 1; }
|
||||||
|
|
||||||
|
unsigned int ethertype;
|
||||||
|
if (sscanf(argv[4], "%x", ðertype) != 1) { fprintf(stderr, "Bad ethertype\n"); return 1; }
|
||||||
|
|
||||||
|
const char *payload = argv[5];
|
||||||
|
size_t payload_len = strlen(payload);
|
||||||
|
|
||||||
|
int sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
|
||||||
|
if (sock == -1) { perror("socket"); return 1; }
|
||||||
|
|
||||||
|
struct ifreq ifr;
|
||||||
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
|
strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1);
|
||||||
|
if (ioctl(sock, SIOCGIFINDEX, &ifr) == -1) { perror("SIOCGIFINDEX"); close(sock); return 1; }
|
||||||
|
int ifindex = ifr.ifr_ifindex;
|
||||||
|
|
||||||
|
unsigned char frame[ETH_FRAME_LEN];
|
||||||
|
size_t frame_len = 0;
|
||||||
|
|
||||||
|
memcpy(frame + frame_len, dst_mac, 6); frame_len += 6;
|
||||||
|
memcpy(frame + frame_len, src_mac, 6); frame_len += 6;
|
||||||
|
frame[frame_len++] = (ethertype >> 8) & 0xff;
|
||||||
|
frame[frame_len++] = ethertype & 0xff;
|
||||||
|
|
||||||
|
if (payload_len + frame_len > ETH_DATA_LEN + ETH_HLEN) {
|
||||||
|
fprintf(stderr, "Payload too large\n"); close(sock); return 1;
|
||||||
|
}
|
||||||
|
memcpy(frame + frame_len, payload, payload_len);
|
||||||
|
frame_len += payload_len;
|
||||||
|
|
||||||
|
if (frame_len < 60) {
|
||||||
|
memset(frame + frame_len, 0, 60 - frame_len);
|
||||||
|
frame_len = 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sockaddr_ll sock_addr;
|
||||||
|
memset(&sock_addr, 0, sizeof(sock_addr));
|
||||||
|
sock_addr.sll_ifindex = ifindex;
|
||||||
|
sock_addr.sll_halen = ETH_ALEN;
|
||||||
|
memcpy(sock_addr.sll_addr, dst_mac, 6);
|
||||||
|
|
||||||
|
ssize_t sent = sendto(sock, frame, frame_len, 0, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
|
||||||
|
if (sent == -1) { perror("sendto"); close(sock); return 1; }
|
||||||
|
|
||||||
|
printf("Sent %zd bytes on %s\n", sent, ifname);
|
||||||
|
close(sock);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -29,8 +29,8 @@ struct ch397_device {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const struct usb_device_id ch397_table[] = {
|
static const struct usb_device_id ch397_table[] = {
|
||||||
{ USB_DEVICE_AND_INTERFACE_INFO(CH397_VENDOR_ID, CH397_PRODUCT_ID,
|
|
||||||
USB_CLASS_CDC_DATA, 0, 0) },
|
{ USB_DEVICE(CH397_VENDOR_ID, CH397_PRODUCT_ID) },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
MODULE_DEVICE_TABLE(usb, ch397_table);
|
MODULE_DEVICE_TABLE(usb, ch397_table);
|
||||||
@@ -99,7 +99,7 @@ static void ch397_read_callback(struct urb *urb)
|
|||||||
struct ch397_device *dev = urb->context;
|
struct ch397_device *dev = urb->context;
|
||||||
struct net_device *netdev = dev->netdev;
|
struct net_device *netdev = dev->netdev;
|
||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
struct ethhdr *eth;
|
|
||||||
int status = urb->status;
|
int status = urb->status;
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
@@ -214,6 +214,7 @@ static int ch397_net_open(struct net_device *netdev)
|
|||||||
if (retval)
|
if (retval)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
|
netif_carrier_on(netdev);
|
||||||
netif_start_queue(netdev);
|
netif_start_queue(netdev);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -225,17 +226,66 @@ static int ch397_net_stop(struct net_device *netdev)
|
|||||||
printk(KERN_INFO "ch397: Interface DOWN\n");
|
printk(KERN_INFO "ch397: Interface DOWN\n");
|
||||||
|
|
||||||
netif_stop_queue(netdev);
|
netif_stop_queue(netdev);
|
||||||
|
netif_carrier_off(netdev);
|
||||||
ch397_stop_rx(dev);
|
ch397_stop_rx(dev);
|
||||||
|
|
||||||
|
netif_carrier_off(netdev);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ch397_write_callback(struct urb *urb)
|
||||||
|
{
|
||||||
|
struct sk_buff *skb = urb->context;
|
||||||
|
struct net_device *netdev = skb->dev;
|
||||||
|
|
||||||
|
if (urb->status == 0) {
|
||||||
|
// Transmission réussie
|
||||||
|
netdev->stats.tx_packets++;
|
||||||
|
netdev->stats.tx_bytes += skb->len;
|
||||||
|
} else {
|
||||||
|
netdev->stats.tx_errors++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Libérer le skb et l'urb
|
||||||
|
dev_kfree_skb_any(skb);
|
||||||
|
usb_free_urb(urb);
|
||||||
|
}
|
||||||
|
|
||||||
static netdev_tx_t ch397_start_xmit(struct sk_buff *skb,
|
static netdev_tx_t ch397_start_xmit(struct sk_buff *skb,
|
||||||
struct net_device *netdev)
|
struct net_device *netdev)
|
||||||
{
|
{
|
||||||
// Pour l'instant, on drop juste les packets TX
|
struct ch397_device *dev = netdev_priv(netdev);
|
||||||
|
struct urb *urb;
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
// Allouer un URB pour l'envoi
|
||||||
|
urb = usb_alloc_urb(0, GFP_ATOMIC);
|
||||||
|
if (!urb) {
|
||||||
dev_kfree_skb(skb);
|
dev_kfree_skb(skb);
|
||||||
netdev->stats.tx_dropped++;
|
netdev->stats.tx_dropped++;
|
||||||
|
return NETDEV_TX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Préparer l'URB (Bulk OUT)
|
||||||
|
usb_fill_bulk_urb(urb, dev->udev,
|
||||||
|
usb_sndbulkpipe(dev->udev,
|
||||||
|
dev->bulk_out_endpointAddr),
|
||||||
|
skb->data, skb->len, ch397_write_callback, skb);
|
||||||
|
|
||||||
|
// Soumettre l'URB
|
||||||
|
retval = usb_submit_urb(urb, GFP_ATOMIC);
|
||||||
|
if (retval) {
|
||||||
|
dev_err(&dev->interface->dev, "Failed to submit TX URB: %d\n",
|
||||||
|
retval);
|
||||||
|
usb_free_urb(urb);
|
||||||
|
dev_kfree_skb(skb);
|
||||||
|
netdev->stats.tx_errors++;
|
||||||
|
} else {
|
||||||
|
// Arrêter la queue si on a trop d'URB en vol (simplification ici: on laisse couler)
|
||||||
|
// netif_stop_queue(netdev);
|
||||||
|
}
|
||||||
|
|
||||||
return NETDEV_TX_OK;
|
return NETDEV_TX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,9 +305,39 @@ static int ch397_probe(struct usb_interface *interface,
|
|||||||
struct usb_endpoint_descriptor *endpoint;
|
struct usb_endpoint_descriptor *endpoint;
|
||||||
u8 mac[ETH_ALEN];
|
u8 mac[ETH_ALEN];
|
||||||
int i;
|
int i;
|
||||||
int retval = -ENOMEM;
|
int retval = 0;
|
||||||
|
struct usb_device *udev = interface_to_usbdev(interface);
|
||||||
|
int config_val = udev->actconfig->desc.bConfigurationValue;
|
||||||
|
int intf_num = interface->cur_altsetting->desc.bInterfaceNumber;
|
||||||
|
|
||||||
dev_info(&interface->dev, "Probing CH397 device\n");
|
dev_info(&interface->dev,
|
||||||
|
|
||||||
|
"Probing CH397 device (config %d, interface %d)\n", config_val,
|
||||||
|
intf_num);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This device exposes 3 USB configurations:
|
||||||
|
* Config 1: Vendor Specific - Interface 0 has bulk endpoints directly
|
||||||
|
* Config 2: CDC Ethernet - Interface 0 = CDC Comm (no bulk)
|
||||||
|
* Interface 1, Alt 1 = CDC Data (bulk endpoints)
|
||||||
|
* Config 3: CDC NCM
|
||||||
|
*
|
||||||
|
* We handle Config 1 and Config 2. In Config 2, we skip Interface 0
|
||||||
|
* (CDC Comm) and only claim Interface 1 (CDC Data) with Alt Setting 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Config 2: Skip Interface 0 (CDC Communications, no bulk endpoints)
|
||||||
|
if (config_val == 2 && intf_num == 0) {
|
||||||
|
dev_info(&interface->dev,
|
||||||
|
"Skipping CDC Comm interface (no bulk endpoints)\n");
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config 3: Not supported for now
|
||||||
|
if (config_val == 3) {
|
||||||
|
dev_info(&interface->dev, "Config 3 (NCM) not supported\n");
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
// Allouer net_device + notre structure
|
// Allouer net_device + notre structure
|
||||||
netdev = alloc_etherdev(sizeof(struct ch397_device));
|
netdev = alloc_etherdev(sizeof(struct ch397_device));
|
||||||
@@ -270,19 +350,23 @@ static int ch397_probe(struct usb_interface *interface,
|
|||||||
dev->netdev = netdev;
|
dev->netdev = netdev;
|
||||||
|
|
||||||
mutex_init(&dev->io_mutex);
|
mutex_init(&dev->io_mutex);
|
||||||
dev->udev = usb_get_dev(interface_to_usbdev(interface));
|
dev->udev = usb_get_dev(udev);
|
||||||
dev->interface = interface;
|
dev->interface = interface;
|
||||||
|
|
||||||
// Sélectionne l'altsetting 1
|
// In Config 2, Interface 1: switch to Alt Setting 1 to get bulk endpoints
|
||||||
retval = usb_set_interface(
|
if (config_val == 2 && intf_num == 1) {
|
||||||
dev->udev, interface->cur_altsetting->desc.bInterfaceNumber, 1);
|
retval = usb_set_interface(udev, intf_num, 1);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
dev_err(&interface->dev, "Cannot set altsetting 1: %d\n",
|
dev_err(&interface->dev,
|
||||||
retval);
|
"Cannot set altsetting 1: %d\n", retval);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
dev_info(&interface->dev,
|
||||||
|
"Switched to altsetting 1 for CDC Data\n");
|
||||||
|
}
|
||||||
|
|
||||||
dev_info(&interface->dev, "Interface obtained\n");
|
dev_info(&interface->dev, "Interface %d obtained (altsetting %d)\n",
|
||||||
|
intf_num, interface->cur_altsetting->desc.bAlternateSetting);
|
||||||
|
|
||||||
for (i = 0; i < interface->cur_altsetting->desc.bNumEndpoints; i++) {
|
for (i = 0; i < interface->cur_altsetting->desc.bNumEndpoints; i++) {
|
||||||
endpoint = &interface->cur_altsetting->endpoint[i].desc;
|
endpoint = &interface->cur_altsetting->endpoint[i].desc;
|
||||||
@@ -318,6 +402,7 @@ static int ch397_probe(struct usb_interface *interface,
|
|||||||
if (!(dev->bulk_in_endpointAddr && dev->bulk_out_endpointAddr)) {
|
if (!(dev->bulk_in_endpointAddr && dev->bulk_out_endpointAddr)) {
|
||||||
dev_err(&interface->dev,
|
dev_err(&interface->dev,
|
||||||
"Could not find both bulk-in and bulk-out endpoints\n");
|
"Could not find both bulk-in and bulk-out endpoints\n");
|
||||||
|
retval = -ENODEV;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,11 +424,12 @@ static int ch397_probe(struct usb_interface *interface,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
netif_carrier_off(netdev);
|
||||||
|
|
||||||
dev_info(&interface->dev, "CH397 attached as %s (MAC: %pM)\n",
|
dev_info(&interface->dev, "CH397 attached as %s (MAC: %pM)\n",
|
||||||
netdev->name, mac);
|
netdev->name, mac);
|
||||||
|
|
||||||
//if (retval)
|
netif_carrier_off(netdev);
|
||||||
// goto error;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user