Compare commits
4 Commits
16119c5725
...
driver_ray
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ca4a10aa4 | ||
|
|
46e2d50a55 | ||
|
|
95889d091c | ||
|
|
32c039da54 |
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
build
|
||||||
|
compile_commands.json
|
||||||
|
.module-commands.o
|
||||||
4
Makefile
4
Makefile
@@ -1,4 +1,4 @@
|
|||||||
MODULE_NAME := ch349_driver
|
MODULE_NAME := ch397_driver
|
||||||
obj-m := $(MODULE_NAME).o
|
obj-m := $(MODULE_NAME).o
|
||||||
|
|
||||||
SRC_DIR := src
|
SRC_DIR := src
|
||||||
@@ -6,7 +6,7 @@ BUILD_DIR := build
|
|||||||
|
|
||||||
KDIR := /lib/modules/$(shell uname -r)/build
|
KDIR := /lib/modules/$(shell uname -r)/build
|
||||||
|
|
||||||
$(MODULE_NAME)-objs := $(SRC_DIR)/ch349_driver.o
|
$(MODULE_NAME)-objs := $(SRC_DIR)/ch397_driver.o
|
||||||
|
|
||||||
ccflags-y := -std=gnu11 -Wno-declaration-after-statement
|
ccflags-y := -std=gnu11 -Wno-declaration-after-statement
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ sudo update-initramfs -u
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
En l'etat (5/2/26) le driver s'installe, s'attache au device ch349 puis creer une interface reseau sur la machine. on peut alors recuperer le nom de l'interface grace a :
|
En l'etat (5/2/26) le driver s'installe, s'attache au device ch397 puis creer une interface reseau sur la machine. on peut alors recuperer le nom de l'interface grace a :
|
||||||
|
|
||||||
```
|
```
|
||||||
ip a
|
ip a
|
||||||
@@ -39,7 +39,7 @@ sudo ip addr add 192.168.1.100/24 dev <nom_interface>
|
|||||||
sudo ip link set <nom_interface> up
|
sudo ip link set <nom_interface> up
|
||||||
```
|
```
|
||||||
|
|
||||||
ce qui nous permet ensuite, depuis une autre machine d'envoyer des pings a l'ip (192.168.1.100) qui sont ensuite parses en hexadecimal et affiches sur l'interface usb (visibles en executant dmesg | grep ch349)
|
ce qui nous permet ensuite, depuis une autre machine d'envoyer des pings a l'ip (192.168.1.100) qui sont ensuite parses en hexadecimal et affiches sur l'interface usb (visibles en executant dmesg | grep ch397)
|
||||||
|
|
||||||
## Todo
|
## Todo
|
||||||
|
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ make -- compile
|
|||||||
make clean -- clean
|
make clean -- clean
|
||||||
make install -- build and load driver
|
make install -- build and load driver
|
||||||
make uninstall -- deload driver
|
make uninstall -- deload driver
|
||||||
make bear -- use bear to generate compile_commands.json to fix lsp errors
|
make bear -- use bear to generate compile_commands.json to fix lsp errors (might need to manually tweak compile_commands.json to suppress some unsupported arguments errors)
|
||||||
|
|||||||
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;
|
||||||
|
}
|
||||||
@@ -12,10 +12,10 @@
|
|||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/usb.h>
|
#include <linux/usb.h>
|
||||||
|
|
||||||
#define CH349_VENDOR_ID 0x1a86
|
#define CH397_VENDOR_ID 0x1a86
|
||||||
#define CH349_PRODUCT_ID 0x5397
|
#define CH397_PRODUCT_ID 0x5397
|
||||||
|
|
||||||
struct ch349_device {
|
struct ch397_device {
|
||||||
struct usb_device *udev;
|
struct usb_device *udev;
|
||||||
struct usb_interface *interface;
|
struct usb_interface *interface;
|
||||||
struct mutex io_mutex;
|
struct mutex io_mutex;
|
||||||
@@ -28,14 +28,15 @@ struct ch349_device {
|
|||||||
struct net_device *netdev;
|
struct net_device *netdev;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct usb_device_id ch349_table[] = {
|
static const struct usb_device_id ch397_table[] = {
|
||||||
{ USB_DEVICE(CH349_VENDOR_ID, CH349_PRODUCT_ID) },
|
|
||||||
|
{ USB_DEVICE(CH397_VENDOR_ID, CH397_PRODUCT_ID) },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
MODULE_DEVICE_TABLE(usb, ch349_table);
|
MODULE_DEVICE_TABLE(usb, ch397_table);
|
||||||
|
|
||||||
// Fonction pour récupérer la MAC
|
// Fonction pour récupérer la MAC
|
||||||
static int ch349_get_mac_address(struct ch349_device *dev, u8 *mac)
|
static int ch397_get_mac_address(struct ch397_device *dev, u8 *mac)
|
||||||
{
|
{
|
||||||
char buf[13];
|
char buf[13];
|
||||||
int ret, i;
|
int ret, i;
|
||||||
@@ -62,7 +63,7 @@ static int ch349_get_mac_address(struct ch349_device *dev, u8 *mac)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ch349_hexdump(const struct device *dev, const char *prefix,
|
static void ch397_hexdump(const struct device *dev, const char *prefix,
|
||||||
const void *data, size_t len)
|
const void *data, size_t len)
|
||||||
{
|
{
|
||||||
const unsigned char *buf = data;
|
const unsigned char *buf = data;
|
||||||
@@ -93,9 +94,9 @@ static void ch349_hexdump(const struct device *dev, const char *prefix,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ch349_read_callback(struct urb *urb)
|
static void ch397_read_callback(struct urb *urb)
|
||||||
{
|
{
|
||||||
struct ch349_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;
|
||||||
|
|
||||||
@@ -105,9 +106,9 @@ static void ch349_read_callback(struct urb *urb)
|
|||||||
case 0: // Success!
|
case 0: // Success!
|
||||||
if (urb->actual_length > 0) {
|
if (urb->actual_length > 0) {
|
||||||
dev_info(&dev->interface->dev,
|
dev_info(&dev->interface->dev,
|
||||||
"ch349: Received %d bytes\n",
|
"ch397: Received %d bytes\n",
|
||||||
urb->actual_length);
|
urb->actual_length);
|
||||||
ch349_hexdump(&dev->interface->dev, "RX",
|
ch397_hexdump(&dev->interface->dev, "RX",
|
||||||
urb->transfer_buffer, urb->actual_length);
|
urb->transfer_buffer, urb->actual_length);
|
||||||
|
|
||||||
// Créer un sk_buff et passer au network stack
|
// Créer un sk_buff et passer au network stack
|
||||||
@@ -126,10 +127,10 @@ static void ch349_read_callback(struct urb *urb)
|
|||||||
netdev->stats.rx_bytes += urb->actual_length;
|
netdev->stats.rx_bytes += urb->actual_length;
|
||||||
|
|
||||||
printk(KERN_INFO
|
printk(KERN_INFO
|
||||||
"ch349: Packet passed to network stack\n");
|
"ch397: Packet passed to network stack\n");
|
||||||
} else {
|
} else {
|
||||||
netdev->stats.rx_dropped++;
|
netdev->stats.rx_dropped++;
|
||||||
printk(KERN_ERR "ch349: Cannot allocate skb\n");
|
printk(KERN_ERR "ch397: Cannot allocate skb\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -155,7 +156,7 @@ static void ch349_read_callback(struct urb *urb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fonction pour démarrer la lecture
|
// Fonction pour démarrer la lecture
|
||||||
static int ch349_start_rx(struct ch349_device *dev)
|
static int ch397_start_rx(struct ch397_device *dev)
|
||||||
{
|
{
|
||||||
struct urb *urb;
|
struct urb *urb;
|
||||||
int retval;
|
int retval;
|
||||||
@@ -173,7 +174,7 @@ static int ch349_start_rx(struct ch349_device *dev)
|
|||||||
usb_fill_bulk_urb(urb, dev->udev,
|
usb_fill_bulk_urb(urb, dev->udev,
|
||||||
usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr),
|
usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr),
|
||||||
dev->bulk_in_buffer, dev->bulk_in_size,
|
dev->bulk_in_buffer, dev->bulk_in_size,
|
||||||
ch349_read_callback, dev);
|
ch397_read_callback, dev);
|
||||||
|
|
||||||
// Sauvegarder l'URB dans la structure
|
// Sauvegarder l'URB dans la structure
|
||||||
dev->rx_urb = urb;
|
dev->rx_urb = urb;
|
||||||
@@ -193,7 +194,7 @@ static int ch349_start_rx(struct ch349_device *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fonction pour arrêter la lecture
|
// Fonction pour arrêter la lecture
|
||||||
static void ch349_stop_rx(struct ch349_device *dev)
|
static void ch397_stop_rx(struct ch397_device *dev)
|
||||||
{
|
{
|
||||||
if (dev->rx_urb) {
|
if (dev->rx_urb) {
|
||||||
usb_kill_urb(dev->rx_urb);
|
usb_kill_urb(dev->rx_urb);
|
||||||
@@ -202,14 +203,14 @@ static void ch349_stop_rx(struct ch349_device *dev)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ch349_net_open(struct net_device *netdev)
|
static int ch397_net_open(struct net_device *netdev)
|
||||||
{
|
{
|
||||||
struct ch349_device *dev = netdev_priv(netdev);
|
struct ch397_device *dev = netdev_priv(netdev);
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
printk(KERN_INFO "ch349: Interface UP\n");
|
printk(KERN_INFO "ch397: Interface UP\n");
|
||||||
|
|
||||||
retval = ch349_start_rx(dev);
|
retval = ch397_start_rx(dev);
|
||||||
if (retval)
|
if (retval)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
@@ -218,20 +219,22 @@ static int ch349_net_open(struct net_device *netdev)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ch349_net_stop(struct net_device *netdev)
|
static int ch397_net_stop(struct net_device *netdev)
|
||||||
{
|
{
|
||||||
struct ch349_device *dev = netdev_priv(netdev);
|
struct ch397_device *dev = netdev_priv(netdev);
|
||||||
|
|
||||||
printk(KERN_INFO "ch349: Interface DOWN\n");
|
printk(KERN_INFO "ch397: Interface DOWN\n");
|
||||||
|
|
||||||
netif_stop_queue(netdev);
|
netif_stop_queue(netdev);
|
||||||
netif_carrier_off(netdev);
|
netif_carrier_off(netdev);
|
||||||
ch349_stop_rx(dev);
|
ch397_stop_rx(dev);
|
||||||
|
|
||||||
|
netif_carrier_off(netdev);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ch349_write_callback(struct urb *urb)
|
static void ch397_write_callback(struct urb *urb)
|
||||||
{
|
{
|
||||||
struct sk_buff *skb = urb->context;
|
struct sk_buff *skb = urb->context;
|
||||||
struct net_device *netdev = skb->dev;
|
struct net_device *netdev = skb->dev;
|
||||||
@@ -249,10 +252,10 @@ static void ch349_write_callback(struct urb *urb)
|
|||||||
usb_free_urb(urb);
|
usb_free_urb(urb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static netdev_tx_t ch349_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)
|
||||||
{
|
{
|
||||||
struct ch349_device *dev = netdev_priv(netdev);
|
struct ch397_device *dev = netdev_priv(netdev);
|
||||||
struct urb *urb;
|
struct urb *urb;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
@@ -266,14 +269,15 @@ static netdev_tx_t ch349_start_xmit(struct sk_buff *skb,
|
|||||||
|
|
||||||
// Préparer l'URB (Bulk OUT)
|
// Préparer l'URB (Bulk OUT)
|
||||||
usb_fill_bulk_urb(urb, dev->udev,
|
usb_fill_bulk_urb(urb, dev->udev,
|
||||||
usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),
|
usb_sndbulkpipe(dev->udev,
|
||||||
skb->data, skb->len,
|
dev->bulk_out_endpointAddr),
|
||||||
ch349_write_callback, skb);
|
skb->data, skb->len, ch397_write_callback, skb);
|
||||||
|
|
||||||
// Soumettre l'URB
|
// Soumettre l'URB
|
||||||
retval = usb_submit_urb(urb, GFP_ATOMIC);
|
retval = usb_submit_urb(urb, GFP_ATOMIC);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
dev_err(&dev->interface->dev, "Failed to submit TX URB: %d\n", retval);
|
dev_err(&dev->interface->dev, "Failed to submit TX URB: %d\n",
|
||||||
|
retval);
|
||||||
usb_free_urb(urb);
|
usb_free_urb(urb);
|
||||||
dev_kfree_skb(skb);
|
dev_kfree_skb(skb);
|
||||||
netdev->stats.tx_errors++;
|
netdev->stats.tx_errors++;
|
||||||
@@ -285,19 +289,18 @@ static netdev_tx_t ch349_start_xmit(struct sk_buff *skb,
|
|||||||
return NETDEV_TX_OK;
|
return NETDEV_TX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct net_device_ops ch349_netdev_ops = {
|
static const struct net_device_ops ch397_netdev_ops = {
|
||||||
.ndo_open = ch349_net_open,
|
.ndo_open = ch397_net_open,
|
||||||
.ndo_stop = ch349_net_stop,
|
.ndo_stop = ch397_net_stop,
|
||||||
.ndo_start_xmit = ch349_start_xmit,
|
.ndo_start_xmit = ch397_start_xmit,
|
||||||
.ndo_validate_addr = eth_validate_addr,
|
.ndo_validate_addr = eth_validate_addr,
|
||||||
.ndo_set_mac_address = eth_mac_addr,
|
.ndo_set_mac_address = eth_mac_addr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int ch397_probe(struct usb_interface *interface,
|
||||||
static int ch349_probe(struct usb_interface *interface,
|
|
||||||
const struct usb_device_id *id)
|
const struct usb_device_id *id)
|
||||||
{
|
{
|
||||||
struct ch349_device *dev;
|
struct ch397_device *dev;
|
||||||
struct net_device *netdev;
|
struct net_device *netdev;
|
||||||
struct usb_endpoint_descriptor *endpoint;
|
struct usb_endpoint_descriptor *endpoint;
|
||||||
u8 mac[ETH_ALEN];
|
u8 mac[ETH_ALEN];
|
||||||
@@ -307,10 +310,10 @@ static int ch349_probe(struct usb_interface *interface,
|
|||||||
int config_val = udev->actconfig->desc.bConfigurationValue;
|
int config_val = udev->actconfig->desc.bConfigurationValue;
|
||||||
int intf_num = interface->cur_altsetting->desc.bInterfaceNumber;
|
int intf_num = interface->cur_altsetting->desc.bInterfaceNumber;
|
||||||
|
|
||||||
|
|
||||||
dev_info(&interface->dev,
|
dev_info(&interface->dev,
|
||||||
"Probing CH349 device (config %d, interface %d)\n",
|
|
||||||
config_val, intf_num);
|
"Probing CH397 device (config %d, interface %d)\n", config_val,
|
||||||
|
intf_num);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This device exposes 3 USB configurations:
|
* This device exposes 3 USB configurations:
|
||||||
@@ -337,7 +340,7 @@ static int ch349_probe(struct usb_interface *interface,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allouer net_device + notre structure
|
// Allouer net_device + notre structure
|
||||||
netdev = alloc_etherdev(sizeof(struct ch349_device));
|
netdev = alloc_etherdev(sizeof(struct ch397_device));
|
||||||
if (!netdev) {
|
if (!netdev) {
|
||||||
dev_err(&interface->dev, "Cannot allocate netdev\n");
|
dev_err(&interface->dev, "Cannot allocate netdev\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@@ -363,9 +366,7 @@ static int ch349_probe(struct usb_interface *interface,
|
|||||||
}
|
}
|
||||||
|
|
||||||
dev_info(&interface->dev, "Interface %d obtained (altsetting %d)\n",
|
dev_info(&interface->dev, "Interface %d obtained (altsetting %d)\n",
|
||||||
intf_num,
|
intf_num, interface->cur_altsetting->desc.bAlternateSetting);
|
||||||
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;
|
||||||
@@ -406,11 +407,11 @@ static int ch349_probe(struct usb_interface *interface,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Récupère la MAC
|
// Récupère la MAC
|
||||||
ch349_get_mac_address(dev, mac);
|
ch397_get_mac_address(dev, mac);
|
||||||
eth_hw_addr_set(netdev, mac);
|
eth_hw_addr_set(netdev, mac);
|
||||||
|
|
||||||
// Configure net_device
|
// Configure net_device
|
||||||
netdev->netdev_ops = &ch349_netdev_ops;
|
netdev->netdev_ops = &ch397_netdev_ops;
|
||||||
netdev->watchdog_timeo = 5 * HZ;
|
netdev->watchdog_timeo = 5 * HZ;
|
||||||
|
|
||||||
usb_set_intfdata(interface, dev);
|
usb_set_intfdata(interface, dev);
|
||||||
@@ -425,12 +426,10 @@ static int ch349_probe(struct usb_interface *interface,
|
|||||||
|
|
||||||
netif_carrier_off(netdev);
|
netif_carrier_off(netdev);
|
||||||
|
|
||||||
dev_info(&interface->dev, "CH349 attached as %s (MAC: %pM)\n",
|
dev_info(&interface->dev, "CH397 attached as %s (MAC: %pM)\n",
|
||||||
netdev->name, mac);
|
netdev->name, mac);
|
||||||
|
|
||||||
//retval = ch349_start_rx(dev);
|
netif_carrier_off(netdev);
|
||||||
//if (retval)
|
|
||||||
// goto error;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -444,9 +443,9 @@ error:
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ch349_disconnect(struct usb_interface *interface)
|
static void ch397_disconnect(struct usb_interface *interface)
|
||||||
{
|
{
|
||||||
struct ch349_device *dev;
|
struct ch397_device *dev;
|
||||||
struct net_device *netdev;
|
struct net_device *netdev;
|
||||||
|
|
||||||
dev = usb_get_intfdata(interface);
|
dev = usb_get_intfdata(interface);
|
||||||
@@ -457,18 +456,18 @@ static void ch349_disconnect(struct usb_interface *interface)
|
|||||||
usb_set_intfdata(interface, NULL);
|
usb_set_intfdata(interface, NULL);
|
||||||
|
|
||||||
unregister_netdev(netdev);
|
unregister_netdev(netdev);
|
||||||
ch349_stop_rx(dev);
|
ch397_stop_rx(dev);
|
||||||
|
|
||||||
kfree(dev->bulk_in_buffer);
|
kfree(dev->bulk_in_buffer);
|
||||||
usb_put_dev(dev->udev);
|
usb_put_dev(dev->udev);
|
||||||
free_netdev(netdev);
|
free_netdev(netdev);
|
||||||
|
|
||||||
dev_info(&interface->dev, "CH349 device now disconnected\n");
|
dev_info(&interface->dev, "CH397 device now disconnected\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ch349_suspend(struct usb_interface *intf, pm_message_t message)
|
static int ch397_suspend(struct usb_interface *intf, pm_message_t message)
|
||||||
{
|
{
|
||||||
struct ch349_device *dev = usb_get_intfdata(intf);
|
struct ch397_device *dev = usb_get_intfdata(intf);
|
||||||
|
|
||||||
if (!dev)
|
if (!dev)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -479,9 +478,9 @@ static int ch349_suspend(struct usb_interface *intf, pm_message_t message)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ch349_resume(struct usb_interface *intf)
|
static int ch397_resume(struct usb_interface *intf)
|
||||||
{
|
{
|
||||||
struct ch349_device *dev = usb_get_intfdata(intf);
|
struct ch397_device *dev = usb_get_intfdata(intf);
|
||||||
|
|
||||||
if (!dev)
|
if (!dev)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -489,18 +488,18 @@ static int ch349_resume(struct usb_interface *intf)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct usb_driver ch349_driver = {
|
static struct usb_driver ch397_driver = {
|
||||||
.name = "ch349",
|
.name = "ch397",
|
||||||
.probe = ch349_probe,
|
.probe = ch397_probe,
|
||||||
.disconnect = ch349_disconnect,
|
.disconnect = ch397_disconnect,
|
||||||
.suspend = ch349_suspend,
|
.suspend = ch397_suspend,
|
||||||
.resume = ch349_resume,
|
.resume = ch397_resume,
|
||||||
.id_table = ch349_table,
|
.id_table = ch397_table,
|
||||||
.supports_autosuspend = 1,
|
.supports_autosuspend = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
module_usb_driver(ch349_driver);
|
module_usb_driver(ch397_driver);
|
||||||
|
|
||||||
MODULE_AUTHOR("bob industries");
|
MODULE_AUTHOR("bob industries");
|
||||||
MODULE_DESCRIPTION("Driver USB pour CH349A");
|
MODULE_DESCRIPTION("Driver USB pour CH397A");
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
Reference in New Issue
Block a user