TCP/IP Protocol STACK - PowerPoint PPT Presentation

1 / 103
About This Presentation
Title:

TCP/IP Protocol STACK

Description:

Title: 1 Author: negi Last modified by: negi Created Date: 2/20/2004 8:05:42 AM Document presentation format: Company – PowerPoint PPT presentation

Number of Views:117
Avg rating:3.0/5.0
Slides: 104
Provided by: negi
Category:

less

Transcript and Presenter's Notes

Title: TCP/IP Protocol STACK


1
12. ???? ???? ????
2
12.1 Network Divice Driver ?? ? ??
  • TCP/IP Protocol STACK

3
12.1 Network Divice Driver ?? ? ??
  • TCP/IP on Linux

4
12.1 Network Divice Driver ?? ? ??
  • Interface with kernel core
  • struct net_devide
  • Kernel?? network device? ??? ???? ???? ??? ???
    data? network device? ?? ????? ? ? ? kernel?
    device? control ?? ?? ??? ??? ???? ??? ??.
  • hard_start_xmit()
  • ?? network device? ???? ??? ?? ??? ?? ???? ???
    ??.
  • Name
  • base_address
  • Interrupt
  • data? ??? ?????? ???? ????? interrupt? ?? ????.
  • Data ?? ??? chip? data? ??? ??? ? ??, data? ???
    ???? ?? interrupt? ?? ????.

5
12.1 Network Divice Driver ?? ? ??
  • Network Device Driver ??? ??

6
12.1 Network Divice Driver ?? ? ??
  • Send Data

7
12.1 Network Divice Driver ?? ? ??
  • Send Data

8
12.1 Network Divice Driver ?? ? ??
  • Receive Data

9
12.1 Network Divice Driver ?? ? ??
  • Receive Data

10
12.2 net_device structure
  • Differ fro character and block driver
  • Interface with protocol stack (not file system)
  • struct net_device is similar to struct
    file_operations

11
12.2 net_device structure
struct net_device struct net_device struct net_device
char nameIFNAMSIZ ????? ??
unsigned long rmem_end ?? ?? ??? ?
unsigned long rmem_start ?? ?? ??? ??
unsigned long mem_end ?? ?? ??? ?
unsigned long mem_start ?? ?? ??? ??
unsigned long base_addr I/O ?? ??
unsigned int irq ??? ???? ??
unsigned char if_port ?? ???? ???? ???? ??
unsigned char dma DMA ??
unsigned long state Device? state,
struct net_device next ?? ???? ???
int (init)(struct net_device dev) ??? ??
struct net_device_stats (get_stats)(struct net_device dev) ????? ????? ?? ??? ??
12
12.2 net_device structure
unsigned long trans_start ??? ?? ??(jiffies ?)
unsigned long last_rx ??? ?? ??(jiffies ?)
unsigned short flags ????? ???
unsigned mtu / interface MTU value /
unsigned short type / interface hardware type /
unsigned short hard_header_len / hardware hdr length /
void priv / pointer to private data /
unsigned char broadcastMAX_ADDR_LEN / hw bcast add /
unsigned char dev_addrMAX_ADDR_LEN / hw address /
unsigned char addr_len / hardware address length /
struct dev_mc_list mc_list / Multicast mac addresses /
int mc_count / Number of installed mcasts /
int watchdog_timeo / watchdog timer ? count ? /
unsigned long tx_queue_len / Max frames per queue allowed /
spinlock_t xmit_lock
int xmit_lock_owner
13
12.2 net_device structure
int (open)(struct net_device dev) device? ???? ? ??? ?? ???
int (stop)(struct net_device dev) device? ????? ? ??? ?? ???
int (hard_start_xmit) (struct sk_buff skb,struct net_device dev) kernel? transit? ???? ???? ?? ???
int (hard_header) (struct sk_buff skb)
int (rebuild_header)(struct sk_buff skb)
void (set_multicast_list)(struct net_device dev) HAVE_MULTICAST
int (set_mac_address)(struct net_device dev, void addr) HAVE_SET_MAC_ADDR
int (do_ioctl)(struct net_device dev, struct ifreq ifr, int cmd) HAVE_PRIVATE_IOCTL
int (set_config)(struct net_device dev, struct ifmap map) HAVE_SET_CONFIG
int (hard_header_cache)(struct neighbour neigh,struct hh_cache hh) HAVE_HEADER_CACHE
void (header_cache_update) (struct hh_cache hh, struct net_device dev, unsigned char haddr)
int (change_mtu)(struct net_device dev, int new_mtu) HAVE_CHANGE_MTU
14
12.2 net_device structure
void (tx_timeout) (struct net_device dev) HAVE_TX_TIMEOUT
int (hard_header_parse)(struct sk_buff skb, unsigned char haddr)
struct module owner
15
12.3 Device Driver source code
kernel/drivers/net/cirrus.c
  • cirrus.c ? ?? ??
  • cirrus_init()
  • module? ??? ??? ?? ???? ??
  • net_device ???? ??? register_netdev() ??? ????.
  • cirrus_cleanup()
  • module? ???? ??? ?? ???? ??
  • release_region(), unregister_netdev() ??
  • cirrus_probe()
  • cirrus_init()?? register_netdev()? ????
    parameter? ???? dev???? init ?? ???? ? ??? ??? ??
    ????.
  • register_netdev() ?? ??? ???? ???? ??
  • net_device? ??? ???? device? ?? ??? ??.

16
12.3 Device Driver source code
kernel/drivers/net/cirrus.c
  • cirrus_start()
  • device ? ??? ? ?? ???? ??? ????? ???? ?? ??? ???
    ????? setting??.
  • cirrus_stop()
  • device ? ???? ? ?? ???? ??? ????? ???? ?? ?????.
  • cirrus_send_start()
  • Application?? data? ??? ???? kernel? tcp/ip
    protocol stack? ip layer?? ???? ??? device? ?????
    ???? data? ????? ??.
  • cirrus_receive()
  • ???? data? ?????? cirrus_interrupt()?? ???? ???
    data? device? ?? ???? kernel ? ?? ? ??.

17
12.3 Device Driver source code
kernel/drivers/net/cirrus.c
  • cirrus_interrupt()
  • ????? ???? 5?? ????? ?? ?????? ????? ??????? ????
    ?? ????? ?????? ???? ??? ??? ??? ??
  • cirrus_start() ???? kernel? request_irq()??? ????
    ???? device? interrupt handler ??? ????.

18
12.3 Device Driver source code
kernel/drivers/net/cirrus.c
19
12.3 Device Driver source code - MACRO
MODULE_AUTHOR ("Abraham van der Merwe
ltabraham_at_2d3d.co.zagt") MODULE_DESCRIPTION
("Cirrus Logic CS8900A driver for Linux
(V0.02)") MODULE_LICENSE ("GPL") MODULE_PARM_DES
C (io,"I/O Base Address") MODULE_PARM
(io,"i") MODULE_PARM_DESC (irq,"IRQ
Number") MODULE_PARM (irq,"i") module_init
(cirrus_init) module_exit (cirrus_cleanup)
20
12.3 Device Driver source code - MACRO
static struct net_device dev static int __init
cirrus_init (void) memset (dev,0,sizeof
(struct net_device)) dev.init
cirrus_probe return (register_netdev (dev))
dev? 0?? ???
Dev? list? ??? ? cirrus_probe() ??
21
12.3 Device Driver source code - MACRO
static void __exit cirrus_cleanup
(void) release_region (dev.base_addr,16) unre
gister_netdev (dev)
22
12.3 Device Driver source code cirrus_probe( )
int __init cirrus_probe (struct net_device
dev) memset (priv,0,sizeof
(cirrus_t)) ether_setup (dev) dev-gtopen
cirrus_start dev-gtstop
cirrus_stop dev-gthard_start_xmit
cirrus_send_start dev-gtget_stats
cirrus_get_stats dev-gtset_multicast_list
cirrus_set_receive_mode dev-gtset_mac_address
cirrus_set_mac_address dev-gttx_timeout
cirrus_transmit_timeout dev-gtwatchdog_timeo
HZ
23
12.3 Device Driver source code cirrus_probe( )
dev-gtdev_addr0 0x00 dev-gtdev_addr1
0x00 dev-gtdev_addr2 0x00 dev-gtdev_addr3
0x00 dev-gtdev_addr4 0x00 dev-gtdev_addr5
0x00 dev-gtif_port IF_PORT_10BASET dev
-gtpriv (void ) priv SET_MODULE_OWNER
(dev) dev-gtbase_addr CIRRUS_DEFAULT_IO dev-gt
irq CIRRUS_DEFAULT_IRQ
24
12.3 Device Driver source code cirrus_probe( )
/ module parameters override everything / if
(io gt 0) dev-gtbase_addr io if (irq gt 0)
dev-gtirq irq ... ... if ((result
check_region (dev-gtbase_addr,16))) printk
(KERN_ERR "s can't get I/O port address\
0xlx\n",dev-gtname,dev-gtbase_addr) return
(result) if(!request_region(dev-gtbase_addr,16
,dev-gtname) ) return EBUSY ... ...
25
12.3 Device Driver source code cirrus_probe( )
if 1 cirrus_write (dev,PP_SelfCTL,RESET) while
((( reset_status cirrus_read(dev,PP_SelfST))
INITD ) 0 ) chip_status
cirrus_read(dev, PP_SelfST ) endif / if an
EEPROM is present, use it's MAC address / ...
... / verify EISA registration number for
Cirrus Logic / ... ... / verify chip version
/ ... ... / setup interrupt number / ...
... / configure MAC address / ... ... return
(0)
26
12.3 Device Driver source code cirrus_start( )
static int cirrus_start (struct net_device
dev) int result / valid ethernet address?
/ if (!is_valid_ether_addr(dev-gtdev_addr))
printk(KERN_ERR "s invalid ethernet MAC
address\n",dev-gtname) return (-EINVAL)
27
12.3 Device Driver source code cirrus_start( )
/ install interrupt handler / if ((result
request_irq (dev- gtirq,cirrus_interrupt,0,dev
-gtname,dev)) lt 0) printk (KERN_ERR "s
could not register interrupt
d\n",dev-gtname,dev-gtirq) return
(result) / enable the ethernet controller
/ cirrus_set (dev,PP_RxCFG,RxOKiE BufferCRC
CRCerroriE RuntiE ExtradataiE) cirrus_set
(dev,PP_RxCTL,RxOKA IndividualA
BroadcastA) cirrus_set (dev,PP_TxCFG,TxOKiE
Out_of_windowiE JabberiE) cirrus_set
(dev,PP_BufCFG,Rdy4TxiE RxMissiE TxUnderruniE
TxColOvfiE MissOvfloiE) cirrus_set
(dev,PP_LineCTL,SerRxON SerTxON) cirrus_set
(dev,PP_BusCTL,EnableRQ)
28
12.3 Device Driver source code cirrus_start( )
ifdef FULL_DUPLEX cirrus_set (dev,PP_TestCTL,FDX
) endif / ifdef FULL_DUPLEX / / start the
queue / netif_start_queue (dev) MOD_INC_USE_C
OUNT return (0)
29
12.3 Device Driver source code cirrus_stop( )
static int cirrus_stop (struct net_device
dev) / disable ethernet controller
/ cirrus_write (dev,PP_BusCTL,0) cirrus_write
(dev,PP_TestCTL,0) cirrus_write
(dev,PP_SelfCTL,0) cirrus_write
(dev,PP_LineCTL,0) cirrus_write
(dev,PP_BufCFG,0) cirrus_write
(dev,PP_TxCFG,0) cirrus_write
(dev,PP_RxCTL,0) cirrus_write (dev,PP_RxCFG,0)
30
12.3 Device Driver source code cirrus_stop( )
/ uninstall interrupt handler / free_irq
(dev-gtirq,dev) / stop the queue
/ netif_stop_queue (dev) MOD_DEC_USE_COUNT
return (0)
31
12.3 Device Driver source code
cirrus_send_start( )
static int cirrus_send_start (struct sk_buff
skb,struct net_device dev) cirrus_t priv
(cirrus_t ) dev-gtpriv u16 status netif_stop_
queue (dev) cirrus_write (dev,PP_TxCMD,TxStart
(After5)) cirrus_write (dev,PP_TxLength,skb-gtlen
)
32
12.3 Device Driver source code
cirrus_send_start( )
status cirrus_read (dev,PP_BusST) if
((status TxBidErr)) printk (KERN_WARNING
"s Invalid frame size d!\n",dev-gtname,skb-
gtlen) priv-gtstats.tx_errors priv-gtstats.tx
_aborted_errors priv-gttxlen 0 return
(1) if (!(status Rdy4TxNOW)) printk
(KERN_WARNING "s Transmit buffer not
free!\n",dev-gtname) priv-gtstats.tx_errors
priv-gttxlen 0 / FIXME store skb and
send it in interrupt handler/ return (1)
33
12.3 Device Driver source code
cirrus_send_start( )
cirrus_frame_write (dev,skb) dev-gttrans_start
jiffies dev_kfree_skb (skb) priv-gttxlen
skb-gtlen return (0)
34
12.3 Device Driver source code cirrus_receive( )
static void cirrus_receive (struct net_device
dev) cirrus_t priv (cirrus_t )
dev-gtpriv struct sk_buff skb u16
status,length status cirrus_read
(dev,PP_RxStatus) length cirrus_read
(dev,PP_RxLength) if (!(status RxOK))
priv-gtstats.rx_errors if ((status
(Runt Extradata))) priv-gtstats.rx_length_err
ors if ((status CRCerror))
priv-gtstats.rx_crc_errors return
35
12.3 Device Driver source code cirrus_receive( )
if ((skb dev_alloc_skb (length 4)) NULL)
priv-gtstats.rx_dropped return skb-gt
dev dev skb_reserve (skb,2) cirrus_frame_re
ad (dev,skb,length)
36
12.3 Device Driver source code cirrus_receive( )
skb-gtprotocol eth_type_trans
(skb,dev) netif_rx (skb) dev-gtlast_rx
jiffies priv-gtstats.rx_packets priv-gtstats.
rx_bytes length
37
12.3 Device Driver source code
cirrus_interrupt( )
static void cirrus_interrupt (int irq,void
id,struct pt_regs regs) struct net_device
dev (struct net_device ) id cirrus_t
priv u16 status if (dev-gtpriv NULL)
printk (KERN_WARNING "s irq d for unknown
device.\n",dev-gtname,irq) return priv
(cirrus_t ) dev-gtpriv
38
12.3 Device Driver source code
cirrus_interrupt( )
while ((status cirrus_read (dev,PP_ISQ)))
switch (RegNum (status)) case
RxEvent cirrus_receive (dev) break
39
12.3 Device Driver source code
cirrus_interrupt( )
case TxEvent priv-gtstats.collisions
ColCount (cirrus_read(dev,PP_TxCOL)) if
(!(RegContent (status) TxOK))
priv-gtstats.tx_errors if
((RegContent (status) Out_of_window))
priv-gtstats.tx_window_errors if
((RegContent (status) Jabber))
priv-gtstats.tx_aborted_errors break
else if (priv-gttxlen) priv-gtstats.tx_pa
ckets priv-gtstats.tx_bytes
priv-gttxlen priv-gttxlen
0 netif_wake_queue (dev) break
40
12.3 Device Driver source code
cirrus_interrupt( )
case BufEvent if ((RegContent (status)
RxMiss)) u16 missed MissCount
(cirrus_read (dev,PP_RxMISS)) priv-gtstats.rx_
errors missed priv-gtstats.rx_missed_errors
missed if ((RegContent (status)
TxUnderrun)) priv-gtstats.tx_errors pr
iv-gtstats.tx_fifo_errors / FIXME if
Rdy4Tx, transmit last sent packet (if any)
/ priv-gttxlen 0 netif_wake_queue
(dev) break
41
12.3 Device Driver source code
cirrus_interrupt( )
case TxCOL priv-gtstats.collisions
ColCount (cirrus_read (dev,PP_TxCOL)) break
case RxMISS status MissCount (cirrus_read
(dev,PP_RxMISS)) priv-gtstats.rx_errors
status priv-gtstats.rx_missed_errors
status break
42
12.4 Network device driver ??
  • Network device driver ?? ??
  • ifconfig? ?? ??
  • eth0? ??? ??? /etc/rc.d/init.d/network start ??

43
12.4 Network device driver ??
  • Network Device Driver ?? test
  • Host? ping? ??? ??? ????? ????.

44
Socket Programing
45
12.4 Socket()
  • TCP/IP ?? ??
  • ?? ? ????? ???? ?? ???? TCP/IP?? ????? ???? ????.
  • ???? ????? ????? ? ? ?? OSI7??? ?? TCP/IP? 4??
    ???? ???? ??.

46
12.4 Socket()
  • TCP/IP ?? ?? ? Transport????? TCP? UDP ?????
    ????.
  • ? ? ????? ???? ??? ??.

47
12.4 Socket()
  • IP??? PORT??
  • IP
  • TCP/IP protocol? ???? ???? ?? ?? ???? ??? ??
  • TCP/IP?? ??? ??? protocol? IP(Internel
    Protocol)??? ?
  • .?? ??? 4byte ??? ??
  • Port ??
  • Host?? ?? ????? ???? ??? ?? ???? ???? ?? ? ??
    ????? ??? ???? ???? ?? port ??
  • 2byte ??? ???? 066535?? ??? ??
  • telnet(23), ftp(21), httpd(80)

48
12.4 Socket()
  • Socket??
  • TCP ???? ???? ?????? ?? ???? ??????? ?? ?? ????
    ?? ????? ?? ??? ? ?? ??? ??.
  • ?? ??? ??? ???? ??? ?? socket??.
  • Socket? ?????? TCP??? ??? ??? ? ??? ???? API??.

49
12.4 Socket()
  • Socket? ?? ????? ?? ??????? ??? ? ????
    ??????Socket? ?? ????? ??? ?? ??? Socket?? ????.
  • AF_UNIX  ??? ??? Socket
  • AF_INET   ??? Socket
  • Socket? TCP? ?????, UDP? ?????? ?? ? ??? ????.
  • SOCK_STREAM  TCP? ??
  • SOCK_DGRAM   UDP? ??

50
12.4 Socket()
  • Socket? ??? TCP/UDP? ???? 4?? ?? ??? ????
  • AF_UNIX, SOCK_STREAM
  • AF_UNIX, SOCK_DGRAM
  • AF_INET, SOCK_STREAM
  • AF_INET, SOCK_DGRAM

51
12.4 Socket()
  • Socket ?? ???(1)
  • socket? ??? ???????? socket? ??? IP??, ???? ??
    ???? ?? ???? ????.
  • ??? ??
  • sin_len ???? ??, ?? ???? ???.
  • sin_family AF_INET
  • sin_port ????
  • sin_addr IP??(???)
  • sin_zero ????(memset/bzero? 0?? ????)

52
12.4 Socket()
  • Socket ?? ???(2)
  • Unix Socket

53
12.4 Socket()
  • Byte Ordering ??(1)
  • ??? ???? ???? ???? 2?? ??? ??.(NBO)
  • Big Endian
  • 0x1234? ??? ?? 0x12, 0x34? ???? ????.
  • Little Endian
  • 0x1234? ??? ?? 0x34, 0x12? ???? ??? ??? ??.
  • TCP/IP??? Big Endian ??? ????. ?? network byte
    order(NBO)?? ??.
  • Host?? ???? byte ??? Host Byte Order(HBO)?? ??.
  • NBO? HBO?? byte ??? ???? ?? ???? ????.

54
12.4 Socket()
  • Byte Ordering ??(2)
  • sockaddr_in ???? ??? ? sin_addr? sin_port? NBO?
    ????. ??? ?? ????? ?? ????? ??? ??? ????. ??
    sin_family? HBO? ????. ?? ??? ????? ??? ??? ????.
    short? 16????? ????? ??? ? ????, long? 32?????
    IP??? ??? ? ????.

55
12.4 Socket()
  • IP ?? ?? ??(1)
  • in_addr ????? IP ??? ???? ??? ???? long???. ???
    '.'?? ???? IP ??? long??? ?????, ?? ?? ????? ????
    ?? ???? ????.

56
12.4 Socket()
  • IP?? ?? ??(2)
  • inet_addr() ??? IP ??? ???? ?? ?? long??? ????.
    inet_ntoa() ??? ?? ??? in_addr ???? ?? ??? ????
    ??.

57
12.4 Socket()
  • Socket Interface ??
  • socket? ???? ???? ?????? ? ? ???? ????? ???? ???
    ??.
  • socket()      ?? ????? ??
  • bind()          ?? ?????? ??? IP??/?????
    ??(bind)
  • listen()  ?????? ?? ?? ??
  • connect()   ?????? ??? ?? ??
  • accept()      ?????? ?? ??
  • recv()           ??? ??
  • send()  ??? ??
  • recvfrom()  ??? ??(????? ??)
  • sendto()      ??? ??(????? ??)
  • close()  ?? ????? ??

58
12.4 Socket()
  • socket()
  • socket() ??? ?? ?????? ???? ????.
  • family   AF_UNIX, AF_INET
  • type    SOCK_STREAM, SOCK_DGRAM
  • protocol 0
  • socket() ??? ??? ???????? ????. ? ???????? ??
    ???? ????.

59
12.4 Socket()
  • bind()(1)
  • bind() ??? socket() ??? ??? ???????? ???
    IP??/????? ?????.
  • s               ???????
  • name      ?? ?? ???
  • namelen     ?? ?? ??? ??

60
12.4 Socket()
  • bind(2)

61
12.4 Socket()
  • listen()(1)
  • ?? ????? ????????? ??? ????? ?? ????
  • s               ???????
  • backlog  ?? ?? ??????(?? 20??)

62
12.4 Socket()
  • listen()(2)
  • listen() ??? ? ?? ??? ???????? ????. ??? ??? ????
    ?? ??? ?????(listening socket)??? ??. listen()
    ??? ??? bind() ??? ??? ?? ????.

63
12.4 Socket()
  • connect()(1)
  • ?????? ??? ??? ???? ????.
  • s               ???????
  • addr         ?? ?? ???(IP??, ????)
  • addrlen  ???? ??

64
12.4 Socket()
  • connect()(2)
  • connect() ??? ??? ???? 0? ????, ???? -1? ????. ??
    ?? ???? ??????. ??? ??? ??? ??? ??(connected
    socket)??? ??. ??? ??? ???? ?? ?? ?? ????.

65
12.4 Socket()
  • accept()(1)
  • ??? ?????? ??? ???? ????.
  • s                ???????
  • addr            ??? ??? ?????? ?? ???
  • addrlen  ??? ??
  • accept() ??? ??? ???? ??? ???????? ????. ??? ??
    -1? ????.

66
12.4 Socket()
  • accept()(2)
  • sockfd? ???????, new_fd? ??? ????. ???? new_fd?
    ??? ???? ?? ???

67
12.4 Socket()
  • send()(1)
  • ??? ???????? ??? ???? ????.
  • s        ???????
  • msg    ??? ???? ??
  • len      ??? ???? ??
  • flags   0
  • send() ??? ??? ??? ???? ?? ????. ??? ???? ???
    ???? ? ??? ???? ????. ??? ???? ?? ???? ???????
    ??. -1? ???? ?? ??? ????? ????.

68
12.4 Socket()
  • send()(2)

69
12.4 Socket()
  • recv()(1)
  • ??? ???????? ??? ??? ???? ????.
  • s        ???????
  • buf      ??? ??? ??
  • len      ??? ??
  • flags 0
  • recv() ??? ??? ??? ???? ?? ????.

70
12.4 Socket()
  • recv()(2)

71
12.4 Socket()
  • sendto()(1)
  • ?????? ??? ???? ???? ????.
  • s   ???????
  • msg    ??? ???? ??
  • len     ??? ???? ??
  • flags 0
  • to      ??? ?? ???
  • tolen   ?? ??? ??
  • ?????? ???? ???? ??? ? sendto() ??? ????. ?????
    ??? ?? connect() ??? ???? ?? ???? ???? ?? ???? 
    sendto() ?? ??? ??? ??? ??? ????.

72
12.4 Socket()
  • sendto()(2)

73
12.4 Socket()
  • recvfrom()(1)
  • ?????? ??? ???????? ??? ??? ???? ????.
  • s         ???????
  • buf      ??? ??? ??
  • len     ??? ??
  • flags   0
  • to      ??? ?? ???
  • tolen   ?? ??? ??

74
12.4 Socket()
  • recvfrom()(2)

75
12.4 Socket()
  • socket programming ??
  • ?? ?????? ???? ???? ??? ?????? ???? ???? ??? ??.
  • ?????(AF_INET)? TCP(SOCK_STREAM)? ???? ???? ?????
    ????. ????? ??? ?????? ?? ???? ??? ?? ????? ???
    ??? ?? ??????? ??? ??? ??? ???? ??.

76
12.4 Socket()
  • server program(1)
  • include ltstdio.hgt
  • include ltsys/types.hgt
  • include ltsys/socket.hgt
  • include ltnetdb.hgt
  • include ltnetinet/in.hgt
  • include lterrno.hgt
  • define PORTNUM 5001
  • main()
  • char buf256
  • struct sockaddr_in sin, cli
  •       int sd, ns, clientlen sizeof(cli)
  •       memset((char )sin, '\0', sizeof(sin))
  •       sin.sin_family AF_INET
  •       sin.sin_port htons(PORTNUM)
  •       sin.sin_addr.s_addr inet_addr("203.230.223
    .235")

77
12.4 Socket()
  • server program(2)
  •       if((sd socket(AF_INET, SOCK_STREAM, 0))
    -1)
  •           perror("socket")
  •           exit(1)
  •      
  •       if(bind(sd, (struct sockaddr )sin,
    sizeof(sin)))
  •           perror("bind")
  •           exit(1)
  •      
  •       if(listen(sd, 5))
  •           perror("listen")
  •           exit(1)
  •      

78
12.4 Socket()
  • server program(3)
  •       while(1)
  •           if((ns accept(sd, (struct sockaddr
    )cli, clientlen)) -1)
  •               perror("accept")
  •               exit(1)
  •    
  •           strcpy(buf, "Server Message")
  •           if(send(ns, buf, strlen(buf) 1, 0)
    -1)
  •               perror("send")
  •               exit(1)
  •          
  •           close(ns)
  •      

79
12.4 Socket()
  • client program(1)
  • include ltstdio.hgt
  • include ltsys/types.hgt
  • include ltsys/socket.hgt
  • include ltnetdb.hgt
  • include ltnetinet/in.hgt
  • include lterrno.hgt
  • define PORTNUM 5001
  • main()
  •       int sd
  •       char buf256
  •       struct sockaddr_in sin
  •       memset((char )sin, '\0', sizeof(sin))
  •       sin.sin_family AF_INET
  •       sin.sin_port htons(PORTNUM)
  •       sin.sin_addr.s_addr inet_addr("203.230.223
    .235")

80
12.4 Socket()
  • client program(2)
  • if((sd socket(AF_INET, SOCK_STREAM, 0))
    -1)
  •           perror("socket")
  •           exit(1)
  •      
  •       if(connect(sd, (struct sockaddr )sin,
    sizeof(sin)))
  •           perror("bind")
  •           exit(1)
  •      
  •       if(recv(sd, buf, sizeof(buf), 0) -1)
  •               perror("recv")
  •               exit(1)
  •      
  •       close(sd)
  •       printf("From Server s\n", buf)

81
12.4 Socket()
  • ???? ??
  • gcc -o ser 12-12s.c -lsocket ln?
  • gcc -o cli 12-12c.c -lsocket -lnsl
  • ser
  • cli

82
PXA255-Pro CS8900
83
12.5 General Description
  • Features
  • Single-Chip IEEE 802.3 Ethernet Controller with
    Direct ISA-Bus Interface
  • Maximum Current Consumption 55mA(5V supply)
  • 3V Operation
  • Industrial Temperature Range Comprehensive Suite
    of Software Drivers Available
  • Efficient PacketPage Architecture Operation in
    I/O and Memory Space, and DMA Full Duplex
    Operation
  • On-Chip RAM Buffers Transmit and Receive Frames
  • 10BASE-T Port with Analog Filters
  • AUI Port for 10BASE2, 10BASE5 and 10BASE-F
  • Programmable Transmit
  • Programmable Receive
  • EEPROM Support for Jumperless Configuration
  • Boot PROM Support Diskless Systems
  • Boundary Scan and Loopback Test
  • LED Drivers for Link Status and LAN Activity
  • Standby and Suspend Sleep Modes

84
12.5 General Description
  • Block Diagram

85
12.5 General Description
  • MAC Interface

1. ??? IEEE 802.3 Ethernet standard ?? 2.
Ethernet Frame ???? ?? ??? ??? 3. Including
collision detection, preamble generation and
detection
86
12.5 General Description
  • Ethernet Frame Format

87
12.5 General Description
  • Data path with pxa255

88
12.5 General Description
  • 16bit I/O ports

CS8900 I/O Mode Mapping
?) static inline u16 cirrus_read(struct
net_device dev, u16 reg) outw(reg,
dev-gtbase_addr PP_Address) return
inw(dev-gtbase_addr PP_Data) Static inline
void cirrus_write(struct net_device dev, u16
reg, u16 value) outw(reg, dev-gtbase_addr
PP_Address) outw(value, dev-gtbase_addr
PP_Data)
offset type Description
0000h R/W RX/TX Data(port 0)
0002h R/W RX/TX Data(port 1)
0004h W TxCMD
0006h W TxLength
0008h R Interrupt Status Queue
000Ah R/W Packet Page Pointer
000Ch R/W Packet Page Data(port0)
000Eh R/W Packet Page Data(port1)
dev-gtbase_addr device I/O address PP_Address
0x000A PP_Data 0x000C
89
12.6 PacketPage(internal registers) Overview
  • Internal Memory (Registers )
  • Bus Interface Registers
  • Status and Control Registers
  • Initiate Transmit Registers
  • Address Filter Registers
  • Receive Transmit Frame Location

90
12.6 PacketPage(internal registers) Overview
  • Bus Interface Registers
  • CS8900A ISA bus ??
  • Map the CS8900A into the host systems I/O and
    Memory space
  • ?? ??? ??? ?? ???? ??? ???.
  • DMA?? ????? ??? DMA? ??? ??? ?? ???
  • CS8900A data sheet ? section 4.3 on page 42 ??

91
12.6 PacketPage(internal registers) Overview
  • Status and Control Registers
  • CS8900A? ?? ?? ??
  • How frames will be transmitted and received.
  • Which frames will be transmitted and received.
  • Which event will cause interrupts to the host
    processor.
  • How the Ethernet physical interface will be
    configured.
  • CS8900A? ?? ?? ??
  • Status of transmitted and received frames.
  • Information about the configuration of the
    CS8900A.
  • CS8900A data sheet ? section 4.4 on page 47 ??

92
12.6 PacketPage(internal registers) Overview
  • Initiate Transmit Registers
  • TxCmd, TxLength registers ??? ??? ? ??
  • CS8900A data sheet Section 4.5 on page 71 ??
  • Address Filter Registers
  • Individual Address ??
  • Logical Address filter ??
  • CS8900A data sheet Section 4.6 on page 72 ??

93
12.6 PacketPage(internal registers) Overview
  • Receive Transmit Frame Location
  • Ethernet frame? ????? ??? ? ??
  • ?? Transmit Frame Location? ??? data? ??
  • ?? Receive Frame Location?? ??? data? ???.
  • CA8900A data sheet Section 4.7 on page 73 ??

94
12.6 PacketPage(internal registers) Overview
  • PacketPage memory map

95
12.6 PacketPage(internal registers) Overview
  • PacketPage memory map

96
12.7 Registers Description
  • Bus Interface

Address ? packet page pointe ? ??? ???.
Address Name Description
0x0000 Product Identification Code Chip ? id? ???? ??. Device Driver?? ??? chip??? ????? chip? ??? ???? ?? ??? ??? ? ??? ???? ? ??? ? ??.
0x0020 I/O Base Address I/O Base Address Register? chip? ???? ?? host? 16 bytes? ??? I/O space? ?? base address? ????. ????? 0x300?? ???? ??.
0x0022 Interrupt Number Interrupt Number Register? interrupt pin? ???? ?? register??. 4?? pin? ?? ?? ?? ?? pin? high impedence? ???.
0x0024 DMA Channel Number DMA Channel Number? ???? ?? register??. 3?? pin? ??? ??? ? ??? DMA? ???? ?? ?? 3?? pin?? ???? ?? ? ? ??.
0x0027 DMA Start of Frame DMA start of frame register? dma? ??? ?? ??? ??? ??.
0x0028 DMA Frame Count ????? ? ????? ?? ??? DMA? ?? ??? ???(valid) frame? ??? ???? ??.
0x002A RxDMA Byte Counter ????? ? ????? ?? ??? DMA? ?? ??? ???(valid) byte? ?? ???? ??.
0x002C Memory Base Address Host? Memory space? mapping? ??? base address
0x0030 Boot PROM Base Address Boot PROM? base address? ??? ??.
97
12.7 Registers Description
  • Bus Interface

Address ? packet page pointer ? ??? ???.
Address Name Description
0x0034 Boot PROM Address Mask Boot PROM? size? ??? ??.
0x0040 EEPROM Command EEPROM? read/write ??? ?? ????.
0x0042 EEPROM Data EEPROM? ????? ?? data? ???.
0x0050 Receive Frame Byte Counter ?? ?? frame? ? byte ?? ???. ?? frame? ? byte? ?? ??? ????? ????.
98
12.6 Registers Description
  • Status and Control Registers

Address Name Description
0x0120 Interrupt Status Queue Host? interrupt? ?? ??? ???? ?? ????? ?? event? ?? interrupt? ????? ?? ? ? ??.
0x0102 Receiver Configuration Frmae? ??? ??? ???, ?? frame type? ???? ? interrupt? ?? ?? ????? ????.
0x0124 Receiver Event ?? ?? frame? ??? ?? ??? ?? ??. crc? ????? Broadcast? ??? frame?? ?
0x0104 Receiver Control ?? type? frame? ?? ?? ???? ?? ??(broadcast, multicast, individual ?)? ??? data? ???? ???? ?? ????.
0x0106 Transmit Configuration Frame? ??? ? ??? ? ?? event? ??? interrupt? ???? ???? ??? ????.
0x0218 Transmit Event ????? ??? ??? event status? ??? ??. ??? ??????? ??? ?????? ?? ??? ?????? ?? ??.
0x0108 Transmit Command Status ??? Transmit Command? ?? ??.
0x010A Buffer Configuration Buffer?? ??? ? ?? event?? ?? interrupt? ???? ???? ??? ????. Received frame? ?? ??, frame? ??? ??? ? ?? ?
0x012C Buffer Event Transmit and receive buffers? ??? ?? ??? ??? ??.
99
12.6 Registers Description
  • Status and Control Registers

Address Name Description
0x0130 Receiver Miss Counter Buffer space? ???? ?? ??? frame?? ?? ???? ??.
0x0132 Transmit Collision Counter Frame ??? collision? ??? ??? 1? ????.
0x0112 Line Control MAC engine? physical interface? ????. Receiver or Transmitter? enable?? ???? ???? ?
0x0134 Line Status Ethernet physical interface? ??? report. AUI ? 10BT? ???? ????? ?? frame? ???? ??? ?
0x0114 Self Control LED? ???, lower-power modes? control. Data? ??? ?? ?? sleep, ???? awake ?? control
0x0136 Self Status EEPROM interface? initialization process? ??? report. EEPROM? ?????, ?? ????? ?
0x0116 Bus Control ISA-bus interface? operation? control. DMA ???, Memory Mode ?? ???? ??
0x0138 Bus Status Bus? frame? ??? ??? ???? ???, host?? CS8900A?? ??? ?? ?? frame(1518 bytes ?? ? frame)? ????? ??? ???
0x0118 Test Control CS8900A ? ??
100
12.6 Registers Description
  • Status and Control Registers

Address Name Description
0x013C AUI Time Domain Reflectometer Cable fault? ???? ??? ??? frame? ??? ? collision?? loss of carrier error? ??? ???? 10 MHz clock periods? ??? ??.
101
12.6 Registers Description
  • Initiate Transmit Registers

Address Name Description
0x0144 Transmit Command Request CS8900A? ?? packet? ??? ????? ???? ????. MAC ?? packet ?? ????? ???? ?? ? ???? CS8900A? ??? ??? ?
0x0146 Transmit Length ??? FRAME? ??? ????.
102
12.6 Registers Description
  • Address Filter Registers

Address Name Description
0x0150 Logical Address Filter (hash table) ??? ??? ?? frame? ?? ????? ?????? ??? ? ????? filter ??? ??.
0x0020 Individual Address (IEEE address) Chip? ?? ??? ??? ??.
103
12.6 Registers Description
  • Receive and Transmit Frame Locations

Address Name Description
0x0400 Receive Status ??? frame? ??? ?? ??? ??? ??. Receive Event register? ??? ?? ??? ???, ????? ?? ?? register? ?? clear?? ???.
0x0402 Receive Length ??? frame? ??? ??? ??. (byte ??)
0x0404 Receive Frame Location ??? frame? ???? ????.
0x0A00 Transmit Frame Location ??? frame? ???? ????.
Write a Comment
User Comments (0)
About PowerShow.com