lwip»ñÈ¡ipµØַ˵Ã÷
lwip¶¨ÒåLwip£¬light weight IP£»ÊÇÓÉAdam Dunkels ¿ª·¢µÄÒ»¸öСÐÍ¿ªÔ´µÄ
TCP/IPÐÒéÕ»£»Ä¿Ç°ÒѾΪȫÇò¹²Í¬¿ª·¢µÄ¿ªÔ´ÐÒ飻֧³ÖTCPIPÐÒé×åµÄºËÐÄÐÒ飻°üÀ¨£ºARP/ICMP/TCP/UDP/IPV4/IPV6/DHCPµÈ£»ÆäºËÐÄÌصãÊÇ£º¹¦ÄÜÆëÈ«¡¢ÔËÐÐÐèÇóµÄRAMºÍROMÉÙ£»
±à³ÌÄ£ÐÍËùÓеŦÄܺÍÐÔÄܶ¼¿É½øÐвüôºÍÅäÖã»Ïà¹ØÎļþΪ£ºlwipopts.h
ÄÚ²¿ÊµÏÖÖ§³Ö´ø²Ù×÷ϵͳºÍ²»´ø²Ù×÷ϵͳ£»ºËÐÄ¿ò¼ÜÊÇ£ºÍⲿµ¥Ïß³ÌÇý¶¯ÐÒéջ״̬»ú£»µ×²ãʹÓÃÖжϽøÐÐÊý¾ÝµÄ½ÓÊÕ£»
ÆäÌṩÈýÖÖAPI £º1£©RAW API 2£©lwip API 3£©BSD API¡£ÆäÖÐBSD API¾ÍÊÇ´ó¼Ò×îÊìϤµÄsocket APIÁË¡£LinuxºÍWindowsƽ̨ÖеÄsocket½Ó¿Ú¶¼Óë´Ë´óͬСÒ죻 ÒÆÖ²½«lwipÒÆÖ²µ½²»Í¬µÄƽ̨Ö÷Òª°üÀ¨Á½¸ö²¿·Ö¹¤×÷£º 1.MAC+PHY²ãÒÆÖ²£¬°üÀ¨³õʼ»¯¡¢Êý¾ÝµÄÊÕ·¢£»
2.Ó¦Óòã¿ò¼ÜÒÆÖ²£¬Èç²Ù×÷ϵͳ²ãµÄÏ̴߳´½¨¡¢¶¨Ê±Æ÷¡¢ÏûÏ¢ÓÊÏ䣻 ƽ̨Ӳ¼þ£ºSTM32F107 PHYоƬ£ºDM9161AEP Èí¼þ£ºUCOS-ii
ÒÆÖ²ºËÐĵãST¹«Ë¾Õë¶ÔSTM32F107 ²»´ø²Ù×÷ϵͳ°æ±¾µÄLWIPÒÆÖ²°æ±¾£¬ÎļþÃûΪSTM32F107_ETH_LwIP£¬°æ±¾ÎªV1.0.0£»ÓÉÓÚÆä°æ±¾²»ÔÙ¸üÐÂÇÒÓë±¾Èí¼þƽ̨²»Ò»Ö£¬ËùÒÔ²»×ö²Î¿¼£»
ÓÉÓÚSTM32F1 STM32F2 STM32F4µÄÒÔÌ«ÍøÇý¶¯¶¼ÊÇÒ»Öµġ£ËùÒÔµ½ST¹ÙÍøÏÂÔØstm32cubdf2¡£ÆäÖÐÓÐLWIPÕë¶ÔFREERTOSµÄÒÆÖ²£»¶øFREERTOSÓëUCOS´óͬСÒ죻ËùÒÔÖ»ÒªÕë¶ÔÆäÐÞ¸ÄÓ¦Óòã¿ò¼ÜÒÆÖ²µÄʵÏÖ¼´¿É£»Ïà¹Ø´úÂëλÓÚ£ºstm32cubef2\\STM32Cube_FW_F2_V1.1.0\\Projects\\STM322xG_EVAL\\ApplicaTIons\\LwIP\\LwIP_UDPTCP_Echo_Server_Netconn_RTOS£»
LWIPµÄ´úÂëʹÓÃ1.4.1°æ±¾£¬¿Éµ½LWIP¹ÙÍøÉÏÏÂÔØ£»Ò²°üº¬ÔÚstm32cubef2ÖУ» ÒÆÖ²µÄÀíÂÛ»ù´¡À´Ô´ÓÚlwip 1.4.1Ô´Âë°üÖÐdocÎļþ¼ÐÖеÄÎļþ£»Í¬Ê±¹Ù·½Ò²ÓÐÒÆÖ²µ½¸÷
¸öƽ̨ÖеÄʾÀý£¬ÎļþΪ£ºcontrib-1.4.1.zip£¬µ½¹ÙÍøÉÏÏÂÔؼ´¿É£» 1.MAC+PHYÒÆÖ²£º ÐèÒªÐ޸ĵÄÎļþΪ£º app_ethernet.c/h etherneTIf.c/h
ͬʱÐèÒª½«stm32cubef2Çý¶¯¿âÖеÄstm32f2xx_hal_eth.c/h¿½±´¹ýÀ´£» ÒÔÉÏÎļþÖ»ÐèÒªÅäÖú㬱£Ö¤±àÒëûÎÊÌ⣬ÔòMAC+PHY²ãÒÆÖ²Íê³É£» 2.Ó¦Óòã¿ò¼ÜÒÆÖ²£º ÐÞ
¸Ä
1
¸ö
ÎÄ
¼þ
sys_arch.c
£¬
λ
ÓÚ
stm32cubef2\\STM32Cube_FW_F2_V1.1.0\\Middlewares\\Third_Party\\LwIP\\system£» ËùÓеÄÒÆÖ²¼´Íê³É£»
ʵÏÖlwipµÄDHCP×Ô¶¯»ñÈ¡ipµØÖ·LM3SϵÁÐÒÆÖ²lwip×Ô¶¯»ñÈ¡ipµÄ¹¦ÄÜ£ºÊµÏÖ¹ý³ÌÊÇ£º1£©ÔÚopt.hÉÏʹÄÜ#define LWIP_ARP 1ºÍ#define LWIP_DHCP 1£»2£©ÔÚlwipopts.hÉÏʹÄÜ#define LWIP_DHCP 1 ºÍ #define DHCP_DOES_ARP_CHECK 1£»3£©ÔÚlwiplib.cÉÏÔö¼Ó#include lwip/dhcp.h£»4£©×îºóÔÚlwiplib.cÉÏÐÞ¸ÄstaTIc unsigned long g_ulIPMode = IPADDR_USE_DHCPºÍInitNicº¯ÊýÖÐµÄ lwIPInit£¨MACAddress£¬xIpAddr£¬ xNetMask£¬ xGateway£¬IPADDR_USE_DHCP£©£»¡£
µ÷ÊÔ¹ý³Ì£º Ò»¿ªÊ¼ÓÃÍøÂçÊý¾Ý°ü·ÖÎöÈí¼þ¿´£¬·¢ÏÖÿ¸ô¼¸ÃëʵÑé°å»á·¢DHCP¹ã²¥¸ø255.255.255.255£¬ÎÒ²»ÖªµÀ³öÏÖʲôÎÊÌ⣬ºóÀ´¿´DHCPÔÀí²ÅÖªµÀ£¬Â·ÓÉÆ÷û»ØÓ¦Êý¾Ý°ü£¬¾Í¾õµÃ·ÓÉÆ÷²»ÄÜ×Ô¶¯·ÖÅäip¡£ÎÒ³¢ÊÔÓÃpc»ú¸Ä³É×Ô¶¯»ñÈ¡ip£¬ÔÀ´ÕæµÄ²»³É¹¦¡£ºóÀ´·¢ÏÖ֮ǰÐ޸ķÓÉÆ÷ʹÄÜDHCP¹¦ÄܺóûÖØÆô·ÓÉ¡£ÖØÆôºó£¬ÊµÑé°åÒ²ÊÇÏÈÓÃDHCP¹ã²¥£¬½Ó×Å·ÓÉÆ÷»ØÓ¦Ò»¸öARPÊý¾Ý°ü¸øʵÑé°å£¬Êý¾Ý°üÀïÓиøʵÑé°å·ÖÅäµÄipµØÖ·¡£½Ó×ÅʵÑé°å·¢³ö3´ÎÇëÎÊÓÐËÊÇ»áÕ¼ÓÃ×Ô¼º½«Òª»ñµÃµÄip£¬±ÜÃâipµØÖ·Öظ´¡£Ö®ºóʲôÊý¾Ý¶¼Ã»£¬ÎÒ»¹ÒÔΪû³É¹¦»ñµÃipÄØ£¬ÒòΪÔÚ·ÓÉÆ÷ÉÏ¿´²»¼ûʵÑé°åÒѾÁ¬ÉÏ£¬ºó»¹ÎÒÓÃping£¬¾ÓÈ»ÊÇͨµÄ£¬¹Ø±ÕʵÑé°å¾Íping²»Í¨£¬ËµÃ÷ÒѾ»ñµÃipµØÖ·ÁË£¬Ö»ÊDz»Ã÷°×ÔÚ
·ÓÉÆ÷ÉÏΪʲô²»ÏÔʾÁ¬½Ó³É¹¦¡£
DHCP¹¤×÷ÔÀí£º¸ù¾Ý¿Í»§¶ËÊÇ·ñµÚÒ»´ÎµÇ¼ÍøÂ磬DHCP µÄ¹¤×÷ÐÎʽ»áÓÐËù²»Í¬¡£ µÚÒ»´ÎµÇ¼µÄʱºò£º Ñ°ÕÒ Server
µ± DHCP ¿Í»§¶ËµÚÒ»´ÎµÇ¼ÍøÂçµÄʱºò£¬Ò²¾ÍÊÇ¿Í»§·¢ÏÖ±¾»úÉÏûÓÐÈκΠIP Êý¾ÝÉ趨£¬Ëü»áÏòÍøÂç·¢³öÒ»¸ö DHCP DISCOVER ·â°ü¡£ÒòΪ¿Í»§¶Ë»¹²»ÖªµÀ×Ô¼ºÊôÓÚÄÄÒ»¸öÍøÂ磬ËùÒÔ·â°üµÄÀ´Ô´µØÖ·»áΪ 0.0.0.0 £¬¶øÄ¿µÄµØÖ·ÔòΪ 255.255.255.255 £¬È»ºóÔÙ¸½ÉÏ DHCP discover µÄÐÅÏ¢£¬ÏòÍøÂç½øÐй㲥¡£ ÔÚ Windows µÄÔ¤ÉèÇéÐÎÏ£¬DHCP discover µÄµÈ´ýʱ¼äÔ¤ÉèΪ 1 Ã룬Ҳ¾ÍÊǵ±¿Í»§¶Ë½«µÚÒ»¸ö DHCP discover ·â°üËͳöÈ¥Ö®ºó£¬ÔÚ 1 ÃëÖ®ÄÚûÓеõ½ÏìÓ¦µÄ»°£¬¾Í»á½øÐеڶþ´Î DHCP discover ¹ã²¥¡£ÈôÒ»Ö±µÃ²»µ½ÏìÓ¦µÄÇé¿öÏ£¬¿Í»§¶ËÒ»¹²»áÓÐËÄ´Î DHCP discover ¹ã²¥£¨°üÀ¨µÚÒ»´ÎÔÚÄÚ£©£¬³ýÁ˵ÚÒ»´Î»áµÈ´ý 1 ÃëÖ®Í⣬ÆäÓàÈý´ÎµÄµÈ´ýʱ¼ä·Ö±ðÊÇ 9¡¢13¡¢16 Ãë¡£Èç¹û¶¼Ã»Óеõ½ DHCP ·þÎñÆ÷µÄÏìÓ¦£¬¿Í»§¶ËÔò»áÏÔʾ´íÎóÐÅÏ¢£¬Ðû¸æ DHCP discover µÄʧ°Ü¡£Ö®ºó£¬»ùÓÚʹÓÃÕßµÄÑ¡Ôñ£¬ÏµÍ³»á¼ÌÐøÔÚ 5 ·ÖÖÓÖ®ºóÔÙÖظ´Ò»´Î DHCP discover µÄ¹ý³Ì¡£ ÌṩIP×âÓõØÖ·
µ± DHCP ·þÎñÆ÷¼àÌýµ½¿Í»§¶Ë·¢³öµÄ DHCP discover ¹ã²¥ºó£¬Ëü»á´ÓÄÇЩ»¹Ã»ÓÐ×â³öµÄµØÖ··¶Î§ÄÚ£¬Ñ¡Ôñ×îÇ°ÃæµÄ¿ÕÖà IP £¬Á¬Í¬ÆäËü TCP/IP É趨£¬ÏìÓ¦¸ø¿Í»§¶ËÒ»¸ö DHCP OFFER ·â°ü¡£ ÓÉÓÚ¿Í»§¶ËÔÚ¿ªÊ¼µÄʱºò»¹Ã»ÓÐ IP µØÖ·£¬ËùÒÔÔÚÆä DHCP discover ·â°üÄÚ»á´øÓÐÆä MAC µØÖ·ÐÅÏ¢£¬²¢ÇÒÓÐÒ»¸ö XID ±àºÅÀ´±æ±ð¸Ã·â°ü£¬DHCP ·þÎñÆ÷ÏìÓ¦µÄ DHCP offer ·â°üÔò»á¸ù¾ÝÕâЩ×ÊÁÏ´«µÝ¸øÒªÇó×âÔ¼µÄ¿Í»§¡£¸ù¾Ý·þÎñÆ÷¶ËµÄÉ趨£¬DHCP offer ·â°ü»á°üº¬Ò»¸ö×âÔ¼ÆÚÏÞµÄÐÅÏ¢¡£ ½ÓÊÜIP×âÔ¼
Èç¹û¿Í»§¶ËÊÕµ½ÍøÂçÉ϶ą̀ DHCP ·þÎñÆ÷µÄÏìÓ¦£¬Ö»»áÌôÑ¡ÆäÖÐÒ»¸ö DHCP offer ¶øÒÑ£¨Í¨³£ÊÇ×îÏȵִïµÄÄǸö£©£¬²¢ÇÒ»áÏòÍøÂç·¢ËÍÒ»¸öDHCP request¹ã²¥·â°ü£¬¸æËßËùÓÐ DHCP ·þÎñÆ÷Ëü½«Ö¸¶¨½ÓÊÜÄÄһ̨·þÎñÆ÷ÌṩµÄ IP µØÖ·¡£ ͬʱ£¬¿Í»§¶Ë»¹»áÏòÍøÂç·¢