一个用于uC/OS的TCP/IP/PPP协议栈Version1.0.0ThesereleasenotesforuC/IParedividedintothefollowingsections:Introduction-AnoverviewoftheuC/IPproject.DesignOverview-Commentsonthedesignofthestack.Features-DescriptionofthefeaturesprovidedornotbyuC/IP.Copyright-Descriptionofthecopyrightsonthesourcefiles.Files-Abriefdescriptionofeachofthesourcefiles.Build-Commentsonhowtobuildthestackforyourapplication.ToDo-Anon-triviallistofthingsonthewishlist.Support-Wheretofindsupportinusingthestack.IntroductionThisisthefirstreleaseofafreeTCP/IP/PPPprotocolstackfortheuC/OSReal-TimeOperatingSystem.Asafirstreleaseit'sstillratherroughandverymuchlargerthandesiredhoweveritisworkingwellinanembeddedproductandthereforemaybeusefultoothers.MuchofthecodeisportedfrompublicsourcesincludingBDSLiteandKA9Q(anditsderivatives)andcarriescopyrightnoticesfromthosesources.EssentiallyTCPisbasedonKA9QbutwithideasfromBSD,IPisasimpleimplementationsupportingBSDstructures,ICMPisportedfromBSD,andPPPisportedfromtheBSDversionofthedistributioncommontoBSD,Linux,andmanyothersystems.ABriefHistoryWeatGlobalElectionSystemsInc.havebeenconvertingourembeddedsystemsfrommonolithicdesignsandproprietaryprotocolstoreal-timemultitaskingdesignsandstandardprotocols.Forvariousreasons,wechoseuC/OSasthefoundationforourprojectsbutwhenevaluatingthecommercialTCPofferings,wefeltthatwewouldwanttotweakthemasmuchaswewouldthepublicsourcesandthereforewemightaswelljustworkwiththepublicsources.Westartedwithvolumes1and2ofStevens'TCP/IPIllustratedandaCDROMofBSD-Liteanddivedintoit.Asalways,itwasrathermoreinvolvedthanplannedbutalsomorerewardinginthatbythetimewegotthroughit,wereallyknewourstuff.LuckilyGlobalhasnocommercialinterestintheresultandwasquitewillingtoletmemakethecodepubliclyavailableprovidedthatIdiditonmyowntimeandthattherewasnoliabilitytothecompany.DesignOverviewThisstackisdesignedforasmallblackboxsystemwithaminimaluserinterfaceandaserialport.Nokeyboard,novideodisplay,nodiskdrive,andnonetworkadaptor.Invariousmodesourboxcanoperateindependantlywithoccasionalconnectionstoahostoritcanworkonlinewithcontinouscommunicationswiththehost.Ourseriallinkmaybedirectlyconnectedtothehostorviamodemandtelephonelines.Now,usingtheTCPprocotols,theconnectionmaygothroughanynetworkconfigurationincludingtheInternet.NetworkBuffersCentraltothesourcesweusedistheideaofanetworkormemorybuffer.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.PointtoPointProtocolThePPPcodewasthefirstcodeimplementedandisthegreatestresourcehog.PPPiscomposedofanumberofdifferentprotocolshandlingeverythingfromtestingthelinktocompressionanduserauthentication.EssentiallyPPPrecievesnbufpacketchainsfromtheserialport,filtersouttheescapesequences,passesitthroughdecompressorsandfinallypassesanIPpackettotheIPprotocol.InmostsystemsPPPisimplementedasapacketdriversothatit'scompatiblewiththeinterfaceforanethernetpacketdriverbutthatrequiresmanaginganothersetofbuffers.MostofthePPPprotocolsusethefinitestatemachineengineinthenetfsmmodule.NotethatalthoughcodeisincludedforCHAP,ithasneverbeenusedandwillnotlikelyworkout-of-the-box.TransactionControlProtocol/InternetProtocolAsmentioned,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.FeaturesFeaturesSupportedPPPwithPAPauthenticationandVJcompressiondynamicIPoptimizedforsinglerequest/responseexchangesTCPkeepalivepollingwithprogrammableintervalsTheoptimizationFeaturesNOTSupportedCHAPauthentication(thecodeistherebutnotused)delayedTCPacknowledgement……