WINDOW network port driver programming

zhaozj2021-02-16  101

Keyword RTL8139; network card; driver; contracting process;

Text 1, preface RTL8139 may be the most popular network card, it is cheap, and it can also be accepted. Although the EEPRO 100 that is sometimes slightly interested in efficiency, because the price is too cheap, a little problem on the chip is usually ignored. 8139 Although the price is not high, the function is not lacking. It built TRANCEIVER in accordance with the MII specification, which automatically determines the connection network is the type. It can also use DMA to store packets received on the network directly on the cache area of ​​the main memory. Similarly, the packet to be transmitted can also be transmitted to the NIC. So although only 2K receiving buffers and 2K transmit buffers on the 8139 chip are still very good. In addition to Realtek itself, there are many manufacturers to produce and 8139 compatible network chips, including SMC 1211, MPX 5030, Delta 8139, ADDTRON 8139, and DFE 538 may have more. So, master the drive programming technology of the RTL8139 network card is important, which is also a good foundation for writing other network cards. At present, the RTL8139 network card has public code under Linux, but there is no in Windows, after all, Microsoft is not happy to do this kind. The following will be discussed is the most important two parts of the source code that I compile and actually use in the Windows2000 environment. Second, the network card is also called "network adapter", and the "Network Interface Card" is called "NIC", and the network card is one of the most basic components in the LAN. It is the hardware that connects to the computer and the network. equipment. Whether it is twisted pair connection, coaxial cable connection or fiber connection, you must use the network card to implement data communication. The main working principle of the NIC is to organize data on the computer to the network, and decompose the data into a packet of the appropriate size to send out on the network. When a computer is ready to send data on the network, his network card starts working. First, the network card's chip is listened to whether there is data on the network. If not, he will send the data to the network, after sending it, The data returned, the data, the test, and the transmitted data are consistent. For full duo network cards, the computer's network card chip will receive the packet at the same time. After receiving a complete packet, a pin of the chip notifies the interrupt controller, the interrupt controller will issue an interrupt to the CPU, thereby, CPU The interrupt routine of the network card is called. Thus the process of completing the transceiver package. Each NDIS_PACKET package represents a packet that can be sent by the NIC. That is, this package is completely encapsulated by the upper layer, and it can be sent to a MAC header (Of course this MAC head is automatically added when the network card is sent). NDIS_PACKET The data to be sent is composed of NDIS_Buffer of a linked table structure. The reason why it is necessary to encapsulate because every time a layer of agreement, the protocol of the layer must add his own information in the header of the data. It uses the chain table structure, just need to add your own information in the original list. If you don't need to copy any data, you can pass the bag to the next layer driver, save time and space. 2.1 Process of the package: To copy the transmitted data into a physical continuous buffer, then pass the physical address of the buffer to the network card, start the network card transmission, the NIC will send the data in the DMA mode. After the transmission is successful, an interrupt is given, indicating that the send is complete.

Details: 1. After obtaining a NDIS_PACKET Packet package, use NdisQueryPacket (Packet, & PhysicalBufferCount, & Buffercount, & PfirstBuffer, & TotalPacketLength); get the length of the data to be sent throughout the package is TOTALPACKETLENGTH. The resulting return value can be used to assign a physical consecutive buffer. 2.) Copy the data to the physical continuous buffer that is just allocated. Recycling NdisQueryBufferSafe (pCurrBuff, & pVirtualAddress, & Length, NormalPagePriority); obtaining NDIS_PACKET Packet package list structure in the linear address of each NDIS_BUFFER pCurrBuff of (linear address), and then use these linear addresses, NdisMoveMemory ((PVOID) ((ULONG) physically continuous Buffer, (PVOID) PVIRTUALADDRESS, (ULONG) LENGTH); copy the package into the transmitted buffer. 3.) After the physical continuous buffer has a complete package, start the network card DMA transmission, start transmitting. 2.2 After the network card accepts the data, the network card generates an interrupt, in this interrupt DPC, call ndismindicateRecePacket (prtladapter-> miniportadapterHandle, Revpacket, Numofpkt); telling the system that received Numofpkt packets, Revpacket is receiving Array of packages. 1.) When the network card driver is initialized, you need to allocate a Ring Buffer. This Ring Buffer is used to accept data to the NIC. Since the DMA transmission of the NIC is transmitted, the Ring Buffer must be a physical continuous memory. Ring Buffer As the name, it is a cyclic buffer. When the end of the buffer is used, it is recycled from the Buffer's start cycle. The accepted data package is just in this annular buffer. 2.) When receiving a good packet (that is, Ring Buffer contains a intact packet), the network card issues an interrupt, indicating that there is a packet to come. Then, all processing is done in the DPC. Each received package contains the following information header additional information header: typedef struct tagpacketheader {ushort Rok: 1; // Accept a good packet. USHORT FAE: 1; // Frame alignment error. Ushort CRC: 1; // CRC check error. Ushort long: 1; // A package of more than 4kbytes. Ushort Runt: 1; // A package that is less than 64bytes. Ushort ISE: 1; Ushort Reserved: 7; Ushort Bar: 1; // Receive a broadcast package. USHORT PAM: 1; // Received the package sent to you. Ushort Mar: 1; // Receive a multicast package.

转载请注明原文地址:https://www.9cbs.com/read-10611.html

New Post(0)