资料介绍
一个用于uC/OS的TCP/IP/PPP协议栈Version1.0.0
ThesereleasenotesforuC/IParedividedintothefollowingsections:
Introduction-AnoverviewoftheuC/IPproject.
DesignOverview-Commentsonthedesignofthestack.
Features-DescriptionofthefeaturesprovidedornotbyuC/IP.
Copyright-Descriptionofthecopyrightsonthesourcefiles.
Files-Abriefdescriptionofeachofthesourcefiles.
Build-Commentsonhowtobuildthestackforyourapplication.
ToDo-Anon-triviallistofthingsonthewishlist.
Support-Wheretofindsupportinusingthestack.
Introduction
ThisisthefirstreleaseofafreeTCP/IP/PPPprotocolstackfortheuC/OSReal-TimeOperatingSystem.Asafirstreleaseit'sstillratherroughandverymuchlargerthandesiredhoweveritisworkingwellinanembeddedproductandthereforemaybeusefultoothers.MuchofthecodeisportedfrompublicsourcesincludingBDSLiteandKA9Q(anditsderivatives)andcarriescopyrightnoticesfromthosesources.EssentiallyTCPisbasedonKA9QbutwithideasfromBSD,IPisasimpleimplementationsupportingBSDstructures,ICMPisportedfromBSD,andPPPisportedfromtheBSDversionofthedistributioncommontoBSD,Linux,andmanyothersystems.
ABriefHistory
WeatGlobalElectionSystemsInc.havebeenconvertingourembeddedsystemsfrommonolithicdesignsandproprietaryprotocolstoreal-timemultitaskingdesignsandstandardprotocols.Forvariousreasons,wechoseuC/OSasthefoundationforourprojectsbutwhenevaluatingthecommercialTCPofferings,wefeltthatwewouldwanttotweakthemasmuchaswewouldthepublicsourcesandthereforewemightaswelljustworkwiththepublicsources.Westartedwithvolumes1and2ofStevens'TCP/IPIllustratedandaCDROMofBSD-Liteanddivedintoit.Asalways,itwasrathermoreinvolvedthanplannedbutalsomorerewardinginthatbythetimewegotthroughit,wereallyknewourstuff.LuckilyGlobalhasnocommercialinterestintheresultandwasquitewillingtoletmemakethecodepubliclyavailableprovidedthatIdiditonmyowntimeandthattherewasnoliabilitytothecompany.
DesignOverview
Thisstackisdesignedforasmallblackboxsystemwithaminimaluserinterfaceandaserialport.Nokeyboard,novideodisplay,nodiskdrive,andnonetworkadaptor.Invariousmodesourboxcanoperateindependantlywithoccasionalconnectionstoahostoritcanworkonlinewithcontinouscommunicationswiththehost.Ourseriallinkmaybedirectlyconnectedtothehostorviamodemandtelephonelines.Now,usingtheTCPprocotols,theconnectionmaygothroughanynetworkconfigurationincludingtheInternet.
NetworkBuffers
Centraltothesourcesweusedistheideaofanetworkormemorybuffer.InBSDandKA9Qit'sknownasanmbuf.Normallydataistransferredtoachainofbuffersatthepacketinterface(commonlyknownsimplyasaninterface)whicharethentransferredviaqueuesthroughtheprotocollayersuntilfinallybeingunloadedatthesocketlayer.WemodifiedthedesignofthembufandrenameditnbufforNetworkBuffer.SinceoursystemhaslimitedRAMspaceandwewanttoguaranteethatneededspaceisalwaysavailable,wecreateafixednumberofnbufsandmanagethemasaresourcepool.Thenetbufmoduleprovidesfunctionssupportingnbufallocationandqueueingandservicessuchasprepending,appending,andtruncatingnbufchains.Inourstack,weusenbufsrightfromtheserialinterrupthandleruptotheapplicationinterface.
Foranyparticularapplication,it'simportanttoselectthenbufandpoolsizesforoptimumperformance.First,setthesizeofthenbufssothatonaverage,eachpacketfitsinasinglenbuf.Ifyourapplicationcommunicateswithalotofsmallpacketsandrarelymorethan100bytes,sayatelnetappthatreturnsasinglelineatatime,thensetthenbufsizetoabout50bytesandallocatemoreofthem.Ifyourapplicationdoesbulktransfers,setthenbufsizetohandleafullTCPsegmentandtherebyminimizethechainingoverhead.ThereiscurrentlyaminimumnbufsizesinceitneedstohandleanentireLCPpacketinPPP.WithalittleworkLCPwouldbeabletohandlepacketssplitacrossmultiplenbufs.
InthenextpassthroughthecodeI'dliketoaddabuffertypefieldthattheprotocolscanusetoautomaticallyhandledatafromdifferentsources.Inparticular,I'dliketoknowwhetherornotaPPPpacketneedstohavespecialcharactersescapedornotsothatthiscouldbehandledintheserialdriver.WhenthePPPprotocolsbuildapacket,theyautomaticallyencodethespecialcharacters.Tohandlethis,PPPneedstoknowwhereapacketoriginatedandthenensurethatallpacketsareencodedbeforepassingthemtotheserialdriver.Thisrequiresacharacterbycharacterfilter(copy)operationwhichcouldtriviallybehandledatthedriverlevelifonlyitknew.
PointtoPointProtocol
ThePPPcodewasthefirstcodeimplementedandisthegreatestresourcehog.PPPiscomposedofanumberofdifferentprotocolshandlingeverythingfromtestingthelinktocompressionanduserauthentication.EssentiallyPPPrecievesnbufpacketchainsfromtheserialport,filtersouttheescapesequences,passesitthroughdecompressorsandfinallypassesanIPpackettotheIPprotocol.InmostsystemsPPPisimplementedasapacketdriversothatit'scompatiblewiththeinterfaceforanethernetpacketdriverbutthatrequiresmanaginganothersetofbuffers.
MostofthePPPprotocolsusethefinitestatemachineengineinthenetfsmmodule.NotethatalthoughcodeisincludedforCHAP,ithasneverbeenusedandwillnotlikelyworkout-of-the-box.
TransactionControlProtocol/InternetProtocol
Asmentioned,theTCPcodeisbasedontheKA9QsourcesalthoughtheTCPControlBlock(TCB)includesfieldsfromtheBSDcodes.Thebiggestchangesfromeitherofthesesourcesisinthetimersandtheuseofsemaphores.KA9QwaswrittenforthesingletaskingenvironmentofDOSandthereforeusescallbackfunctionstodriveapplicationsusingthestack.WewantedtomakeblockingcallsandthereforewebuiltsemaphoresintotheTCBtosychronizereads,writes,connections,andformutualexclusionofcriticalsections.Thisdesigndoesn'thandlewakingupmultipletaskswaitingonareadorwritewhichwouldbeusefuliftheconnectionhasclosed.Thisisn'taproblemforourapplicationbutI'dliketofindamoregeneralsolution.
InUnix,thenormalmethodtohandleTCPtimersistohaveprocessespollingalloftheTCBat200msand500msintervals.Likeallpolling,thismeansthatCPUcyclesare"wasted"checkingTCB'sthatdon'tneedtobeservicedbutthemethodscaleswell(i.e.linearly)tolargenumbersofTCBs.InuC/IPweuseLinuxstyletimerswithpreallocatedtimerstructuresthatgetinsertedintoanorderedlinkedlistthatispolledbythesystemclockinterrupt.ThisworkswellforasmallnumberofTCBsbutformorethanafewdozen,theoverheadofinsertingandremovingtimersfromthelistwouldstarttoexceedinanon-linearfashionthecostofpollingalltheTCBs.
TheIPmoduleisprettybasicsinceweonlydotrivialroutingandwedon'thandlefragmentation.OnethingthatIwouldliketochangeistheuseofthesocketstylenetworkaddresses.Thesockaddrstruct(NetAddrtype)iswonderfullygeneralwhenyouwantittohandleanytypeofnetworkaddressbutwon'tbeabletohandleIPv6addresseswithoutchange.So,IwouldliketogothroughandsimplyhandleIPaddresses.
Features
FeaturesSupported
PPPwithPAPauthenticationandVJcompression
dynamicIP
optimizedforsinglerequest/responseexchanges
TCPkeepalivepollingwithprogrammableintervals
Theoptimization
FeaturesNOTSupported
CHAPauthentication(thecodeistherebutnotused)
delayedTCPacknowledgement