/******************************************************************************
*
* Driver for Option High Speed Mobile Devices.
*
* Copyright (C) 2008 Option International
* Filip Aben <f.aben@option.com>
* Denis Joseph Barrow <d.barow@option.com>
* Jan Dumon <j.dumon@option.com>
* Copyright (C) 2007 Andrew Bird (Sphere Systems Ltd)
* <ajb@spheresystems.co.uk>
* Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de>
* Copyright (C) 2008 Novell, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA
*
*
*****************************************************************************/
/******************************************************************************
*
* Description of the device:
*
* Interface 0: Contains the IP network interface on the bulk end points.
* The multiplexed serial ports are using the interrupt and
* control endpoints.
* Interrupt contains a bitmap telling which multiplexed
* serialport needs servicing.
*
* Interface 1: Diagnostics port, uses bulk only, do not submit urbs until the
* port is opened, as this have a huge impact on the network port
* throughput.
*
* Interface 2: Standard modem interface - circuit switched interface, this
* can be used to make a standard ppp connection however it
* should not be used in conjunction with the IP network interface
* enabled for USB performance reasons i.e. if using this set
* ideally disable_net=1.
*
*****************************************************************************/
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/netdevice.h>
#include <linux/module.h>
#include <linux/ethtool.h>
#include <linux/usb.h>
#include <linux/timer.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/kmod.h>
#include <linux/rfkill.h>
#include <linux/ip.h>
#include <linux/uaccess.h>
#include <linux/usb/cdc.h>
#include <net/arp.h>
#include <asm/byteorder.h>
#include <linux/serial_core.h>
#include <linux/serial.h>
#define MOD_AUTHOR "Option Wireless"
#define MOD_DESCRIPTION "USB High Speed Option driver"
#define MOD_LICENSE "GPL"
#define HSO_MAX_NET_DEVICES 10
#define HSO__MAX_MTU 2048
#define DEFAULT_MTU 1500
#define DEFAULT_MRU 1500
#define CTRL_URB_RX_SIZE 1024
#define CTRL_URB_TX_SIZE 64
#define BULK_URB_RX_SIZE 4096
#define BULK_URB_TX_SIZE 8192
#define MUX_BULK_RX_BUF_SIZE HSO__MAX_MTU
#define MUX_BULK_TX_BUF_SIZE HSO__MAX_MTU
#define MUX_BULK_RX_BUF_COUNT 4
#define USB_TYPE_OPTION_VENDOR 0x20
/* These definitions are used with the struct hso_net flags element */
/* - use *_bit operations on it. (bit indices not values.) */
#define HSO_NET_RUNNING 0
#define HSO_NET_TX_TIMEOUT (HZ*10)
#define HSO_SERIAL_MAGIC 0x48534f31
/* Number of ttys to handle */
#define HSO_SERIAL_TTY_MINORS 256
#define MAX_RX_URBS 2
/*****************************************************************************/
/* Debugging functions */
/*****************************************************************************/
#define D__(lvl_, fmt, arg...) \
do { \
printk(lvl_ "[%d:%s]: " fmt "\n", \
__LINE__, __func__, ## arg); \
} while (0)
#define D_(lvl, args...) \
do { \
if (lvl & debug) \
D__(KERN_INFO, args); \
} while (0)
#define D1(args...) D_(0x01, ##args)
#define D2(args...) D_(0x02, ##args)
#define D3(args...) D_(0x04, ##args)
#define D4(args...) D_(0x08, ##args)
#define D5(args...) D_(0x10, ##args)
/*****************************************************************************/
/* Enumerators */
/*****************************************************************************/
enum pkt_parse_state {
WAIT_IP,
WAIT_DATA,
WAIT_SYNC
};
/*****************************************************************************/
/* Structs */
/*****************************************************************************/
struct hso_shared_int {
struct usb_endpoint_descriptor *intr_endp;
void *shared_intr_buf;
struct urb *shared_intr_urb;
struct usb_device *usb;
int use_count;
int ref_count;
struct mutex shared_int_lock;
};
struct hso_net {
struct hso_device *parent;
struct net_device *net;
struct rfkill *rfkill;
struct usb_endpoint_descriptor *in_endp;
struct usb_endpoint_descriptor *out_endp;
struct urb *mux_bulk_rx_urb_pool[MUX_BULK_RX_BUF_COUNT];
struct urb *mux_bulk_tx_urb;
void *mux_bulk_rx_buf_pool[MUX_BULK_RX_BUF_COUNT];
void *mux_bulk_tx_buf;
struct sk_buff *skb_rx_buf;
struct sk_buff *skb_tx_buf;
enum pkt_parse_state rx_parse_state;
spinlock_t net_lock;
unsigned short rx_buf_size;
unsigned short rx_buf_missing;
struct iphdr rx_ip_hdr;
unsigned long flags;
};
enum rx_ctrl_state{
RX_IDLE,
RX_SENT,
RX_PENDING
};
#define BM_REQUEST_TYPE (0xa1)
#define B_NOTIFICATION (0x20)
#define W_VALUE (0x0)
#define W_LENGTH (0x2)
#define B_OVERRUN (0x1<<6)
#define B_PARITY (0x1<<5)
#define B_FRAMING (0x1<<4)
#define B_RING_SIGNAL (0x1<<3)
#define B_BREAK (0x1<<2)
#define B_TX_CARRIER (0x1<<1)
#define B_RX_CARRIER (0x1<<0)
struct hso_serial_state_notification {
u8 bmRequestType;
u8 bNotification;
u16 wValue;
u16 wIndex;
u16 wLength;
u16 UART_state_bitmap;
} __packed;
struct hso_tiocmget {
struct mutex mutex;
wait_queue_head_t waitq;
int intr_completed;
struct usb_endpoint_descriptor *endp;
struct urb *urb;
struct hso_serial_state_notification serial_state_notification;
u16 prev_UART_state_bitmap;
struct uart_icount icount;
};
struct hso_serial {
struct hso_device *parent;
int magic;
u8 minor;
struct hso_shared_int *shared_int;
/* rx/tx urb could be either a bulk urb or a control urb depending
on which serial port it is used on. */
struct urb *rx_urb[MAX_RX_URBS];
u8 num_rx_urbs;
u8 *rx_data[MAX_RX_URBS];
u16 rx_data_length; /* should contain allocated length */
struct urb *tx_urb;
u8 *tx_data;
u8 *tx_buffer;
u16 tx_data_length; /* should contain allocated length */
u16 tx_data_count;
u16 tx_buffer_count;
struct usb_ctrlrequest ctrl_req_tx;
struct usb_ctrlrequest ctrl_req_rx;
struct usb_endpoint_descriptor *in_endp;
struct usb_endpoint_descriptor *out_endp;
enum rx_ctrl_state rx_state;
u8 rts_state;
u8 dtr_state;
unsigned tx_urb_used:1;
struct tty_port port;
/* from usb_serial_port */
spinlock_t serial_lock;
int (*write_data) (struct hso_serial *serial);
struct hso_tiocmget *tiocmget;
/* Hacks required to get flow control
* working on the serial receive buffers
* so as not to drop characters on the floor.
*/
int curr_rx_urb_idx;
u8 rx_urb_filled[MAX_RX_URBS];
struct tasklet_struct unthrottle_tasklet;
};
struct hso_device {
union {
struct hso_serial *dev_serial;
struct hso_net *dev_net;
} port_data;
u32 port_spec;
u8 is_active;
u8 usb_gone;
struct work_struct async_get_intf;
struct work_struct async_put_intf;
struct work_struct reset_device;
struct usb_device *usb;
struct usb_interface *interface;
struct device *dev;
struct kref ref;
struct m
hso.rar_The Network
版权申诉
44 浏览量
2022-09-24
06:58:56
上传
评论
收藏 19KB RAR 举报
小贝德罗
- 粉丝: 68
- 资源: 1万+
最新资源
- 探索tecreate:软件开发的未来之星.zip
- 打标机项目C#源码连接扫码
- 基于SSM的房屋租赁系统的设计与实现
- xyctf:从入门到精通的实用指南.zip
- mmqrcode1714153659780.png
- Screenshot_2024-04-27-06-08-58-486_com.baidu.xin.aiqicha.jpg
- 基于Javaweb+Tomcat+MySQL的大学生公寓管理系统+sql文件.zip
- 实训作业基于javaweb的订单管理系统源码+数据库+实训报告.zip
- 多机调度问题贪心算法基于最小堆和贪心算法求解多机调度问题.zip
- 基于同态加密技术的匿名电子投票系统源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈