pmf.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664
  1. /******************************************************************************
  2. *
  3. * (C)Copyright 1998,1999 SysKonnect,
  4. * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
  5. *
  6. * See the file "skfddi.c" for further information.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * The information in this file is provided "AS IS" without warranty.
  14. *
  15. ******************************************************************************/
  16. /*
  17. Parameter Management Frame processing for SMT 7.2
  18. */
  19. #include "h/types.h"
  20. #include "h/fddi.h"
  21. #include "h/smc.h"
  22. #include "h/smt_p.h"
  23. #define KERNEL
  24. #include "h/smtstate.h"
  25. #ifndef SLIM_SMT
  26. #ifndef lint
  27. static const char ID_sccs[] = "@(#)pmf.c 1.37 97/08/04 (C) SK " ;
  28. #endif
  29. static int smt_authorize(struct s_smc *smc, struct smt_header *sm);
  30. static int smt_check_set_count(struct s_smc *smc, struct smt_header *sm);
  31. static const struct s_p_tab* smt_get_ptab(u_short para);
  32. static int smt_mib_phys(struct s_smc *smc);
  33. static int smt_set_para(struct s_smc *smc, struct smt_para *pa, int index,
  34. int local, int set);
  35. void smt_add_para(struct s_smc *smc, struct s_pcon *pcon, u_short para,
  36. int index, int local);
  37. static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req,
  38. int set, int local);
  39. static int port_to_mib(struct s_smc *smc, int p);
  40. #define MOFFSS(e) offsetof(struct fddi_mib, e)
  41. #define MOFFMS(e) offsetof(struct fddi_mib_m, e)
  42. #define MOFFAS(e) offsetof(struct fddi_mib_a, e)
  43. #define MOFFPS(e) offsetof(struct fddi_mib_p, e)
  44. #define AC_G 0x01 /* Get */
  45. #define AC_GR 0x02 /* Get/Set */
  46. #define AC_S 0x04 /* Set */
  47. #define AC_NA 0x08
  48. #define AC_GROUP 0x10 /* Group */
  49. #define MS2BCLK(x) ((x)*12500L)
  50. /*
  51. F LFag (byte)
  52. B byte
  53. S u_short 16 bit
  54. C Counter 32 bit
  55. L Long 32 bit
  56. T Timer_2 32 bit
  57. P TimeStamp ;
  58. A LongAddress (6 byte)
  59. E Enum 16 bit
  60. R ResId 16 Bit
  61. */
  62. static const struct s_p_tab {
  63. u_short p_num ; /* parameter code */
  64. u_char p_access ; /* access rights */
  65. u_short p_offset ; /* offset in mib */
  66. char p_swap[3] ; /* format string */
  67. } p_tab[] = {
  68. /* StationIdGrp */
  69. { SMT_P100A,AC_GROUP } ,
  70. { SMT_P100B,AC_G, MOFFSS(fddiSMTStationId), "8" } ,
  71. { SMT_P100D,AC_G, MOFFSS(fddiSMTOpVersionId), "S" } ,
  72. { SMT_P100E,AC_G, MOFFSS(fddiSMTHiVersionId), "S" } ,
  73. { SMT_P100F,AC_G, MOFFSS(fddiSMTLoVersionId), "S" } ,
  74. { SMT_P1010,AC_G, MOFFSS(fddiSMTManufacturerData), "D" } ,
  75. { SMT_P1011,AC_GR, MOFFSS(fddiSMTUserData), "D" } ,
  76. { SMT_P1012,AC_G, MOFFSS(fddiSMTMIBVersionId), "S" } ,
  77. /* StationConfigGrp */
  78. { SMT_P1014,AC_GROUP } ,
  79. { SMT_P1015,AC_G, MOFFSS(fddiSMTMac_Ct), "B" } ,
  80. { SMT_P1016,AC_G, MOFFSS(fddiSMTNonMaster_Ct), "B" } ,
  81. { SMT_P1017,AC_G, MOFFSS(fddiSMTMaster_Ct), "B" } ,
  82. { SMT_P1018,AC_G, MOFFSS(fddiSMTAvailablePaths), "B" } ,
  83. { SMT_P1019,AC_G, MOFFSS(fddiSMTConfigCapabilities),"S" } ,
  84. { SMT_P101A,AC_GR, MOFFSS(fddiSMTConfigPolicy), "wS" } ,
  85. { SMT_P101B,AC_GR, MOFFSS(fddiSMTConnectionPolicy),"wS" } ,
  86. { SMT_P101D,AC_GR, MOFFSS(fddiSMTTT_Notify), "wS" } ,
  87. { SMT_P101E,AC_GR, MOFFSS(fddiSMTStatRptPolicy), "bB" } ,
  88. { SMT_P101F,AC_GR, MOFFSS(fddiSMTTrace_MaxExpiration),"lL" } ,
  89. { SMT_P1020,AC_G, MOFFSS(fddiSMTPORTIndexes), "II" } ,
  90. { SMT_P1021,AC_G, MOFFSS(fddiSMTMACIndexes), "I" } ,
  91. { SMT_P1022,AC_G, MOFFSS(fddiSMTBypassPresent), "F" } ,
  92. /* StatusGrp */
  93. { SMT_P1028,AC_GROUP } ,
  94. { SMT_P1029,AC_G, MOFFSS(fddiSMTECMState), "E" } ,
  95. { SMT_P102A,AC_G, MOFFSS(fddiSMTCF_State), "E" } ,
  96. { SMT_P102C,AC_G, MOFFSS(fddiSMTRemoteDisconnectFlag),"F" } ,
  97. { SMT_P102D,AC_G, MOFFSS(fddiSMTStationStatus), "E" } ,
  98. { SMT_P102E,AC_G, MOFFSS(fddiSMTPeerWrapFlag), "F" } ,
  99. /* MIBOperationGrp */
  100. { SMT_P1032,AC_GROUP } ,
  101. { SMT_P1033,AC_G, MOFFSS(fddiSMTTimeStamp),"P" } ,
  102. { SMT_P1034,AC_G, MOFFSS(fddiSMTTransitionTimeStamp),"P" } ,
  103. /* NOTE : SMT_P1035 is already swapped ! SMT_P_SETCOUNT */
  104. { SMT_P1035,AC_G, MOFFSS(fddiSMTSetCount),"4P" } ,
  105. { SMT_P1036,AC_G, MOFFSS(fddiSMTLastSetStationId),"8" } ,
  106. { SMT_P103C,AC_S, 0, "wS" } ,
  107. /*
  108. * PRIVATE EXTENSIONS
  109. * only accessible locally to get/set passwd
  110. */
  111. { SMT_P10F0,AC_GR, MOFFSS(fddiPRPMFPasswd), "8" } ,
  112. { SMT_P10F1,AC_GR, MOFFSS(fddiPRPMFStation), "8" } ,
  113. #ifdef ESS
  114. { SMT_P10F2,AC_GR, MOFFSS(fddiESSPayload), "lL" } ,
  115. { SMT_P10F3,AC_GR, MOFFSS(fddiESSOverhead), "lL" } ,
  116. { SMT_P10F4,AC_GR, MOFFSS(fddiESSMaxTNeg), "lL" } ,
  117. { SMT_P10F5,AC_GR, MOFFSS(fddiESSMinSegmentSize), "lL" } ,
  118. { SMT_P10F6,AC_GR, MOFFSS(fddiESSCategory), "lL" } ,
  119. { SMT_P10F7,AC_GR, MOFFSS(fddiESSSynchTxMode), "wS" } ,
  120. #endif
  121. #ifdef SBA
  122. { SMT_P10F8,AC_GR, MOFFSS(fddiSBACommand), "bF" } ,
  123. { SMT_P10F9,AC_GR, MOFFSS(fddiSBAAvailable), "bF" } ,
  124. #endif
  125. /* MAC Attributes */
  126. { SMT_P200A,AC_GROUP } ,
  127. { SMT_P200B,AC_G, MOFFMS(fddiMACFrameStatusFunctions),"S" } ,
  128. { SMT_P200D,AC_G, MOFFMS(fddiMACT_MaxCapabilitiy),"T" } ,
  129. { SMT_P200E,AC_G, MOFFMS(fddiMACTVXCapabilitiy),"T" } ,
  130. /* ConfigGrp */
  131. { SMT_P2014,AC_GROUP } ,
  132. { SMT_P2016,AC_G, MOFFMS(fddiMACAvailablePaths), "B" } ,
  133. { SMT_P2017,AC_G, MOFFMS(fddiMACCurrentPath), "S" } ,
  134. { SMT_P2018,AC_G, MOFFMS(fddiMACUpstreamNbr), "A" } ,
  135. { SMT_P2019,AC_G, MOFFMS(fddiMACDownstreamNbr), "A" } ,
  136. { SMT_P201A,AC_G, MOFFMS(fddiMACOldUpstreamNbr), "A" } ,
  137. { SMT_P201B,AC_G, MOFFMS(fddiMACOldDownstreamNbr),"A" } ,
  138. { SMT_P201D,AC_G, MOFFMS(fddiMACDupAddressTest), "E" } ,
  139. { SMT_P2020,AC_GR, MOFFMS(fddiMACRequestedPaths), "wS" } ,
  140. { SMT_P2021,AC_G, MOFFMS(fddiMACDownstreamPORTType),"E" } ,
  141. { SMT_P2022,AC_G, MOFFMS(fddiMACIndex), "S" } ,
  142. /* AddressGrp */
  143. { SMT_P2028,AC_GROUP } ,
  144. { SMT_P2029,AC_G, MOFFMS(fddiMACSMTAddress), "A" } ,
  145. /* OperationGrp */
  146. { SMT_P2032,AC_GROUP } ,
  147. { SMT_P2033,AC_G, MOFFMS(fddiMACT_Req), "T" } ,
  148. { SMT_P2034,AC_G, MOFFMS(fddiMACT_Neg), "T" } ,
  149. { SMT_P2035,AC_G, MOFFMS(fddiMACT_Max), "T" } ,
  150. { SMT_P2036,AC_G, MOFFMS(fddiMACTvxValue), "T" } ,
  151. { SMT_P2038,AC_G, MOFFMS(fddiMACT_Pri0), "T" } ,
  152. { SMT_P2039,AC_G, MOFFMS(fddiMACT_Pri1), "T" } ,
  153. { SMT_P203A,AC_G, MOFFMS(fddiMACT_Pri2), "T" } ,
  154. { SMT_P203B,AC_G, MOFFMS(fddiMACT_Pri3), "T" } ,
  155. { SMT_P203C,AC_G, MOFFMS(fddiMACT_Pri4), "T" } ,
  156. { SMT_P203D,AC_G, MOFFMS(fddiMACT_Pri5), "T" } ,
  157. { SMT_P203E,AC_G, MOFFMS(fddiMACT_Pri6), "T" } ,
  158. /* CountersGrp */
  159. { SMT_P2046,AC_GROUP } ,
  160. { SMT_P2047,AC_G, MOFFMS(fddiMACFrame_Ct), "C" } ,
  161. { SMT_P2048,AC_G, MOFFMS(fddiMACCopied_Ct), "C" } ,
  162. { SMT_P2049,AC_G, MOFFMS(fddiMACTransmit_Ct), "C" } ,
  163. { SMT_P204A,AC_G, MOFFMS(fddiMACToken_Ct), "C" } ,
  164. { SMT_P2051,AC_G, MOFFMS(fddiMACError_Ct), "C" } ,
  165. { SMT_P2052,AC_G, MOFFMS(fddiMACLost_Ct), "C" } ,
  166. { SMT_P2053,AC_G, MOFFMS(fddiMACTvxExpired_Ct), "C" } ,
  167. { SMT_P2054,AC_G, MOFFMS(fddiMACNotCopied_Ct), "C" } ,
  168. { SMT_P2056,AC_G, MOFFMS(fddiMACRingOp_Ct), "C" } ,
  169. /* FrameErrorConditionGrp */
  170. { SMT_P205A,AC_GROUP } ,
  171. { SMT_P205F,AC_GR, MOFFMS(fddiMACFrameErrorThreshold),"wS" } ,
  172. { SMT_P2060,AC_G, MOFFMS(fddiMACFrameErrorRatio), "S" } ,
  173. /* NotCopiedConditionGrp */
  174. { SMT_P2064,AC_GROUP } ,
  175. { SMT_P2067,AC_GR, MOFFMS(fddiMACNotCopiedThreshold),"wS" } ,
  176. { SMT_P2069,AC_G, MOFFMS(fddiMACNotCopiedRatio), "S" } ,
  177. /* StatusGrp */
  178. { SMT_P206E,AC_GROUP } ,
  179. { SMT_P206F,AC_G, MOFFMS(fddiMACRMTState), "S" } ,
  180. { SMT_P2070,AC_G, MOFFMS(fddiMACDA_Flag), "F" } ,
  181. { SMT_P2071,AC_G, MOFFMS(fddiMACUNDA_Flag), "F" } ,
  182. { SMT_P2072,AC_G, MOFFMS(fddiMACFrameErrorFlag), "F" } ,
  183. { SMT_P2073,AC_G, MOFFMS(fddiMACNotCopiedFlag), "F" } ,
  184. { SMT_P2074,AC_G, MOFFMS(fddiMACMA_UnitdataAvailable),"F" } ,
  185. { SMT_P2075,AC_G, MOFFMS(fddiMACHardwarePresent), "F" } ,
  186. { SMT_P2076,AC_GR, MOFFMS(fddiMACMA_UnitdataEnable),"bF" } ,
  187. /*
  188. * PRIVATE EXTENSIONS
  189. * only accessible locally to get/set TMIN
  190. */
  191. { SMT_P20F0,AC_NA } ,
  192. { SMT_P20F1,AC_GR, MOFFMS(fddiMACT_Min), "lT" } ,
  193. /* Path Attributes */
  194. /*
  195. * DON't swap 320B,320F,3210: they are already swapped in swap_para()
  196. */
  197. { SMT_P320A,AC_GROUP } ,
  198. { SMT_P320B,AC_G, MOFFAS(fddiPATHIndex), "r" } ,
  199. { SMT_P320F,AC_GR, MOFFAS(fddiPATHSbaPayload), "l4" } ,
  200. { SMT_P3210,AC_GR, MOFFAS(fddiPATHSbaOverhead), "l4" } ,
  201. /* fddiPATHConfiguration */
  202. { SMT_P3212,AC_G, 0, "" } ,
  203. { SMT_P3213,AC_GR, MOFFAS(fddiPATHT_Rmode), "lT" } ,
  204. { SMT_P3214,AC_GR, MOFFAS(fddiPATHSbaAvailable), "lL" } ,
  205. { SMT_P3215,AC_GR, MOFFAS(fddiPATHTVXLowerBound), "lT" } ,
  206. { SMT_P3216,AC_GR, MOFFAS(fddiPATHT_MaxLowerBound),"lT" } ,
  207. { SMT_P3217,AC_GR, MOFFAS(fddiPATHMaxT_Req), "lT" } ,
  208. /* Port Attributes */
  209. /* ConfigGrp */
  210. { SMT_P400A,AC_GROUP } ,
  211. { SMT_P400C,AC_G, MOFFPS(fddiPORTMy_Type), "E" } ,
  212. { SMT_P400D,AC_G, MOFFPS(fddiPORTNeighborType), "E" } ,
  213. { SMT_P400E,AC_GR, MOFFPS(fddiPORTConnectionPolicies),"bB" } ,
  214. { SMT_P400F,AC_G, MOFFPS(fddiPORTMacIndicated), "2" } ,
  215. { SMT_P4010,AC_G, MOFFPS(fddiPORTCurrentPath), "E" } ,
  216. { SMT_P4011,AC_GR, MOFFPS(fddiPORTRequestedPaths), "l4" } ,
  217. { SMT_P4012,AC_G, MOFFPS(fddiPORTMACPlacement), "S" } ,
  218. { SMT_P4013,AC_G, MOFFPS(fddiPORTAvailablePaths), "B" } ,
  219. { SMT_P4016,AC_G, MOFFPS(fddiPORTPMDClass), "E" } ,
  220. { SMT_P4017,AC_G, MOFFPS(fddiPORTConnectionCapabilities), "B"} ,
  221. { SMT_P401D,AC_G, MOFFPS(fddiPORTIndex), "R" } ,
  222. /* OperationGrp */
  223. { SMT_P401E,AC_GROUP } ,
  224. { SMT_P401F,AC_GR, MOFFPS(fddiPORTMaint_LS), "wE" } ,
  225. { SMT_P4021,AC_G, MOFFPS(fddiPORTBS_Flag), "F" } ,
  226. { SMT_P4022,AC_G, MOFFPS(fddiPORTPC_LS), "E" } ,
  227. /* ErrorCtrsGrp */
  228. { SMT_P4028,AC_GROUP } ,
  229. { SMT_P4029,AC_G, MOFFPS(fddiPORTEBError_Ct), "C" } ,
  230. { SMT_P402A,AC_G, MOFFPS(fddiPORTLCTFail_Ct), "C" } ,
  231. /* LerGrp */
  232. { SMT_P4032,AC_GROUP } ,
  233. { SMT_P4033,AC_G, MOFFPS(fddiPORTLer_Estimate), "F" } ,
  234. { SMT_P4034,AC_G, MOFFPS(fddiPORTLem_Reject_Ct), "C" } ,
  235. { SMT_P4035,AC_G, MOFFPS(fddiPORTLem_Ct), "C" } ,
  236. { SMT_P403A,AC_GR, MOFFPS(fddiPORTLer_Cutoff), "bB" } ,
  237. { SMT_P403B,AC_GR, MOFFPS(fddiPORTLer_Alarm), "bB" } ,
  238. /* StatusGrp */
  239. { SMT_P403C,AC_GROUP } ,
  240. { SMT_P403D,AC_G, MOFFPS(fddiPORTConnectState), "E" } ,
  241. { SMT_P403E,AC_G, MOFFPS(fddiPORTPCMStateX), "E" } ,
  242. { SMT_P403F,AC_G, MOFFPS(fddiPORTPC_Withhold), "E" } ,
  243. { SMT_P4040,AC_G, MOFFPS(fddiPORTLerFlag), "F" } ,
  244. { SMT_P4041,AC_G, MOFFPS(fddiPORTHardwarePresent),"F" } ,
  245. { SMT_P4046,AC_S, 0, "wS" } ,
  246. { 0, AC_GROUP } ,
  247. { 0 }
  248. } ;
  249. void smt_pmf_received_pack(struct s_smc *smc, SMbuf *mb, int local)
  250. {
  251. struct smt_header *sm ;
  252. SMbuf *reply ;
  253. sm = smtod(mb,struct smt_header *) ;
  254. DB_SMT("SMT: processing PMF frame at %x len %d\n",sm,mb->sm_len) ;
  255. #ifdef DEBUG
  256. dump_smt(smc,sm,"PMF Received") ;
  257. #endif
  258. /*
  259. * Start the watchdog: It may be a long, long packet and
  260. * maybe the watchdog occurs ...
  261. */
  262. smt_start_watchdog(smc) ;
  263. if (sm->smt_class == SMT_PMF_GET ||
  264. sm->smt_class == SMT_PMF_SET) {
  265. reply = smt_build_pmf_response(smc,sm,
  266. sm->smt_class == SMT_PMF_SET,local) ;
  267. if (reply) {
  268. sm = smtod(reply,struct smt_header *) ;
  269. #ifdef DEBUG
  270. dump_smt(smc,sm,"PMF Reply") ;
  271. #endif
  272. smt_send_frame(smc,reply,FC_SMT_INFO,local) ;
  273. }
  274. }
  275. }
  276. static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req,
  277. int set, int local)
  278. {
  279. SMbuf *mb ;
  280. struct smt_header *smt ;
  281. struct smt_para *pa ;
  282. struct smt_p_reason *res ;
  283. const struct s_p_tab *pt ;
  284. int len ;
  285. int index ;
  286. int idx_end ;
  287. int error ;
  288. int range ;
  289. SK_LOC_DECL(struct s_pcon,pcon) ;
  290. SK_LOC_DECL(struct s_pcon,set_pcon) ;
  291. /*
  292. * build SMT header
  293. */
  294. if (!(mb = smt_get_mbuf(smc)))
  295. return mb;
  296. smt = smtod(mb, struct smt_header *) ;
  297. smt->smt_dest = req->smt_source ; /* DA == source of request */
  298. smt->smt_class = req->smt_class ; /* same class (GET/SET) */
  299. smt->smt_type = SMT_REPLY ;
  300. smt->smt_version = SMT_VID_2 ;
  301. smt->smt_tid = req->smt_tid ; /* same TID */
  302. smt->smt_pad = 0 ;
  303. smt->smt_len = 0 ;
  304. /*
  305. * setup parameter status
  306. */
  307. pcon.pc_len = SMT_MAX_INFO_LEN ; /* max para length */
  308. pcon.pc_err = 0 ; /* no error */
  309. pcon.pc_badset = 0 ; /* no bad set count */
  310. pcon.pc_p = (void *) (smt + 1) ; /* paras start here */
  311. /*
  312. * check authoriziation and set count
  313. */
  314. error = 0 ;
  315. if (set) {
  316. if (!local && smt_authorize(smc,req))
  317. error = SMT_RDF_AUTHOR ;
  318. else if (smt_check_set_count(smc,req))
  319. pcon.pc_badset = SMT_RDF_BADSET ;
  320. }
  321. /*
  322. * add reason code and all mandatory parameters
  323. */
  324. res = (struct smt_p_reason *) pcon.pc_p ;
  325. smt_add_para(smc,&pcon,(u_short) SMT_P_REASON,0,0) ;
  326. smt_add_para(smc,&pcon,(u_short) SMT_P1033,0,0) ;
  327. /* update 1035 and 1036 later if set */
  328. set_pcon = pcon ;
  329. smt_add_para(smc,&pcon,(u_short) SMT_P1035,0,0) ;
  330. smt_add_para(smc,&pcon,(u_short) SMT_P1036,0,0) ;
  331. pcon.pc_err = error ;
  332. len = req->smt_len ;
  333. pa = (struct smt_para *) (req + 1) ;
  334. /*
  335. * process list of paras
  336. */
  337. while (!pcon.pc_err && len > 0 ) {
  338. if (((u_short)len < pa->p_len + PARA_LEN) || (pa->p_len & 3)) {
  339. pcon.pc_err = SMT_RDF_LENGTH ;
  340. break ;
  341. }
  342. if (((range = (pa->p_type & 0xf000)) == 0x2000) ||
  343. range == 0x3000 || range == 0x4000) {
  344. /*
  345. * get index for PART,MAC ad PATH group
  346. */
  347. index = *((u_char *)pa + PARA_LEN + 3) ;/* index */
  348. idx_end = index ;
  349. if (!set && (pa->p_len != 4)) {
  350. pcon.pc_err = SMT_RDF_LENGTH ;
  351. break ;
  352. }
  353. if (!index && !set) {
  354. switch (range) {
  355. case 0x2000 :
  356. index = INDEX_MAC ;
  357. idx_end = index - 1 + NUMMACS ;
  358. break ;
  359. case 0x3000 :
  360. index = INDEX_PATH ;
  361. idx_end = index - 1 + NUMPATHS ;
  362. break ;
  363. case 0x4000 :
  364. index = INDEX_PORT ;
  365. idx_end = index - 1 + NUMPHYS ;
  366. #ifndef CONCENTRATOR
  367. if (smc->s.sas == SMT_SAS)
  368. idx_end = INDEX_PORT ;
  369. #endif
  370. break ;
  371. }
  372. }
  373. }
  374. else {
  375. /*
  376. * smt group has no index
  377. */
  378. if (!set && (pa->p_len != 0)) {
  379. pcon.pc_err = SMT_RDF_LENGTH ;
  380. break ;
  381. }
  382. index = 0 ;
  383. idx_end = 0 ;
  384. }
  385. while (index <= idx_end) {
  386. /*
  387. * if group
  388. * add all paras of group
  389. */
  390. pt = smt_get_ptab(pa->p_type) ;
  391. if (pt && pt->p_access == AC_GROUP && !set) {
  392. pt++ ;
  393. while (pt->p_access == AC_G ||
  394. pt->p_access == AC_GR) {
  395. smt_add_para(smc,&pcon,pt->p_num,
  396. index,local);
  397. pt++ ;
  398. }
  399. }
  400. /*
  401. * ignore
  402. * AUTHORIZATION in get/set
  403. * SET COUNT in set
  404. */
  405. else if (pa->p_type != SMT_P_AUTHOR &&
  406. (!set || (pa->p_type != SMT_P1035))) {
  407. int st ;
  408. if (pcon.pc_badset) {
  409. smt_add_para(smc,&pcon,pa->p_type,
  410. index,local) ;
  411. }
  412. else if (set) {
  413. st = smt_set_para(smc,pa,index,local,1);
  414. /*
  415. * return para even if error
  416. */
  417. smt_add_para(smc,&pcon,pa->p_type,
  418. index,local) ;
  419. pcon.pc_err = st ;
  420. }
  421. else {
  422. if (pt && pt->p_access == AC_S) {
  423. pcon.pc_err =
  424. SMT_RDF_ILLEGAL ;
  425. }
  426. smt_add_para(smc,&pcon,pa->p_type,
  427. index,local) ;
  428. }
  429. }
  430. if (pcon.pc_err)
  431. break ;
  432. index++ ;
  433. }
  434. len -= pa->p_len + PARA_LEN ;
  435. pa = (struct smt_para *) ((char *)pa + pa->p_len + PARA_LEN) ;
  436. }
  437. smt->smt_len = SMT_MAX_INFO_LEN - pcon.pc_len ;
  438. mb->sm_len = smt->smt_len + sizeof(struct smt_header) ;
  439. /* update reason code */
  440. res->rdf_reason = pcon.pc_badset ? pcon.pc_badset :
  441. pcon.pc_err ? pcon.pc_err : SMT_RDF_SUCCESS ;
  442. if (set && (res->rdf_reason == SMT_RDF_SUCCESS)) {
  443. /*
  444. * increment set count
  445. * set time stamp
  446. * store station id of last set
  447. */
  448. smc->mib.fddiSMTSetCount.count++ ;
  449. smt_set_timestamp(smc,smc->mib.fddiSMTSetCount.timestamp) ;
  450. smc->mib.fddiSMTLastSetStationId = req->smt_sid ;
  451. smt_add_para(smc,&set_pcon,(u_short) SMT_P1035,0,0) ;
  452. smt_add_para(smc,&set_pcon,(u_short) SMT_P1036,0,0) ;
  453. }
  454. return mb;
  455. }
  456. static int smt_authorize(struct s_smc *smc, struct smt_header *sm)
  457. {
  458. struct smt_para *pa ;
  459. int i ;
  460. char *p ;
  461. /*
  462. * check source station id if not zero
  463. */
  464. p = (char *) &smc->mib.fddiPRPMFStation ;
  465. for (i = 0 ; i < 8 && !p[i] ; i++)
  466. ;
  467. if (i != 8) {
  468. if (memcmp((char *) &sm->smt_sid,
  469. (char *) &smc->mib.fddiPRPMFStation,8))
  470. return 1;
  471. }
  472. /*
  473. * check authoriziation parameter if passwd not zero
  474. */
  475. p = (char *) smc->mib.fddiPRPMFPasswd ;
  476. for (i = 0 ; i < 8 && !p[i] ; i++)
  477. ;
  478. if (i != 8) {
  479. pa = (struct smt_para *) sm_to_para(smc,sm,SMT_P_AUTHOR) ;
  480. if (!pa)
  481. return 1;
  482. if (pa->p_len != 8)
  483. return 1;
  484. if (memcmp((char *)(pa+1),(char *)smc->mib.fddiPRPMFPasswd,8))
  485. return 1;
  486. }
  487. return 0;
  488. }
  489. static int smt_check_set_count(struct s_smc *smc, struct smt_header *sm)
  490. {
  491. struct smt_para *pa ;
  492. struct smt_p_setcount *sc ;
  493. pa = (struct smt_para *) sm_to_para(smc,sm,SMT_P1035) ;
  494. if (pa) {
  495. sc = (struct smt_p_setcount *) pa ;
  496. if ((smc->mib.fddiSMTSetCount.count != sc->count) ||
  497. memcmp((char *) smc->mib.fddiSMTSetCount.timestamp,
  498. (char *)sc->timestamp,8))
  499. return 1;
  500. }
  501. return 0;
  502. }
  503. void smt_add_para(struct s_smc *smc, struct s_pcon *pcon, u_short para,
  504. int index, int local)
  505. {
  506. struct smt_para *pa ;
  507. const struct s_p_tab *pt ;
  508. struct fddi_mib_m *mib_m = NULL;
  509. struct fddi_mib_p *mib_p = NULL;
  510. int len ;
  511. int plen ;
  512. char *from ;
  513. char *to ;
  514. const char *swap ;
  515. char c ;
  516. int range ;
  517. char *mib_addr ;
  518. int mac ;
  519. int path ;
  520. int port ;
  521. int sp_len ;
  522. /*
  523. * skip if error
  524. */
  525. if (pcon->pc_err)
  526. return ;
  527. /*
  528. * actions don't have a value
  529. */
  530. pt = smt_get_ptab(para) ;
  531. if (pt && pt->p_access == AC_S)
  532. return ;
  533. to = (char *) (pcon->pc_p) ; /* destination pointer */
  534. len = pcon->pc_len ; /* free space */
  535. plen = len ; /* remember start length */
  536. pa = (struct smt_para *) to ; /* type/length pointer */
  537. to += PARA_LEN ; /* skip smt_para */
  538. len -= PARA_LEN ;
  539. /*
  540. * set index if required
  541. */
  542. if (((range = (para & 0xf000)) == 0x2000) ||
  543. range == 0x3000 || range == 0x4000) {
  544. if (len < 4)
  545. goto wrong_error ;
  546. to[0] = 0 ;
  547. to[1] = 0 ;
  548. to[2] = 0 ;
  549. to[3] = index ;
  550. len -= 4 ;
  551. to += 4 ;
  552. }
  553. mac = index - INDEX_MAC ;
  554. path = index - INDEX_PATH ;
  555. port = index - INDEX_PORT ;
  556. /*
  557. * get pointer to mib
  558. */
  559. switch (range) {
  560. case 0x1000 :
  561. default :
  562. mib_addr = (char *) (&smc->mib) ;
  563. break ;
  564. case 0x2000 :
  565. if (mac < 0 || mac >= NUMMACS) {
  566. pcon->pc_err = SMT_RDF_NOPARAM ;
  567. return ;
  568. }
  569. mib_addr = (char *) (&smc->mib.m[mac]) ;
  570. mib_m = (struct fddi_mib_m *) mib_addr ;
  571. break ;
  572. case 0x3000 :
  573. if (path < 0 || path >= NUMPATHS) {
  574. pcon->pc_err = SMT_RDF_NOPARAM ;
  575. return ;
  576. }
  577. mib_addr = (char *) (&smc->mib.a[path]) ;
  578. break ;
  579. case 0x4000 :
  580. if (port < 0 || port >= smt_mib_phys(smc)) {
  581. pcon->pc_err = SMT_RDF_NOPARAM ;
  582. return ;
  583. }
  584. mib_addr = (char *) (&smc->mib.p[port_to_mib(smc,port)]) ;
  585. mib_p = (struct fddi_mib_p *) mib_addr ;
  586. break ;
  587. }
  588. /*
  589. * check special paras
  590. */
  591. swap = NULL;
  592. switch (para) {
  593. case SMT_P10F0 :
  594. case SMT_P10F1 :
  595. #ifdef ESS
  596. case SMT_P10F2 :
  597. case SMT_P10F3 :
  598. case SMT_P10F4 :
  599. case SMT_P10F5 :
  600. case SMT_P10F6 :
  601. case SMT_P10F7 :
  602. #endif
  603. #ifdef SBA
  604. case SMT_P10F8 :
  605. case SMT_P10F9 :
  606. #endif
  607. case SMT_P20F1 :
  608. if (!local) {
  609. pcon->pc_err = SMT_RDF_NOPARAM ;
  610. return ;
  611. }
  612. break ;
  613. case SMT_P2034 :
  614. case SMT_P2046 :
  615. case SMT_P2047 :
  616. case SMT_P204A :
  617. case SMT_P2051 :
  618. case SMT_P2052 :
  619. mac_update_counter(smc) ;
  620. break ;
  621. case SMT_P4022:
  622. mib_p->fddiPORTPC_LS = LS2MIB(
  623. sm_pm_get_ls(smc,port_to_mib(smc,port))) ;
  624. break ;
  625. case SMT_P_REASON :
  626. * (u_long *) to = 0 ;
  627. sp_len = 4 ;
  628. goto sp_done ;
  629. case SMT_P1033 : /* time stamp */
  630. smt_set_timestamp(smc,smc->mib.fddiSMTTimeStamp) ;
  631. break ;
  632. case SMT_P1020: /* port indexes */
  633. #if NUMPHYS == 12
  634. swap = "IIIIIIIIIIII" ;
  635. #else
  636. #if NUMPHYS == 2
  637. if (smc->s.sas == SMT_SAS)
  638. swap = "I" ;
  639. else
  640. swap = "II" ;
  641. #else
  642. #if NUMPHYS == 24
  643. swap = "IIIIIIIIIIIIIIIIIIIIIIII" ;
  644. #else
  645. ????
  646. #endif
  647. #endif
  648. #endif
  649. break ;
  650. case SMT_P3212 :
  651. {
  652. sp_len = cem_build_path(smc,to,path) ;
  653. goto sp_done ;
  654. }
  655. case SMT_P1048 : /* peer wrap condition */
  656. {
  657. struct smt_p_1048 *sp ;
  658. sp = (struct smt_p_1048 *) to ;
  659. sp->p1048_flag = smc->mib.fddiSMTPeerWrapFlag ;
  660. sp->p1048_cf_state = smc->mib.fddiSMTCF_State ;
  661. sp_len = sizeof(struct smt_p_1048) ;
  662. goto sp_done ;
  663. }
  664. case SMT_P208C :
  665. {
  666. struct smt_p_208c *sp ;
  667. sp = (struct smt_p_208c *) to ;
  668. sp->p208c_flag =
  669. smc->mib.m[MAC0].fddiMACDuplicateAddressCond ;
  670. sp->p208c_dupcondition =
  671. (mib_m->fddiMACDA_Flag ? SMT_ST_MY_DUPA : 0) |
  672. (mib_m->fddiMACUNDA_Flag ? SMT_ST_UNA_DUPA : 0);
  673. sp->p208c_fddilong =
  674. mib_m->fddiMACSMTAddress ;
  675. sp->p208c_fddiunalong =
  676. mib_m->fddiMACUpstreamNbr ;
  677. sp->p208c_pad = 0 ;
  678. sp_len = sizeof(struct smt_p_208c) ;
  679. goto sp_done ;
  680. }
  681. case SMT_P208D : /* frame error condition */
  682. {
  683. struct smt_p_208d *sp ;
  684. sp = (struct smt_p_208d *) to ;
  685. sp->p208d_flag =
  686. mib_m->fddiMACFrameErrorFlag ;
  687. sp->p208d_frame_ct =
  688. mib_m->fddiMACFrame_Ct ;
  689. sp->p208d_error_ct =
  690. mib_m->fddiMACError_Ct ;
  691. sp->p208d_lost_ct =
  692. mib_m->fddiMACLost_Ct ;
  693. sp->p208d_ratio =
  694. mib_m->fddiMACFrameErrorRatio ;
  695. sp_len = sizeof(struct smt_p_208d) ;
  696. goto sp_done ;
  697. }
  698. case SMT_P208E : /* not copied condition */
  699. {
  700. struct smt_p_208e *sp ;
  701. sp = (struct smt_p_208e *) to ;
  702. sp->p208e_flag =
  703. mib_m->fddiMACNotCopiedFlag ;
  704. sp->p208e_not_copied =
  705. mib_m->fddiMACNotCopied_Ct ;
  706. sp->p208e_copied =
  707. mib_m->fddiMACCopied_Ct ;
  708. sp->p208e_not_copied_ratio =
  709. mib_m->fddiMACNotCopiedRatio ;
  710. sp_len = sizeof(struct smt_p_208e) ;
  711. goto sp_done ;
  712. }
  713. case SMT_P208F : /* neighbor change event */
  714. {
  715. struct smt_p_208f *sp ;
  716. sp = (struct smt_p_208f *) to ;
  717. sp->p208f_multiple =
  718. mib_m->fddiMACMultiple_N ;
  719. sp->p208f_nacondition =
  720. mib_m->fddiMACDuplicateAddressCond ;
  721. sp->p208f_old_una =
  722. mib_m->fddiMACOldUpstreamNbr ;
  723. sp->p208f_new_una =
  724. mib_m->fddiMACUpstreamNbr ;
  725. sp->p208f_old_dna =
  726. mib_m->fddiMACOldDownstreamNbr ;
  727. sp->p208f_new_dna =
  728. mib_m->fddiMACDownstreamNbr ;
  729. sp->p208f_curren_path =
  730. mib_m->fddiMACCurrentPath ;
  731. sp->p208f_smt_address =
  732. mib_m->fddiMACSMTAddress ;
  733. sp_len = sizeof(struct smt_p_208f) ;
  734. goto sp_done ;
  735. }
  736. case SMT_P2090 :
  737. {
  738. struct smt_p_2090 *sp ;
  739. sp = (struct smt_p_2090 *) to ;
  740. sp->p2090_multiple =
  741. mib_m->fddiMACMultiple_P ;
  742. sp->p2090_availablepaths =
  743. mib_m->fddiMACAvailablePaths ;
  744. sp->p2090_currentpath =
  745. mib_m->fddiMACCurrentPath ;
  746. sp->p2090_requestedpaths =
  747. mib_m->fddiMACRequestedPaths ;
  748. sp_len = sizeof(struct smt_p_2090) ;
  749. goto sp_done ;
  750. }
  751. case SMT_P4050 :
  752. {
  753. struct smt_p_4050 *sp ;
  754. sp = (struct smt_p_4050 *) to ;
  755. sp->p4050_flag =
  756. mib_p->fddiPORTLerFlag ;
  757. sp->p4050_pad = 0 ;
  758. sp->p4050_cutoff =
  759. mib_p->fddiPORTLer_Cutoff ;
  760. sp->p4050_alarm =
  761. mib_p->fddiPORTLer_Alarm ;
  762. sp->p4050_estimate =
  763. mib_p->fddiPORTLer_Estimate ;
  764. sp->p4050_reject_ct =
  765. mib_p->fddiPORTLem_Reject_Ct ;
  766. sp->p4050_ct =
  767. mib_p->fddiPORTLem_Ct ;
  768. sp_len = sizeof(struct smt_p_4050) ;
  769. goto sp_done ;
  770. }
  771. case SMT_P4051 :
  772. {
  773. struct smt_p_4051 *sp ;
  774. sp = (struct smt_p_4051 *) to ;
  775. sp->p4051_multiple =
  776. mib_p->fddiPORTMultiple_U ;
  777. sp->p4051_porttype =
  778. mib_p->fddiPORTMy_Type ;
  779. sp->p4051_connectstate =
  780. mib_p->fddiPORTConnectState ;
  781. sp->p4051_pc_neighbor =
  782. mib_p->fddiPORTNeighborType ;
  783. sp->p4051_pc_withhold =
  784. mib_p->fddiPORTPC_Withhold ;
  785. sp_len = sizeof(struct smt_p_4051) ;
  786. goto sp_done ;
  787. }
  788. case SMT_P4052 :
  789. {
  790. struct smt_p_4052 *sp ;
  791. sp = (struct smt_p_4052 *) to ;
  792. sp->p4052_flag =
  793. mib_p->fddiPORTEB_Condition ;
  794. sp->p4052_eberrorcount =
  795. mib_p->fddiPORTEBError_Ct ;
  796. sp_len = sizeof(struct smt_p_4052) ;
  797. goto sp_done ;
  798. }
  799. case SMT_P4053 :
  800. {
  801. struct smt_p_4053 *sp ;
  802. sp = (struct smt_p_4053 *) to ;
  803. sp->p4053_multiple =
  804. mib_p->fddiPORTMultiple_P ;
  805. sp->p4053_availablepaths =
  806. mib_p->fddiPORTAvailablePaths ;
  807. sp->p4053_currentpath =
  808. mib_p->fddiPORTCurrentPath ;
  809. memcpy( (char *) &sp->p4053_requestedpaths,
  810. (char *) mib_p->fddiPORTRequestedPaths,4) ;
  811. sp->p4053_mytype =
  812. mib_p->fddiPORTMy_Type ;
  813. sp->p4053_neighbortype =
  814. mib_p->fddiPORTNeighborType ;
  815. sp_len = sizeof(struct smt_p_4053) ;
  816. goto sp_done ;
  817. }
  818. default :
  819. break ;
  820. }
  821. /*
  822. * in table ?
  823. */
  824. if (!pt) {
  825. pcon->pc_err = (para & 0xff00) ? SMT_RDF_NOPARAM :
  826. SMT_RDF_ILLEGAL ;
  827. return ;
  828. }
  829. /*
  830. * check access rights
  831. */
  832. switch (pt->p_access) {
  833. case AC_G :
  834. case AC_GR :
  835. break ;
  836. default :
  837. pcon->pc_err = SMT_RDF_ILLEGAL ;
  838. return ;
  839. }
  840. from = mib_addr + pt->p_offset ;
  841. if (!swap)
  842. swap = pt->p_swap ; /* pointer to swap string */
  843. /*
  844. * copy values
  845. */
  846. while ((c = *swap++)) {
  847. switch(c) {
  848. case 'b' :
  849. case 'w' :
  850. case 'l' :
  851. break ;
  852. case 'S' :
  853. case 'E' :
  854. case 'R' :
  855. case 'r' :
  856. if (len < 4)
  857. goto len_error ;
  858. to[0] = 0 ;
  859. to[1] = 0 ;
  860. #ifdef LITTLE_ENDIAN
  861. if (c == 'r') {
  862. to[2] = *from++ ;
  863. to[3] = *from++ ;
  864. }
  865. else {
  866. to[3] = *from++ ;
  867. to[2] = *from++ ;
  868. }
  869. #else
  870. to[2] = *from++ ;
  871. to[3] = *from++ ;
  872. #endif
  873. to += 4 ;
  874. len -= 4 ;
  875. break ;
  876. case 'I' : /* for SET of port indexes */
  877. if (len < 2)
  878. goto len_error ;
  879. #ifdef LITTLE_ENDIAN
  880. to[1] = *from++ ;
  881. to[0] = *from++ ;
  882. #else
  883. to[0] = *from++ ;
  884. to[1] = *from++ ;
  885. #endif
  886. to += 2 ;
  887. len -= 2 ;
  888. break ;
  889. case 'F' :
  890. case 'B' :
  891. if (len < 4)
  892. goto len_error ;
  893. len -= 4 ;
  894. to[0] = 0 ;
  895. to[1] = 0 ;
  896. to[2] = 0 ;
  897. to[3] = *from++ ;
  898. to += 4 ;
  899. break ;
  900. case 'C' :
  901. case 'T' :
  902. case 'L' :
  903. if (len < 4)
  904. goto len_error ;
  905. #ifdef LITTLE_ENDIAN
  906. to[3] = *from++ ;
  907. to[2] = *from++ ;
  908. to[1] = *from++ ;
  909. to[0] = *from++ ;
  910. #else
  911. to[0] = *from++ ;
  912. to[1] = *from++ ;
  913. to[2] = *from++ ;
  914. to[3] = *from++ ;
  915. #endif
  916. len -= 4 ;
  917. to += 4 ;
  918. break ;
  919. case '2' : /* PortMacIndicated */
  920. if (len < 4)
  921. goto len_error ;
  922. to[0] = 0 ;
  923. to[1] = 0 ;
  924. to[2] = *from++ ;
  925. to[3] = *from++ ;
  926. len -= 4 ;
  927. to += 4 ;
  928. break ;
  929. case '4' :
  930. if (len < 4)
  931. goto len_error ;
  932. to[0] = *from++ ;
  933. to[1] = *from++ ;
  934. to[2] = *from++ ;
  935. to[3] = *from++ ;
  936. len -= 4 ;
  937. to += 4 ;
  938. break ;
  939. case 'A' :
  940. if (len < 8)
  941. goto len_error ;
  942. to[0] = 0 ;
  943. to[1] = 0 ;
  944. memcpy((char *) to+2,(char *) from,6) ;
  945. to += 8 ;
  946. from += 8 ;
  947. len -= 8 ;
  948. break ;
  949. case '8' :
  950. if (len < 8)
  951. goto len_error ;
  952. memcpy((char *) to,(char *) from,8) ;
  953. to += 8 ;
  954. from += 8 ;
  955. len -= 8 ;
  956. break ;
  957. case 'D' :
  958. if (len < 32)
  959. goto len_error ;
  960. memcpy((char *) to,(char *) from,32) ;
  961. to += 32 ;
  962. from += 32 ;
  963. len -= 32 ;
  964. break ;
  965. case 'P' : /* timestamp is NOT swapped */
  966. if (len < 8)
  967. goto len_error ;
  968. to[0] = *from++ ;
  969. to[1] = *from++ ;
  970. to[2] = *from++ ;
  971. to[3] = *from++ ;
  972. to[4] = *from++ ;
  973. to[5] = *from++ ;
  974. to[6] = *from++ ;
  975. to[7] = *from++ ;
  976. to += 8 ;
  977. len -= 8 ;
  978. break ;
  979. default :
  980. SMT_PANIC(smc,SMT_E0119, SMT_E0119_MSG) ;
  981. break ;
  982. }
  983. }
  984. done:
  985. /*
  986. * make it even (in case of 'I' encoding)
  987. * note: len is DECREMENTED
  988. */
  989. if (len & 3) {
  990. to[0] = 0 ;
  991. to[1] = 0 ;
  992. to += 4 - (len & 3 ) ;
  993. len = len & ~ 3 ;
  994. }
  995. /* set type and length */
  996. pa->p_type = para ;
  997. pa->p_len = plen - len - PARA_LEN ;
  998. /* return values */
  999. pcon->pc_p = (void *) to ;
  1000. pcon->pc_len = len ;
  1001. return ;
  1002. sp_done:
  1003. len -= sp_len ;
  1004. to += sp_len ;
  1005. goto done ;
  1006. len_error:
  1007. /* parameter does not fit in frame */
  1008. pcon->pc_err = SMT_RDF_TOOLONG ;
  1009. return ;
  1010. wrong_error:
  1011. pcon->pc_err = SMT_RDF_LENGTH ;
  1012. }
  1013. /*
  1014. * set parameter
  1015. */
  1016. static int smt_set_para(struct s_smc *smc, struct smt_para *pa, int index,
  1017. int local, int set)
  1018. {
  1019. #define IFSET(x) if (set) (x)
  1020. const struct s_p_tab *pt ;
  1021. int len ;
  1022. char *from ;
  1023. char *to ;
  1024. const char *swap ;
  1025. char c ;
  1026. char *mib_addr ;
  1027. struct fddi_mib *mib ;
  1028. struct fddi_mib_m *mib_m = NULL;
  1029. struct fddi_mib_a *mib_a = NULL;
  1030. struct fddi_mib_p *mib_p = NULL;
  1031. int mac ;
  1032. int path ;
  1033. int port ;
  1034. SK_LOC_DECL(u_char,byte_val) ;
  1035. SK_LOC_DECL(u_short,word_val) ;
  1036. SK_LOC_DECL(u_long,long_val) ;
  1037. mac = index - INDEX_MAC ;
  1038. path = index - INDEX_PATH ;
  1039. port = index - INDEX_PORT ;
  1040. len = pa->p_len ;
  1041. from = (char *) (pa + 1 ) ;
  1042. mib = &smc->mib ;
  1043. switch (pa->p_type & 0xf000) {
  1044. case 0x1000 :
  1045. default :
  1046. mib_addr = (char *) mib ;
  1047. break ;
  1048. case 0x2000 :
  1049. if (mac < 0 || mac >= NUMMACS) {
  1050. return SMT_RDF_NOPARAM;
  1051. }
  1052. mib_m = &smc->mib.m[mac] ;
  1053. mib_addr = (char *) mib_m ;
  1054. from += 4 ; /* skip index */
  1055. len -= 4 ;
  1056. break ;
  1057. case 0x3000 :
  1058. if (path < 0 || path >= NUMPATHS) {
  1059. return SMT_RDF_NOPARAM;
  1060. }
  1061. mib_a = &smc->mib.a[path] ;
  1062. mib_addr = (char *) mib_a ;
  1063. from += 4 ; /* skip index */
  1064. len -= 4 ;
  1065. break ;
  1066. case 0x4000 :
  1067. if (port < 0 || port >= smt_mib_phys(smc)) {
  1068. return SMT_RDF_NOPARAM;
  1069. }
  1070. mib_p = &smc->mib.p[port_to_mib(smc,port)] ;
  1071. mib_addr = (char *) mib_p ;
  1072. from += 4 ; /* skip index */
  1073. len -= 4 ;
  1074. break ;
  1075. }
  1076. switch (pa->p_type) {
  1077. case SMT_P10F0 :
  1078. case SMT_P10F1 :
  1079. #ifdef ESS
  1080. case SMT_P10F2 :
  1081. case SMT_P10F3 :
  1082. case SMT_P10F4 :
  1083. case SMT_P10F5 :
  1084. case SMT_P10F6 :
  1085. case SMT_P10F7 :
  1086. #endif
  1087. #ifdef SBA
  1088. case SMT_P10F8 :
  1089. case SMT_P10F9 :
  1090. #endif
  1091. case SMT_P20F1 :
  1092. if (!local)
  1093. return SMT_RDF_NOPARAM;
  1094. break ;
  1095. }
  1096. pt = smt_get_ptab(pa->p_type) ;
  1097. if (!pt)
  1098. return (pa->p_type & 0xff00) ? SMT_RDF_NOPARAM :
  1099. SMT_RDF_ILLEGAL;
  1100. switch (pt->p_access) {
  1101. case AC_GR :
  1102. case AC_S :
  1103. break ;
  1104. default :
  1105. return SMT_RDF_ILLEGAL;
  1106. }
  1107. to = mib_addr + pt->p_offset ;
  1108. swap = pt->p_swap ; /* pointer to swap string */
  1109. while (swap && (c = *swap++)) {
  1110. switch(c) {
  1111. case 'b' :
  1112. to = (char *) &byte_val ;
  1113. break ;
  1114. case 'w' :
  1115. to = (char *) &word_val ;
  1116. break ;
  1117. case 'l' :
  1118. to = (char *) &long_val ;
  1119. break ;
  1120. case 'S' :
  1121. case 'E' :
  1122. case 'R' :
  1123. case 'r' :
  1124. if (len < 4) {
  1125. goto len_error ;
  1126. }
  1127. if (from[0] | from[1])
  1128. goto val_error ;
  1129. #ifdef LITTLE_ENDIAN
  1130. if (c == 'r') {
  1131. to[0] = from[2] ;
  1132. to[1] = from[3] ;
  1133. }
  1134. else {
  1135. to[1] = from[2] ;
  1136. to[0] = from[3] ;
  1137. }
  1138. #else
  1139. to[0] = from[2] ;
  1140. to[1] = from[3] ;
  1141. #endif
  1142. from += 4 ;
  1143. to += 2 ;
  1144. len -= 4 ;
  1145. break ;
  1146. case 'F' :
  1147. case 'B' :
  1148. if (len < 4) {
  1149. goto len_error ;
  1150. }
  1151. if (from[0] | from[1] | from[2])
  1152. goto val_error ;
  1153. to[0] = from[3] ;
  1154. len -= 4 ;
  1155. from += 4 ;
  1156. to += 4 ;
  1157. break ;
  1158. case 'C' :
  1159. case 'T' :
  1160. case 'L' :
  1161. if (len < 4) {
  1162. goto len_error ;
  1163. }
  1164. #ifdef LITTLE_ENDIAN
  1165. to[3] = *from++ ;
  1166. to[2] = *from++ ;
  1167. to[1] = *from++ ;
  1168. to[0] = *from++ ;
  1169. #else
  1170. to[0] = *from++ ;
  1171. to[1] = *from++ ;
  1172. to[2] = *from++ ;
  1173. to[3] = *from++ ;
  1174. #endif
  1175. len -= 4 ;
  1176. to += 4 ;
  1177. break ;
  1178. case 'A' :
  1179. if (len < 8)
  1180. goto len_error ;
  1181. if (set)
  1182. memcpy((char *) to,(char *) from+2,6) ;
  1183. to += 8 ;
  1184. from += 8 ;
  1185. len -= 8 ;
  1186. break ;
  1187. case '4' :
  1188. if (len < 4)
  1189. goto len_error ;
  1190. if (set)
  1191. memcpy((char *) to,(char *) from,4) ;
  1192. to += 4 ;
  1193. from += 4 ;
  1194. len -= 4 ;
  1195. break ;
  1196. case '8' :
  1197. if (len < 8)
  1198. goto len_error ;
  1199. if (set)
  1200. memcpy((char *) to,(char *) from,8) ;
  1201. to += 8 ;
  1202. from += 8 ;
  1203. len -= 8 ;
  1204. break ;
  1205. case 'D' :
  1206. if (len < 32)
  1207. goto len_error ;
  1208. if (set)
  1209. memcpy((char *) to,(char *) from,32) ;
  1210. to += 32 ;
  1211. from += 32 ;
  1212. len -= 32 ;
  1213. break ;
  1214. case 'P' : /* timestamp is NOT swapped */
  1215. if (set) {
  1216. to[0] = *from++ ;
  1217. to[1] = *from++ ;
  1218. to[2] = *from++ ;
  1219. to[3] = *from++ ;
  1220. to[4] = *from++ ;
  1221. to[5] = *from++ ;
  1222. to[6] = *from++ ;
  1223. to[7] = *from++ ;
  1224. }
  1225. to += 8 ;
  1226. len -= 8 ;
  1227. break ;
  1228. default :
  1229. SMT_PANIC(smc,SMT_E0120, SMT_E0120_MSG) ;
  1230. return SMT_RDF_ILLEGAL;
  1231. }
  1232. }
  1233. /*
  1234. * actions and internal updates
  1235. */
  1236. switch (pa->p_type) {
  1237. case SMT_P101A: /* fddiSMTConfigPolicy */
  1238. if (word_val & ~1)
  1239. goto val_error ;
  1240. IFSET(mib->fddiSMTConfigPolicy = word_val) ;
  1241. break ;
  1242. case SMT_P101B : /* fddiSMTConnectionPolicy */
  1243. if (!(word_val & POLICY_MM))
  1244. goto val_error ;
  1245. IFSET(mib->fddiSMTConnectionPolicy = word_val) ;
  1246. break ;
  1247. case SMT_P101D : /* fddiSMTTT_Notify */
  1248. if (word_val < 2 || word_val > 30)
  1249. goto val_error ;
  1250. IFSET(mib->fddiSMTTT_Notify = word_val) ;
  1251. break ;
  1252. case SMT_P101E : /* fddiSMTStatRptPolicy */
  1253. if (byte_val & ~1)
  1254. goto val_error ;
  1255. IFSET(mib->fddiSMTStatRptPolicy = byte_val) ;
  1256. break ;
  1257. case SMT_P101F : /* fddiSMTTrace_MaxExpiration */
  1258. /*
  1259. * note: lower limit trace_max = 6.001773... s
  1260. * NO upper limit
  1261. */
  1262. if (long_val < (long)0x478bf51L)
  1263. goto val_error ;
  1264. IFSET(mib->fddiSMTTrace_MaxExpiration = long_val) ;
  1265. break ;
  1266. #ifdef ESS
  1267. case SMT_P10F2 : /* fddiESSPayload */
  1268. if (long_val > 1562)
  1269. goto val_error ;
  1270. if (set && smc->mib.fddiESSPayload != long_val) {
  1271. smc->ess.raf_act_timer_poll = TRUE ;
  1272. smc->mib.fddiESSPayload = long_val ;
  1273. }
  1274. break ;
  1275. case SMT_P10F3 : /* fddiESSOverhead */
  1276. if (long_val < 50 || long_val > 5000)
  1277. goto val_error ;
  1278. if (set && smc->mib.fddiESSPayload &&
  1279. smc->mib.fddiESSOverhead != long_val) {
  1280. smc->ess.raf_act_timer_poll = TRUE ;
  1281. smc->mib.fddiESSOverhead = long_val ;
  1282. }
  1283. break ;
  1284. case SMT_P10F4 : /* fddiESSMaxTNeg */
  1285. if (long_val > -MS2BCLK(5) || long_val < -MS2BCLK(165))
  1286. goto val_error ;
  1287. IFSET(mib->fddiESSMaxTNeg = long_val) ;
  1288. break ;
  1289. case SMT_P10F5 : /* fddiESSMinSegmentSize */
  1290. if (long_val < 1 || long_val > 4478)
  1291. goto val_error ;
  1292. IFSET(mib->fddiESSMinSegmentSize = long_val) ;
  1293. break ;
  1294. case SMT_P10F6 : /* fddiESSCategory */
  1295. if ((long_val & 0xffff) != 1)
  1296. goto val_error ;
  1297. IFSET(mib->fddiESSCategory = long_val) ;
  1298. break ;
  1299. case SMT_P10F7 : /* fddiESSSyncTxMode */
  1300. if (word_val > 1)
  1301. goto val_error ;
  1302. IFSET(mib->fddiESSSynchTxMode = word_val) ;
  1303. break ;
  1304. #endif
  1305. #ifdef SBA
  1306. case SMT_P10F8 : /* fddiSBACommand */
  1307. if (byte_val != SB_STOP && byte_val != SB_START)
  1308. goto val_error ;
  1309. IFSET(mib->fddiSBACommand = byte_val) ;
  1310. break ;
  1311. case SMT_P10F9 : /* fddiSBAAvailable */
  1312. if (byte_val > 100)
  1313. goto val_error ;
  1314. IFSET(mib->fddiSBAAvailable = byte_val) ;
  1315. break ;
  1316. #endif
  1317. case SMT_P2020 : /* fddiMACRequestedPaths */
  1318. if ((word_val & (MIB_P_PATH_PRIM_PREFER |
  1319. MIB_P_PATH_PRIM_ALTER)) == 0 )
  1320. goto val_error ;
  1321. IFSET(mib_m->fddiMACRequestedPaths = word_val) ;
  1322. break ;
  1323. case SMT_P205F : /* fddiMACFrameErrorThreshold */
  1324. /* 0 .. ffff acceptable */
  1325. IFSET(mib_m->fddiMACFrameErrorThreshold = word_val) ;
  1326. break ;
  1327. case SMT_P2067 : /* fddiMACNotCopiedThreshold */
  1328. /* 0 .. ffff acceptable */
  1329. IFSET(mib_m->fddiMACNotCopiedThreshold = word_val) ;
  1330. break ;
  1331. case SMT_P2076: /* fddiMACMA_UnitdataEnable */
  1332. if (byte_val & ~1)
  1333. goto val_error ;
  1334. if (set) {
  1335. mib_m->fddiMACMA_UnitdataEnable = byte_val ;
  1336. queue_event(smc,EVENT_RMT,RM_ENABLE_FLAG) ;
  1337. }
  1338. break ;
  1339. case SMT_P20F1 : /* fddiMACT_Min */
  1340. IFSET(mib_m->fddiMACT_Min = long_val) ;
  1341. break ;
  1342. case SMT_P320F :
  1343. if (long_val > 1562)
  1344. goto val_error ;
  1345. IFSET(mib_a->fddiPATHSbaPayload = long_val) ;
  1346. #ifdef ESS
  1347. if (set)
  1348. ess_para_change(smc) ;
  1349. #endif
  1350. break ;
  1351. case SMT_P3210 :
  1352. if (long_val > 5000)
  1353. goto val_error ;
  1354. if (long_val != 0 && mib_a->fddiPATHSbaPayload == 0)
  1355. goto val_error ;
  1356. IFSET(mib_a->fddiPATHSbaOverhead = long_val) ;
  1357. #ifdef ESS
  1358. if (set)
  1359. ess_para_change(smc) ;
  1360. #endif
  1361. break ;
  1362. case SMT_P3213: /* fddiPATHT_Rmode */
  1363. /* no limit :
  1364. * 0 .. 343.597 => 0 .. 2e32 * 80nS
  1365. */
  1366. if (set) {
  1367. mib_a->fddiPATHT_Rmode = long_val ;
  1368. rtm_set_timer(smc) ;
  1369. }
  1370. break ;
  1371. case SMT_P3214 : /* fddiPATHSbaAvailable */
  1372. if (long_val > 0x00BEBC20L)
  1373. goto val_error ;
  1374. #ifdef SBA
  1375. if (set && mib->fddiSBACommand == SB_STOP)
  1376. goto val_error ;
  1377. #endif
  1378. IFSET(mib_a->fddiPATHSbaAvailable = long_val) ;
  1379. break ;
  1380. case SMT_P3215 : /* fddiPATHTVXLowerBound */
  1381. IFSET(mib_a->fddiPATHTVXLowerBound = long_val) ;
  1382. goto change_mac_para ;
  1383. case SMT_P3216 : /* fddiPATHT_MaxLowerBound */
  1384. IFSET(mib_a->fddiPATHT_MaxLowerBound = long_val) ;
  1385. goto change_mac_para ;
  1386. case SMT_P3217 : /* fddiPATHMaxT_Req */
  1387. IFSET(mib_a->fddiPATHMaxT_Req = long_val) ;
  1388. change_mac_para:
  1389. if (set && smt_set_mac_opvalues(smc)) {
  1390. RS_SET(smc,RS_EVENT) ;
  1391. smc->sm.please_reconnect = 1 ;
  1392. queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
  1393. }
  1394. break ;
  1395. case SMT_P400E : /* fddiPORTConnectionPolicies */
  1396. if (byte_val > 1)
  1397. goto val_error ;
  1398. IFSET(mib_p->fddiPORTConnectionPolicies = byte_val) ;
  1399. break ;
  1400. case SMT_P4011 : /* fddiPORTRequestedPaths */
  1401. /* all 3*8 bits allowed */
  1402. IFSET(memcpy((char *)mib_p->fddiPORTRequestedPaths,
  1403. (char *)&long_val,4)) ;
  1404. break ;
  1405. case SMT_P401F: /* fddiPORTMaint_LS */
  1406. if (word_val > 4)
  1407. goto val_error ;
  1408. IFSET(mib_p->fddiPORTMaint_LS = word_val) ;
  1409. break ;
  1410. case SMT_P403A : /* fddiPORTLer_Cutoff */
  1411. if (byte_val < 4 || byte_val > 15)
  1412. goto val_error ;
  1413. IFSET(mib_p->fddiPORTLer_Cutoff = byte_val) ;
  1414. break ;
  1415. case SMT_P403B : /* fddiPORTLer_Alarm */
  1416. if (byte_val < 4 || byte_val > 15)
  1417. goto val_error ;
  1418. IFSET(mib_p->fddiPORTLer_Alarm = byte_val) ;
  1419. break ;
  1420. /*
  1421. * Actions
  1422. */
  1423. case SMT_P103C : /* fddiSMTStationAction */
  1424. if (smt_action(smc,SMT_STATION_ACTION, (int) word_val, 0))
  1425. goto val_error ;
  1426. break ;
  1427. case SMT_P4046: /* fddiPORTAction */
  1428. if (smt_action(smc,SMT_PORT_ACTION, (int) word_val,
  1429. port_to_mib(smc,port)))
  1430. goto val_error ;
  1431. break ;
  1432. default :
  1433. break ;
  1434. }
  1435. return 0;
  1436. val_error:
  1437. /* parameter value in frame is out of range */
  1438. return SMT_RDF_RANGE;
  1439. len_error:
  1440. /* parameter value in frame is too short */
  1441. return SMT_RDF_LENGTH;
  1442. #if 0
  1443. no_author_error:
  1444. /* parameter not setable, because the SBA is not active
  1445. * Please note: we give the return code 'not authorizeed
  1446. * because SBA denied is not a valid return code in the
  1447. * PMF protocol.
  1448. */
  1449. return SMT_RDF_AUTHOR;
  1450. #endif
  1451. }
  1452. static const struct s_p_tab *smt_get_ptab(u_short para)
  1453. {
  1454. const struct s_p_tab *pt ;
  1455. for (pt = p_tab ; pt->p_num && pt->p_num != para ; pt++)
  1456. ;
  1457. return pt->p_num ? pt : NULL;
  1458. }
  1459. static int smt_mib_phys(struct s_smc *smc)
  1460. {
  1461. #ifdef CONCENTRATOR
  1462. SK_UNUSED(smc) ;
  1463. return NUMPHYS;
  1464. #else
  1465. if (smc->s.sas == SMT_SAS)
  1466. return 1;
  1467. return NUMPHYS;
  1468. #endif
  1469. }
  1470. static int port_to_mib(struct s_smc *smc, int p)
  1471. {
  1472. #ifdef CONCENTRATOR
  1473. SK_UNUSED(smc) ;
  1474. return p;
  1475. #else
  1476. if (smc->s.sas == SMT_SAS)
  1477. return PS;
  1478. return p;
  1479. #endif
  1480. }
  1481. #ifdef DEBUG
  1482. #ifndef BOOT
  1483. void dump_smt(struct s_smc *smc, struct smt_header *sm, char *text)
  1484. {
  1485. int len ;
  1486. struct smt_para *pa ;
  1487. char *c ;
  1488. int n ;
  1489. int nn ;
  1490. #ifdef LITTLE_ENDIAN
  1491. int smtlen ;
  1492. #endif
  1493. SK_UNUSED(smc) ;
  1494. #ifdef DEBUG_BRD
  1495. if (smc->debug.d_smtf < 2)
  1496. #else
  1497. if (debug.d_smtf < 2)
  1498. #endif
  1499. return ;
  1500. #ifdef LITTLE_ENDIAN
  1501. smtlen = sm->smt_len + sizeof(struct smt_header) ;
  1502. #endif
  1503. printf("SMT Frame [%s]:\nDA ",text) ;
  1504. dump_hex((char *) &sm->smt_dest,6) ;
  1505. printf("\tSA ") ;
  1506. dump_hex((char *) &sm->smt_source,6) ;
  1507. printf(" Class %x Type %x Version %x\n",
  1508. sm->smt_class,sm->smt_type,sm->smt_version) ;
  1509. printf("TID %lx\t\tSID ",sm->smt_tid) ;
  1510. dump_hex((char *) &sm->smt_sid,8) ;
  1511. printf(" LEN %x\n",sm->smt_len) ;
  1512. len = sm->smt_len ;
  1513. pa = (struct smt_para *) (sm + 1) ;
  1514. while (len > 0 ) {
  1515. int plen ;
  1516. #ifdef UNIX
  1517. printf("TYPE %x LEN %x VALUE\t",pa->p_type,pa->p_len) ;
  1518. #else
  1519. printf("TYPE %04x LEN %2x VALUE\t",pa->p_type,pa->p_len) ;
  1520. #endif
  1521. n = pa->p_len ;
  1522. if ( (n < 0 ) || (n > (int)(len - PARA_LEN))) {
  1523. n = len - PARA_LEN ;
  1524. printf(" BAD LENGTH\n") ;
  1525. break ;
  1526. }
  1527. #ifdef LITTLE_ENDIAN
  1528. smt_swap_para(sm,smtlen,0) ;
  1529. #endif
  1530. if (n < 24) {
  1531. dump_hex((char *)(pa+1),(int) n) ;
  1532. printf("\n") ;
  1533. }
  1534. else {
  1535. int first = 0 ;
  1536. c = (char *)(pa+1) ;
  1537. dump_hex(c,16) ;
  1538. printf("\n") ;
  1539. n -= 16 ;
  1540. c += 16 ;
  1541. while (n > 0) {
  1542. nn = (n > 16) ? 16 : n ;
  1543. if (n > 64) {
  1544. if (first == 0)
  1545. printf("\t\t\t...\n") ;
  1546. first = 1 ;
  1547. }
  1548. else {
  1549. printf("\t\t\t") ;
  1550. dump_hex(c,nn) ;
  1551. printf("\n") ;
  1552. }
  1553. n -= nn ;
  1554. c += 16 ;
  1555. }
  1556. }
  1557. #ifdef LITTLE_ENDIAN
  1558. smt_swap_para(sm,smtlen,1) ;
  1559. #endif
  1560. plen = (pa->p_len + PARA_LEN + 3) & ~3 ;
  1561. len -= plen ;
  1562. pa = (struct smt_para *)((char *)pa + plen) ;
  1563. }
  1564. printf("-------------------------------------------------\n\n") ;
  1565. }
  1566. void dump_hex(char *p, int len)
  1567. {
  1568. int n = 0 ;
  1569. while (len--) {
  1570. n++ ;
  1571. #ifdef UNIX
  1572. printf("%x%s",*p++ & 0xff,len ? ( (n & 7) ? " " : "-") : "") ;
  1573. #else
  1574. printf("%02x%s",*p++ & 0xff,len ? ( (n & 7) ? " " : "-") : "") ;
  1575. #endif
  1576. }
  1577. }
  1578. #endif /* no BOOT */
  1579. #endif /* DEBUG */
  1580. #endif /* no SLIM_SMT */