cmd9500.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689
  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2008-2009 SMSC
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. *
  19. ***************************************************************************
  20. * File: cmd9500.c
  21. */
  22. #ifdef USING_LINT
  23. #include "lint.h"
  24. #else //not USING_LINT
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <unistd.h>
  28. #include <string.h>
  29. #include <errno.h>
  30. #include <sys/socket.h>
  31. #include <sys/types.h>
  32. #include <net/if.h>
  33. #include <sys/ioctl.h>
  34. #include <net/if_arp.h>
  35. #include <arpa/inet.h>
  36. #endif //not USING_LINT
  37. #include "version.h"
  38. #include "ioctl_9500.h"
  39. char *iam=NULL;
  40. typedef enum _bool {
  41. false=0,
  42. true=1
  43. } bool;
  44. typedef struct _COMMAND_DATA {
  45. int hSockFD;
  46. struct ifreq IfReq;
  47. SMSC9500_IOCTL_DATA IoctlData;
  48. } COMMAND_DATA, *PCOMMAND_DATA;
  49. #define SOCKET int
  50. #define INVALID_SOCKET (-1)
  51. #define SOCKET_ERROR (-1)
  52. #define DEFAULT_PORT_NUMBER (11500U)
  53. SOCKET server_sock=INVALID_SOCKET;
  54. typedef struct _FLOW_PARAMS
  55. {
  56. unsigned long MeasuredMaxThroughput;
  57. unsigned long MeasuredMaxPacketCount;
  58. unsigned long MaxThroughput;
  59. unsigned long MaxPacketCount;
  60. unsigned long PacketCost;
  61. unsigned long BurstPeriod;
  62. unsigned long MaxWorkLoad;
  63. unsigned long IntDeas;
  64. } FLOW_PARAMS, * PFLOW_PARAMS;
  65. bool ParseNumber(const char *str,unsigned long *number);
  66. void DisplayUsage(void);
  67. void GetMacAddress(PCOMMAND_DATA commandData);
  68. void SetMacAddress(PCOMMAND_DATA commandData,unsigned long addrh,unsigned long addrl);
  69. void LoadMacAddress(PCOMMAND_DATA commandData);
  70. void SaveMacAddress(PCOMMAND_DATA commandData,unsigned long addrh,unsigned long addrl);
  71. void LanDumpRegs(PCOMMAND_DATA commandData);
  72. void MacDumpRegs(PCOMMAND_DATA commandData);
  73. void DumpEEPROM(PCOMMAND_DATA commandData);
  74. void DumpTemp(PCOMMAND_DATA commandData);
  75. void PhyDumpRegs(PCOMMAND_DATA commandData);
  76. void SetDebugMode(PCOMMAND_DATA commandData,
  77. unsigned long debug_mode);
  78. void SetLinkMode(PCOMMAND_DATA commandData,
  79. unsigned long link_mode);
  80. void SetPowerMode(PCOMMAND_DATA commandData,
  81. unsigned long power_mode);
  82. void GetLinkMode(PCOMMAND_DATA commandData);
  83. void CheckLink(PCOMMAND_DATA commandData);
  84. void GetPowerMode(PCOMMAND_DATA commandData);
  85. void GetFlowParams(PCOMMAND_DATA commandData);
  86. void GetConfiguration(PCOMMAND_DATA commandData);
  87. void SetAutoMdixSts(PCOMMAND_DATA commandData,unsigned int AutoMdix);
  88. void GetAutoMdixSts(PCOMMAND_DATA commandData);
  89. #ifdef RW_MEM
  90. void ReadByte(PCOMMAND_DATA commandData,unsigned long address);
  91. void ReadWord(PCOMMAND_DATA commandData, unsigned long address);
  92. void ReadDWord(PCOMMAND_DATA commandData,unsigned long address);
  93. void WriteByte(PCOMMAND_DATA commandData,unsigned long address, unsigned long data);
  94. void WriteWord(PCOMMAND_DATA commandData,unsigned long address, unsigned long data);
  95. void WriteDWord(PCOMMAND_DATA commandData,unsigned long address, unsigned long data);
  96. #endif //RW_MEM
  97. void LanGetReg(PCOMMAND_DATA commandData,unsigned long address);
  98. void LanSetReg(PCOMMAND_DATA commandData, unsigned long address, unsigned long data);
  99. void MacGetReg(PCOMMAND_DATA commandData, unsigned long address);
  100. void MacSetReg(
  101. PCOMMAND_DATA commandData,
  102. unsigned long address, unsigned long data);
  103. void PhyGetReg(PCOMMAND_DATA commandData, unsigned long address);
  104. void PhySetReg(
  105. PCOMMAND_DATA commandData,
  106. unsigned long address, unsigned long data);
  107. bool Initialize(PCOMMAND_DATA commandData,const char *ethName);
  108. bool ReceiveULong(SOCKET sock,unsigned long * pDWord);
  109. bool SendULong(SOCKET sock,unsigned long data);
  110. unsigned long ReadThroughput(char * fileName);
  111. bool ParseNumber(const char *str,unsigned long *number) {
  112. if(str==NULL) return false;
  113. if(str[0]==0) return false;
  114. if((str[0]=='0')&&(str[1]=='x')) {
  115. if(sscanf(&(str[2]),"%lx",number)==1) {
  116. return true;
  117. }
  118. }
  119. if(sscanf(str,"%ld",number)==1) {
  120. return true;
  121. }
  122. return false;
  123. }
  124. bool ParseString(const char *str, char **fileName)
  125. {
  126. if(*fileName)free(*fileName);
  127. *fileName = malloc(strlen(str)+1);
  128. strcpy(*fileName, str);
  129. }
  130. void DisplayUsage(void) {
  131. printf("usage: %s [-h] [-e adaptername] [-c command] [-a address] [-d data] [-f filename]\n",iam);
  132. printf(" -h displays this usage information, other options ignored.\n");
  133. printf(" -e specifies the adapter name (eth0,eth1...)\n");
  134. printf(" if not specified then %s will attempt to\n",iam);
  135. printf(" auto detect.\n");
  136. printf(" -c specifies the command code\n");
  137. printf(" GET_CONFIG = gets internal variables of driver\n");
  138. printf(" DUMP_REGS = dumps the LAN9500 memory mapped registers\n");
  139. printf(" DUMP_MAC = dumps the LAN9500 MAC registers\n");
  140. printf(" DUMP_PHY = dumps the LAN9500 PHY registers\n");
  141. printf(" DUMP_EEPROM = dumps 512 bytes of the EEPROM\n");
  142. printf(" GET_MAC = gets MAC address from ADDRH and ADDRL\n");
  143. printf(" SET_MAC = sets MAC address in ADDRH and ADDRL\n");
  144. printf(" -a specifies the value to write to ADDRH\n");
  145. printf(" -d specifies the value to write to ADDRL\n");
  146. printf(" LOAD_MAC = causes the LAN9500 to reload the MAC address\n");
  147. printf(" from the external EEPROM. Also displays it\n");
  148. printf(" SAVE_MAC = writes a MAC address to the EEPROM\n");
  149. printf(" -a specifies the part of the MAC address that would\n");
  150. printf(" appear in ADDRH\n");
  151. printf(" -d specifies the part of the MAC address that would\n");
  152. printf(" appear in ADDRL\n");
  153. printf(" SET_DEBUG = sets the driver's internal debug_mode value\n");
  154. printf(" -d specifies the debug mode\n");
  155. printf(" 0x01, bit 0, enables trace messages\n");
  156. printf(" 0x02, bit 1, enables warning messages\n");
  157. printf(" 0x04, bit 2, enables GPO signals\n");
  158. printf(" NOTE: trace, and warning messages will only show if\n");
  159. printf(" they have been turned on at driver compile time.\n");
  160. printf(" SET_LINK = sets the driver's internal link_mode value\n");
  161. printf(" and also attempts to relink with the new setting\n");
  162. printf(" -d specifies the link mode\n");
  163. printf(" 1 = 10HD, 2 = 10FD, 4 = 100HD, 8 = 100FD\n");
  164. printf(" to specify multiple link modes, add the values\n");
  165. printf(" of each mode you want and use the sum as the link mode\n");
  166. printf(" GET_LINK = gets the driver's internal link_mode value\n");
  167. printf(" CHECK_LINK = causes the driver to recheck its link status\n");
  168. printf(" SET_AMDIX = sets the Auto Mdix value\n");
  169. printf(" -d specifies the Auto Mdix value\n");
  170. printf(" 0 = Straight Cable, 1 = CrossOver Cable, 2 = Enable AMDIX\n");
  171. printf(" GET_AMDIX = gets the Auto Mdix value\n");
  172. printf(" Warning!! the following read and write commands may cause\n");
  173. printf(" unpredictable results, including system lock up or crash.\n");
  174. printf(" Use with caution\n");
  175. printf(" READ_REG = reads a value from the LAN9500 Memory Map\n");
  176. printf(" -a specifies offset into LAN9500 Memory Map\n");
  177. printf(" WRITE_REG = writes a value to the LAN9500 Memory Map\n");
  178. printf(" -a specifies offset into LAN9500 Memory Map\n");
  179. printf(" -d specifies data to write in HEX form\n");
  180. printf(" READ_MAC = reads a value from the LAN9500 Mac registers\n");
  181. printf(" -a specifies the Mac register index\n");
  182. printf(" WRITE_MAC = writes a value to the LAN9500 Mac registers\n");
  183. printf(" -a specifies the Mac register index\n");
  184. printf(" -d specifies data to write in HEX form\n");
  185. printf(" READ_PHY = reads a value from the LAN9500 Phy registers\n");
  186. printf(" -a specifies the Phy register index\n");
  187. printf(" WRITE_PHY = writes a value to the LAN9500 Phy registers\n");
  188. printf(" -a specifies the Phy register index\n");
  189. printf(" -d specifies data to write in HEX form\n");
  190. printf(" READ_EEPROM = reads a value from the LAN9500 eeprom\n");
  191. printf(" -a specifies the eeprom offset\n");
  192. printf(" WRITE_EEPROM = writes a value to the LAN9500 eeprom\n");
  193. printf(" -a specifies the eeprom offset\n");
  194. printf(" -d specifies data to write in HEX form\n");
  195. printf(" WRITE_FILE_TO_EEPROM = writes contents from a binary file into the LAN9500 eeprom\n");
  196. printf(" -f specifies the binary file name\n");
  197. printf(" READ_EEPROM_TO_FILE = reads the whole LAN9500 eeprom and write into a binary file\n");
  198. printf(" -f specifies the binary file name\n");
  199. printf(" VERIFY_EEPROM_WITH_FILE = compares the LAN9500 eeprom with the binary file\n");
  200. printf(" -f specifies the binary file name\n");
  201. printf(" GET_ERRORS = reads Linux urb error counters\n");
  202. #ifdef RW_MEM
  203. printf(" READ_BYTE = reads a byte from a location in memory\n");
  204. printf(" -a address\n");
  205. printf(" READ_WORD = reads a word from a location in memory\n");
  206. printf(" -a address\n");
  207. printf(" READ_DWORD = reads a dword from a location in memory\n");
  208. printf(" -a address\n");
  209. printf(" WRITE_BYTE = write a byte to a location in memory\n");
  210. printf(" -a address -d data\n");
  211. printf(" WRITE_WORD = write a word to a location in memory\n");
  212. printf(" -a address -d data\n");
  213. printf(" WRITE_DWORD = write a dword to a location in memory\n");
  214. printf(" -a address -d data\n");
  215. #endif //RW_MEM
  216. printf(" -a specifies the address, index, or offset of a register\n");
  217. printf(" -d specifies the data to write to a register\n");
  218. printf(" can be decimal or hexadecimal\n");
  219. printf(" -f specifies the file name\n");
  220. }
  221. void GetMacAddress(PCOMMAND_DATA commandData)
  222. {
  223. if(commandData==NULL) return;
  224. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  225. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  226. commandData->IoctlData.dwCommand=COMMAND_GET_MAC_ADDRESS;
  227. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  228. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  229. printf("Mac Address == %02lX %02lX %02lX %02lX %02lX %02lX \n", commandData->IoctlData.Data[1] & 0xFF,
  230. (commandData->IoctlData.Data[1] >> 8) & 0xFF,
  231. (commandData->IoctlData.Data[1] >> 16) & 0xFF, (commandData->IoctlData.Data[1] >> 24) & 0xFF,
  232. commandData->IoctlData.Data[0] & 0xFF, (commandData->IoctlData.Data[0] >> 8) & 0xFF);
  233. } else {
  234. printf("Failed to Get Mac Address\n");
  235. }
  236. }
  237. void SetMacAddress(PCOMMAND_DATA commandData,unsigned long addrh,unsigned long addrl)
  238. {
  239. if(commandData==NULL) return;
  240. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  241. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  242. commandData->IoctlData.dwCommand=COMMAND_SET_MAC_ADDRESS;
  243. commandData->IoctlData.Data[0]=addrh;
  244. commandData->IoctlData.Data[1]=addrl;
  245. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  246. if(commandData->IoctlData.dwSignature!=SMSC9500_DRIVER_SIGNATURE) {
  247. printf("Failed to Set Mac Address\n");
  248. }
  249. }
  250. void LoadMacAddress(PCOMMAND_DATA commandData)
  251. {
  252. if(commandData==NULL) return;
  253. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  254. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  255. commandData->IoctlData.dwCommand=COMMAND_LOAD_MAC_ADDRESS;
  256. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  257. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  258. printf("Mac Address == %02lX %02lX %02lX %02lX %02lX %02lX \n", commandData->IoctlData.Data[1] & 0xFF,
  259. (commandData->IoctlData.Data[1] >> 8) & 0xFF,
  260. (commandData->IoctlData.Data[1] >> 16) & 0xFF, (commandData->IoctlData.Data[1] >> 24) & 0xFF,
  261. commandData->IoctlData.Data[0] & 0xFF, (commandData->IoctlData.Data[0] >> 8) & 0xFF);
  262. } else {
  263. printf("Failed to Load Mac Address\n");
  264. }
  265. }
  266. void SaveMacAddress(PCOMMAND_DATA commandData,unsigned long addrh,unsigned long addrl)
  267. {
  268. if(commandData==NULL) return;
  269. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  270. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  271. commandData->IoctlData.dwCommand=COMMAND_SAVE_MAC_ADDRESS;
  272. commandData->IoctlData.Data[0]=addrh;
  273. commandData->IoctlData.Data[1]=addrl;
  274. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  275. if(commandData->IoctlData.dwSignature!=SMSC9500_DRIVER_SIGNATURE) {
  276. printf("Failed to Save Mac Address\n");
  277. }
  278. }
  279. void LanDumpRegs(PCOMMAND_DATA commandData)
  280. {
  281. if(commandData==NULL) return;
  282. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  283. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  284. commandData->IoctlData.dwCommand=COMMAND_DUMP_LAN_REGS;
  285. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  286. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  287. printf("offset 0x00, ID_REV = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_ID_REV]);
  288. printf("offset 0x04 FPGA_REV = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_FPGA_REV]);
  289. printf("offset 0x08 INT_STS = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_INT_STS]);
  290. printf("offset 0x0C RX_CFG = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_RX_CFG]);
  291. printf("offset 0x10 TX_CFG = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_TX_CFG]);
  292. printf("offset 0x14 HW_CFG = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_HW_CFG]);
  293. printf("offset 0x18 RX_FIFO_INF = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_RX_FIFO_INF]);
  294. printf("offset 0x1C TX_FIFO_INF = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_TX_FIFO_INF]);
  295. printf("offset 0x20 PMT_CTRL = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_PMT_CTRL]);
  296. printf("offset 0x24 LED_GPIO_CFG = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_LED_GPIO_CFG]);
  297. printf("offset 0x28 GPIO_CFG = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_GPIO_CFG]);
  298. printf("offset 0x2C AFC_CFG = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_AFC_CFG]);
  299. printf("offset 0x30 E2P_CMD = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_E2P_CMD]);
  300. printf("offset 0x34 E2P_DATA = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_E2P_DATA]);
  301. printf("offset 0x38 BURST_CAP = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_BURST_CAP]);
  302. printf("offset 0x3C STRAP_DBG = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_STRAP_DBG]);
  303. printf("offset 0x40 DP_SEL = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_DP_SEL]);
  304. printf("offset 0x44 DP_CMD = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_DP_CMD]);
  305. printf("offset 0x48 DP_ADDR = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_DP_ADDR]);
  306. printf("offset 0x4C DP_DATA0 = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_DP_DATA0]);
  307. printf("offset 0x50 DP_DATA1 = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_DP_DATA1]);
  308. printf("offset 0x64 GPIO_WAKE = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_GPIO_WAKE]);
  309. printf("offset 0x68 INT_EP_CTL = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_INT_EP_CTL]);
  310. printf("offset 0x6C BULK_IN_DLY = 0x%08lX\n", commandData->IoctlData.Data[LAN_REG_BULK_IN_DLY]);
  311. } else {
  312. printf("Failed to DUMP registers\n");
  313. }
  314. }
  315. void MacDumpRegs(PCOMMAND_DATA commandData)
  316. {
  317. if(commandData==NULL) return;
  318. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  319. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  320. commandData->IoctlData.dwCommand=COMMAND_DUMP_MAC_REGS;
  321. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  322. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  323. printf("offset 0x100, MAC_CR = 0x%08lX\n",commandData->IoctlData.Data[MAC_REG_MAC_CR]);
  324. printf("offset 0x104, ADDRH = 0x%08lX\n",commandData->IoctlData.Data[MAC_REG_ADDRH]);
  325. printf("offset 0x108, ADDRL = 0x%08lX\n",commandData->IoctlData.Data[MAC_REG_ADDRL]);
  326. printf("offset 0x10C, HASHH = 0x%08lX\n",commandData->IoctlData.Data[MAC_REG_HASHH]);
  327. printf("offset 0x110, HASHL = 0x%08lX\n",commandData->IoctlData.Data[MAC_REG_HASHL]);
  328. printf("offset 0x114, MII_ACC = 0x%08lX\n",commandData->IoctlData.Data[MAC_REG_MII_ADDR]);
  329. printf("offset 0x118, MII_DATA = 0x%08lX\n",commandData->IoctlData.Data[MAC_REG_MII_DATA]);
  330. printf("offset 0x11C, FLOW = 0x%08lX\n",commandData->IoctlData.Data[MAC_REG_FLOW]);
  331. printf("offset 0x120, VLAN1 = 0x%08lX\n",commandData->IoctlData.Data[MAC_REG_VLAN1]);
  332. printf("offset 0x124, VLAN2 = 0x%08lX\n",commandData->IoctlData.Data[MAC_REG_VLAN2]);
  333. printf("offset 0x128, WUFF = 0x%08lX\n",commandData->IoctlData.Data[MAC_REG_WUFF]);
  334. printf("offset 0x12C, WUCSR = 0x%08lX\n",commandData->IoctlData.Data[MAC_REG_WUCSR]);
  335. printf("offset 0x130, COE_CR = 0x%08lX\n",commandData->IoctlData.Data[MAC_REG_COE_CR]);
  336. } else {
  337. printf("Failed to Dump Mac Registers\n");
  338. }
  339. }
  340. void DumpEEPROM(PCOMMAND_DATA commandData)
  341. {
  342. int i,j;
  343. unsigned char* value;
  344. int eepromSize;
  345. if(commandData==NULL) return;
  346. eepromSize = GetEepromSize(commandData) * 128;
  347. if(eepromSize == 0){
  348. printf("EEPROM doesn't exist!\n");
  349. return;
  350. }
  351. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  352. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  353. commandData->IoctlData.dwCommand=COMMAND_DUMP_EEPROM;
  354. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  355. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  356. value = (unsigned char*)&commandData->IoctlData.Data[0];
  357. printf("Offset Values\n");
  358. printf("------ ------\n");
  359. for(i=0; i<eepromSize/16; i++){
  360. printf("0x%04lX ", (long unsigned int)i*16);
  361. for(j=0; j<16; j++){
  362. printf("%02lX ", (long unsigned int)value[i*16+j]);
  363. }
  364. printf("\n");
  365. }
  366. } else {
  367. printf("Failed to Dump EEPROM\n");
  368. }
  369. }
  370. void DumpTemp(PCOMMAND_DATA commandData)
  371. {
  372. if(commandData==NULL) return;
  373. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  374. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  375. commandData->IoctlData.dwCommand=COMMAND_DUMP_TEMP;
  376. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  377. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  378. unsigned long c=0;
  379. for(c=0;c<0x10;c++) {
  380. printf("temp[0x%02lX]=0x%08lX, ",c,commandData->IoctlData.Data[c]);
  381. printf("temp[0x%02lX]=0x%08lX, ",c+0x10,commandData->IoctlData.Data[c+0x10]);
  382. printf("temp[0x%02lX]=0x%08lX, ",c+0x20,commandData->IoctlData.Data[c+0x20]);
  383. printf("temp[0x%02lX]=0x%08lX\n",c+0x30,commandData->IoctlData.Data[c+0x30]);
  384. }
  385. } else {
  386. printf("Failed to dump temp data.\n");
  387. }
  388. }
  389. void PhyDumpRegs(PCOMMAND_DATA commandData)
  390. {
  391. if(commandData==NULL) return;
  392. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  393. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  394. commandData->IoctlData.dwCommand=COMMAND_DUMP_PHY_REGS;
  395. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  396. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  397. printf("index 0, Basic Control Reg = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_BCR]);
  398. printf("index 1, Basic Status Reg = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_BSR]);
  399. printf("index 2, PHY identifier 1 = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_ID1]);
  400. printf("index 3, PHY identifier 2 = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_ID2]);
  401. printf("index 4, Auto Negotiation Advertisement Reg = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_ANEG_ADV]);
  402. printf("index 5, Auto Negotiation Link Partner Ability Reg = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_ANEG_LPA]);
  403. printf("index 6, Auto Negotiation Expansion Register = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_ANEG_ER]);
  404. printf("index 16, Silicon Revision Reg = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_SILICON_REV]);
  405. printf("index 17, Mode Control/Status Reg = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_MODE_CTRL_STS]);
  406. printf("index 18, Special Modes = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_SPECIAL_MODES]);
  407. printf("index 20, TSTCNTL = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_TSTCNTL]);
  408. printf("index 21, TSTREAD1 = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_TSTREAD1]);
  409. printf("index 22, TSTREAD2 = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_TSTREAD2]);
  410. printf("index 23, TSTWRITE = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_TSTWRITE]);
  411. printf("index 27, Control/Status Indication = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_SPECIAL_CTRL_STS]);
  412. printf("index 28, Special internal testability = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_SITC]);
  413. printf("index 29, Interrupt Source Register = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_INT_SRC]);
  414. printf("index 30, Interrupt Mask Register = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_INT_MASK]);
  415. printf("index 31, PHY Special Control/Status Register = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_SPECIAL]);
  416. } else {
  417. printf("Failed to DUMP Phy Registers\n");
  418. }
  419. }
  420. void SetDebugMode(PCOMMAND_DATA commandData,
  421. unsigned long debug_mode)
  422. {
  423. if(commandData==NULL) return;
  424. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  425. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  426. commandData->IoctlData.dwCommand=COMMAND_SET_DEBUG_MODE;
  427. commandData->IoctlData.Data[0]=debug_mode;
  428. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  429. if(commandData->IoctlData.dwSignature!=SMSC9500_DRIVER_SIGNATURE) {
  430. printf("Failed to set debug mode.\n");
  431. }
  432. }
  433. void SetLinkMode(PCOMMAND_DATA commandData,
  434. unsigned long link_mode)
  435. {
  436. if(link_mode<=0x7F) {
  437. if(commandData==NULL) return;
  438. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  439. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  440. commandData->IoctlData.dwCommand=COMMAND_SET_LINK_MODE;
  441. commandData->IoctlData.Data[0]=link_mode;
  442. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  443. if(commandData->IoctlData.dwSignature!=SMSC9500_DRIVER_SIGNATURE) {
  444. printf("Failed to set link mode.\n");
  445. }
  446. } else {
  447. printf("Invalid Link Mode, %ld\n",link_mode);
  448. }
  449. }
  450. void SetAutoMdixSts(PCOMMAND_DATA commandData, unsigned int AutoMdix)
  451. {
  452. // if(AutoMdix<=2) {
  453. if(commandData==NULL) return;
  454. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  455. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  456. commandData->IoctlData.dwCommand=COMMAND_SET_AMDIX_STS;
  457. commandData->IoctlData.Data[0]=AutoMdix;
  458. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  459. if(commandData->IoctlData.dwSignature!=SMSC9500_DRIVER_SIGNATURE) {
  460. printf("Failed to set AMDIX State.\n");
  461. }
  462. // } else {
  463. // printf("Invalid AutoMdix value, %d\n",AutoMdix);
  464. // }
  465. }
  466. void GetLinkMode(PCOMMAND_DATA commandData)
  467. {
  468. if(commandData==NULL) return;
  469. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  470. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  471. commandData->IoctlData.dwCommand=COMMAND_GET_LINK_MODE;
  472. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  473. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  474. unsigned long link_mode=commandData->IoctlData.Data[0];
  475. printf("link_mode == 0x%02lX == %s,%s,%s,%s,%s,%s,%s\n",
  476. link_mode,
  477. (link_mode&0x40)?"ANEG":"",
  478. (link_mode&0x20)?"SYMP":"",
  479. (link_mode&0x10)?"ASYMP":"",
  480. (link_mode&0x08)?"100FD":"",
  481. (link_mode&0x04)?"100HD":"",
  482. (link_mode&0x02)?"10FD":"",
  483. (link_mode&0x01)?"10HD":"");
  484. } else {
  485. printf("Failed to get link mode\n");
  486. }
  487. }
  488. void GetAutoMdixSts(PCOMMAND_DATA commandData)
  489. {
  490. if(commandData==NULL) return;
  491. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  492. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  493. commandData->IoctlData.dwCommand=COMMAND_GET_AMDIX_STS;
  494. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  495. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  496. printf("AutoMdix value = 0x%x\n", (unsigned int)commandData->IoctlData.Data[0]);
  497. } else {
  498. printf("Failed to get AutoMdix value.\n");
  499. }
  500. }
  501. void CheckLink(PCOMMAND_DATA commandData)
  502. {
  503. if(commandData==NULL) return;
  504. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  505. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  506. commandData->IoctlData.dwCommand=COMMAND_CHECK_LINK;
  507. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  508. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  509. printf("Checked link successfully\n");
  510. } else {
  511. printf("Failed to check link\n");
  512. }
  513. }
  514. void GetFlowParams(PCOMMAND_DATA commandData)
  515. {
  516. if(commandData==NULL) return;
  517. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  518. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  519. commandData->IoctlData.dwCommand=COMMAND_GET_FLOW_PARAMS;
  520. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  521. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  522. const unsigned long * data=commandData->IoctlData.Data;
  523. printf("Flow Control Parameters\n");
  524. printf(" RxFlowMeasuredMaxThroughput = 0x%08lX\n",data[0]);
  525. printf(" RxFlowMeasuredMaxPacketCount = 0x%08lX\n",data[1]);
  526. printf(" RxFlowParameters.MaxThroughput = 0x%08lX\n",data[2]);
  527. printf(" RxFlowParameters.MaxPacketCount = 0x%08lX\n",data[3]);
  528. printf(" RxFlowParameters.PacketCost = 0x%08lX\n",data[4]);
  529. printf(" RxFlowParameters.BurstPeriod = 0x%08lX\n",data[5]);
  530. printf(" RxFlowMaxWorkLoad = 0x%08lX\n",data[6]);
  531. printf(" INT_CFG.INT_DEAS = 0x%08lX\n",data[7]);
  532. } else {
  533. printf("Failed to get flow control parameters\n");
  534. }
  535. }
  536. void GetConfiguration(PCOMMAND_DATA commandData)
  537. {
  538. if(commandData==NULL) return;
  539. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  540. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  541. commandData->IoctlData.dwCommand=COMMAND_GET_CONFIGURATION;
  542. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  543. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  544. const unsigned long * data=commandData->IoctlData.Data;
  545. printf("Compiled: %s\n",commandData->IoctlData.Strng1);
  546. printf("Driver Version = %lX.%02lX.%02lX\n",
  547. data[0]>>16&0xFF, data[0]>>8&0xFF, data[0]&0xFFUL);
  548. printf("Driver Parameters\n");
  549. printf(" link_mode = 0x%08lX\n",data[1]);
  550. printf(" mac_addr_hi16 = 0x%08lX\n",data[2]);
  551. printf(" mac_addr_lo32 = 0x%08lX\n",data[3]);
  552. printf(" debug_mode = 0x%08lX\n",data[4]);
  553. printf("privateData\n");
  554. printf(" dwIdRev = 0x%08lX\n",data[5]);
  555. printf(" dwFpgaRev = 0x%08lX\n",data[6]);
  556. printf(" bPhyAddress = 0x%08lX\n",data[7]);
  557. printf(" dwPhyId = 0x%08lX\n",data[8]);
  558. printf(" bPhyModel = 0x%08lX\n",data[9]);
  559. printf(" bPhyRev = 0x%08lX\n",data[10]);
  560. printf(" dwLinkSpeed = 0x%08lX\n",data[11]);
  561. printf(" eepromSize = %d\n", (unsigned int)data[12] * 128);
  562. } else {
  563. printf("Failed to get driver configuration\n");
  564. }
  565. }
  566. void GetErrors(PCOMMAND_DATA commandData)
  567. {
  568. if(commandData==NULL) return;
  569. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  570. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  571. commandData->IoctlData.dwCommand=COMMAND_GET_ERRORS;
  572. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  573. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  574. const unsigned long * data=commandData->IoctlData.Data;
  575. printf(" TX EPIPE = 0x%08lX\n",data[0]);
  576. printf(" TX EPROTO = 0x%08lX\n",data[1]);
  577. printf(" TX ETIMWOUT = 0x%08lX\n",data[2]);
  578. printf(" TX EILSEQ = 0x%08lX\n",data[3]);
  579. printf(" RX EPIPE = 0x%08lX\n",data[4]);
  580. printf(" RX EPROTO = 0x%08lX\n",data[5]);
  581. printf(" RX ETIMWOUT = 0x%08lX\n",data[6]);
  582. printf(" RX EILSEQ = 0x%08lX\n",data[7]);
  583. printf(" RX EOVERFLOW = 0x%08lX\n",data[8]);
  584. } else {
  585. printf("Failed to get driver configuration\n");
  586. }
  587. }
  588. #ifdef RW_MEM
  589. void ReadByte(PCOMMAND_DATA commandData,unsigned long address)
  590. {
  591. if(commandData==NULL) return;
  592. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  593. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  594. commandData->IoctlData.dwCommand=COMMAND_READ_BYTE;
  595. commandData->IoctlData.Data[0]=address;
  596. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  597. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  598. printf("Memory Address == 0x%08lX, Read Value == 0x%02lX\n",
  599. commandData->IoctlData.Data[0],
  600. commandData->IoctlData.Data[1]&0xFFUL);
  601. } else {
  602. printf("Failed to Read Memory\n");
  603. }
  604. }
  605. void ReadWord(PCOMMAND_DATA commandData, unsigned long address)
  606. {
  607. if(commandData==NULL) return;
  608. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  609. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  610. commandData->IoctlData.dwCommand=COMMAND_READ_WORD;
  611. commandData->IoctlData.Data[0]=address;
  612. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  613. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  614. printf("Memory Address == 0x%08lX, Read Value == 0x%04lX\n",
  615. commandData->IoctlData.Data[0],
  616. commandData->IoctlData.Data[1]&0xFFFFUL);
  617. } else {
  618. printf("Failed to Read Memory\n");
  619. }
  620. }
  621. void ReadDWord(PCOMMAND_DATA commandData,unsigned long address)
  622. {
  623. if(commandData==NULL) return;
  624. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  625. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  626. commandData->IoctlData.dwCommand=COMMAND_READ_DWORD;
  627. commandData->IoctlData.Data[0]=address;
  628. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  629. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  630. printf("Memory Address == 0x%08lX, Read Value == 0x%08lX\n",
  631. commandData->IoctlData.Data[0],
  632. commandData->IoctlData.Data[1]);
  633. } else {
  634. printf("Failed to Read Memory\n");
  635. }
  636. }
  637. void WriteByte(PCOMMAND_DATA commandData,unsigned long address, unsigned long data)
  638. {
  639. if(commandData==NULL) return;
  640. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  641. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  642. commandData->IoctlData.dwCommand=COMMAND_WRITE_BYTE;
  643. commandData->IoctlData.Data[0]=address;
  644. commandData->IoctlData.Data[1]=data&0xFFUL;
  645. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  646. if(commandData->IoctlData.dwSignature!=SMSC9500_DRIVER_SIGNATURE) {
  647. printf("Failed to Write Memory\n");
  648. }
  649. }
  650. void WriteWord(PCOMMAND_DATA commandData,unsigned long address, unsigned long data)
  651. {
  652. if(commandData==NULL) return;
  653. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  654. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  655. commandData->IoctlData.dwCommand=COMMAND_WRITE_WORD;
  656. commandData->IoctlData.Data[0]=address;
  657. commandData->IoctlData.Data[1]=data&0xFFFFUL;
  658. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  659. if(commandData->IoctlData.dwSignature!=SMSC9500_DRIVER_SIGNATURE) {
  660. printf("Failed to Write Memory\n");
  661. }
  662. }
  663. void WriteDWord(PCOMMAND_DATA commandData,unsigned long address, unsigned long data)
  664. {
  665. if(commandData==NULL) return;
  666. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  667. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  668. commandData->IoctlData.dwCommand=COMMAND_WRITE_DWORD;
  669. commandData->IoctlData.Data[0]=address;
  670. commandData->IoctlData.Data[1]=data;
  671. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  672. if(commandData->IoctlData.dwSignature!=SMSC9500_DRIVER_SIGNATURE) {
  673. printf("Failed to Write Memory\n");
  674. }
  675. }
  676. #endif //RW_MEM
  677. void LanGetReg(PCOMMAND_DATA commandData,unsigned long address)
  678. {
  679. if(commandData==NULL) return;
  680. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  681. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  682. commandData->IoctlData.dwCommand=COMMAND_LAN_GET_REG;
  683. commandData->IoctlData.Data[0]=address;
  684. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  685. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  686. printf("Mem Map Offset == 0x%08lX, Read Value == 0x%08lX\n",
  687. commandData->IoctlData.Data[0],
  688. commandData->IoctlData.Data[1]);
  689. } else {
  690. printf("Failed to Read Register\n");
  691. }
  692. }
  693. void LanSetReg(PCOMMAND_DATA commandData, unsigned long address, unsigned long data)
  694. {
  695. if(commandData==NULL) return;
  696. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  697. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  698. commandData->IoctlData.dwCommand=COMMAND_LAN_SET_REG;
  699. commandData->IoctlData.Data[0]=address;
  700. commandData->IoctlData.Data[1]=data;
  701. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  702. if(commandData->IoctlData.dwSignature!=SMSC9500_DRIVER_SIGNATURE) {
  703. printf("Failed to Write Register\n");
  704. }
  705. }
  706. void MacGetReg(PCOMMAND_DATA commandData, unsigned long address)
  707. {
  708. if(commandData==NULL) return;
  709. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  710. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  711. commandData->IoctlData.dwCommand=COMMAND_MAC_GET_REG;
  712. commandData->IoctlData.Data[0]=address;
  713. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  714. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  715. printf("Mac Index == 0x%08lX, Read Value == 0x%08lX\n",
  716. commandData->IoctlData.Data[0],
  717. commandData->IoctlData.Data[1]);
  718. } else {
  719. printf("Failed to read Mac Register\n");
  720. }
  721. }
  722. void MacSetReg(
  723. PCOMMAND_DATA commandData,
  724. unsigned long address, unsigned long data)
  725. {
  726. if(commandData==NULL) return;
  727. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  728. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  729. commandData->IoctlData.dwCommand=COMMAND_MAC_SET_REG;
  730. commandData->IoctlData.Data[0]=address;
  731. commandData->IoctlData.Data[1]=data;
  732. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  733. if(commandData->IoctlData.dwSignature!=SMSC9500_DRIVER_SIGNATURE) {
  734. printf("Failed to Write Mac Register\n");
  735. }
  736. }
  737. void PhyGetReg(PCOMMAND_DATA commandData, unsigned long address)
  738. {
  739. if(commandData==NULL) return;
  740. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  741. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  742. commandData->IoctlData.dwCommand=COMMAND_PHY_GET_REG;
  743. commandData->IoctlData.Data[0]=address;
  744. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  745. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  746. printf("Phy Index == 0x%08lX, Read Value == 0x%08lX\n",
  747. commandData->IoctlData.Data[0],
  748. commandData->IoctlData.Data[1]);
  749. } else {
  750. printf("Failed to Read Phy Register\n");
  751. }
  752. }
  753. void PhySetReg(
  754. PCOMMAND_DATA commandData,
  755. unsigned long address, unsigned long data)
  756. {
  757. if(commandData==NULL) return;
  758. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  759. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  760. commandData->IoctlData.dwCommand=COMMAND_PHY_SET_REG;
  761. commandData->IoctlData.Data[0]=address;
  762. commandData->IoctlData.Data[1]=data;
  763. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  764. if(commandData->IoctlData.dwSignature!=SMSC9500_DRIVER_SIGNATURE) {
  765. printf("Failed to Write Phy Register\n");
  766. }
  767. }
  768. void GetEeprom(PCOMMAND_DATA commandData, unsigned long address, bool msgOn)
  769. {
  770. if(commandData==NULL) return;
  771. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  772. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  773. commandData->IoctlData.dwCommand=COMMAND_GET_EEPROM;
  774. commandData->IoctlData.Data[0]=address;
  775. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  776. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  777. if(msgOn){
  778. printf("Index == 0x%04lX, Read Value == 0x%02X\n",
  779. commandData->IoctlData.Data[0],
  780. (unsigned int)commandData->IoctlData.Data[1]);
  781. }
  782. } else {
  783. printf("Failed to Read EEPROM\n");
  784. }
  785. }
  786. void SetEeprom(
  787. PCOMMAND_DATA commandData,
  788. unsigned long address, unsigned long data)
  789. {
  790. if(commandData==NULL) return;
  791. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  792. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  793. commandData->IoctlData.dwCommand=COMMAND_SET_EEPROM;
  794. commandData->IoctlData.Data[0]=address;
  795. commandData->IoctlData.Data[1]=data;
  796. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  797. if(commandData->IoctlData.dwSignature!=SMSC9500_DRIVER_SIGNATURE) {
  798. printf("Failed to Write EEPROM\n");
  799. }
  800. }
  801. void SetEepromBuffer(
  802. PCOMMAND_DATA commandData,
  803. unsigned long address, unsigned int len, char* buf)
  804. {
  805. if(commandData==NULL) return;
  806. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  807. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  808. commandData->IoctlData.dwCommand=COMMAND_SET_EEPROM_BUFFER;
  809. commandData->IoctlData.Data[0]=address;
  810. commandData->IoctlData.Data[1]=len;
  811. memcpy(&commandData->IoctlData.Data[2], buf, len);
  812. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  813. if(commandData->IoctlData.dwSignature!=SMSC9500_DRIVER_SIGNATURE) {
  814. printf("Failed to Write EEPROM\n");
  815. }
  816. }
  817. int GetEepromSize(PCOMMAND_DATA commandData)
  818. {
  819. if(commandData==NULL) return;
  820. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  821. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  822. commandData->IoctlData.dwCommand=COMMAND_GET_CONFIGURATION;
  823. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  824. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  825. const unsigned long * data=commandData->IoctlData.Data;
  826. return(data[12]);
  827. } else {
  828. return 0;
  829. }
  830. }
  831. void WriteEepromToFile(PCOMMAND_DATA commandData, char* fileName)
  832. {
  833. FILE * filePtr=NULL;
  834. int eepromSize, i;
  835. unsigned long addr, data;
  836. char buf;
  837. eepromSize = GetEepromSize(commandData) * 128;
  838. printf("Eeprom size is %dB\n", eepromSize);
  839. if(eepromSize == 0){
  840. printf("EEPROM doesn't exist\n");
  841. return;
  842. }
  843. filePtr = fopen(fileName,"w+b");
  844. if(filePtr != NULL){
  845. for(i=0; i<eepromSize; i++){
  846. GetEeprom(commandData, i, false);
  847. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  848. buf = commandData->IoctlData.Data[1];
  849. fwrite(&buf, 1, 1, filePtr);
  850. } else {
  851. printf("Failed to Read EEPROM\n");
  852. break;
  853. }
  854. }
  855. if(i == eepromSize){
  856. printf("Wrote EEPROM contents into file %s successfully\n", fileName);
  857. }
  858. }
  859. fclose(filePtr);
  860. }
  861. void VerifyEepromWithFile(PCOMMAND_DATA commandData, char* fileName)
  862. {
  863. FILE * filePtr=NULL;
  864. int eepromSize, fileSize, i;
  865. unsigned long addr, data;
  866. unsigned char buf;
  867. eepromSize = GetEepromSize(commandData) * 128;
  868. printf("Eeprom size is %dB\n", eepromSize);
  869. if(eepromSize == 0){
  870. printf("EEPROM doesn't exist\n");
  871. return;
  872. }
  873. filePtr = fopen(fileName,"rb");
  874. if(filePtr != NULL){
  875. fseek(filePtr, 0, SEEK_END);
  876. fileSize = ftell(filePtr); //Get file size
  877. fseek(filePtr, 0, SEEK_SET);
  878. if(fileSize < eepromSize){
  879. printf("EEPROM size is larger than file size\n");
  880. fclose(filePtr);
  881. return;
  882. }
  883. for(i=0; i<eepromSize; i++){
  884. GetEeprom(commandData, i, false);
  885. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  886. if(fread(&buf, 1, 1, filePtr) != 0){
  887. if(buf != (unsigned char)commandData->IoctlData.Data[1]){
  888. printf("EEPROM contents are DIFFERENT from the file contents at offset %d\n", i);
  889. break;
  890. }
  891. }
  892. } else {
  893. printf("Failed to Read EEPROM\n");
  894. break;
  895. }
  896. }
  897. if(i == eepromSize){
  898. printf("EEPROM contents are as SAME as the file contents\n");
  899. }
  900. }
  901. fclose(filePtr);
  902. }
  903. void UpdateEepromFromFile(PCOMMAND_DATA commandData, char* fileName)
  904. {
  905. FILE * filePtr=NULL;
  906. int eepromSize, fileSize, i;
  907. unsigned long addr, data;
  908. char* buf;
  909. eepromSize = GetEepromSize(commandData) * 128;
  910. printf("Eeprom size is %dB\n", eepromSize);
  911. if(eepromSize == 0){
  912. printf("EEPROM doesn't exist\n");
  913. return;
  914. }
  915. filePtr = fopen(fileName,"rb");
  916. if(filePtr != NULL){
  917. fseek(filePtr, 0, SEEK_END);
  918. fileSize = ftell(filePtr); //Get file size
  919. fseek(filePtr, 0, SEEK_SET);
  920. if(fileSize > eepromSize){
  921. printf("The binary file size is larger than %d\n", eepromSize);
  922. fclose(filePtr);
  923. return;
  924. }
  925. if(fileSize > MAX_EEPROM_SIZE){
  926. printf("The binary file size is larger than supported EEPROM size (%d)\n", MAX_EEPROM_SIZE);
  927. fclose(filePtr);
  928. return;
  929. }
  930. printf("File size is %dB\n", fileSize);
  931. buf = malloc(fileSize);
  932. if(!buf){
  933. printf("No memory available\n");
  934. fclose(filePtr);
  935. return;
  936. }
  937. if(fread(buf, 1, fileSize, filePtr) != 0){
  938. SetEepromBuffer(commandData, 0, fileSize, buf);
  939. if(commandData->IoctlData.dwSignature != SMSC9500_DRIVER_SIGNATURE) {
  940. printf("Failed to update EEPROM\n");
  941. } else {
  942. printf("Updated EEPROM contents successfully\n");
  943. }
  944. } else {
  945. printf("Unable to read binary file\n");
  946. }
  947. free(buf);
  948. }
  949. fclose(filePtr);
  950. }
  951. bool Initialize(PCOMMAND_DATA commandData,const char *ethName) {
  952. if(commandData==NULL) return false;
  953. if(ethName==NULL) return false;
  954. commandData->hSockFD=socket(AF_INET,SOCK_DGRAM,0);
  955. if((commandData->hSockFD) < 0) {
  956. perror("\r\nFailed to create socket !! ->");
  957. return false;
  958. }
  959. commandData->IfReq.ifr_data= (void *)&(commandData->IoctlData);
  960. memset(&(commandData->IoctlData),0,sizeof(SMSC9500_IOCTL_DATA));
  961. if(ethName[0]!=0) {
  962. strncpy(commandData->IfReq.ifr_name,ethName,IFNAMSIZ);
  963. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  964. commandData->IoctlData.dwCommand=COMMAND_GET_SIGNATURE;
  965. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  966. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  967. return true;
  968. }
  969. printf("Failed to find 9500 driver on %s\n",commandData->IfReq.ifr_name);
  970. } else {
  971. int ifNumber;
  972. for(ifNumber=0;ifNumber<8;ifNumber++) {
  973. sprintf(commandData->IfReq.ifr_name,"eth%d",ifNumber);
  974. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  975. commandData->IoctlData.dwCommand=COMMAND_GET_SIGNATURE;
  976. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  977. ioctl(commandData->hSockFD,SMSC9500_IOCTL,&(commandData->IfReq));
  978. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  979. //printf("found 9500 on %s\n",commandData->IfReq.ifr_name);
  980. return true;
  981. }
  982. }
  983. printf("Failed to find 9500 driver on eth0 .. eth7\n");
  984. }
  985. printf("Either the driver has not been installed or there is\n");
  986. printf("a possible version mismatch between smsc9500.o and cmd9500\n");
  987. return false;
  988. }
  989. bool ReceiveULong(SOCKET sock,unsigned long * pDWord)
  990. {
  991. bool result=false;
  992. unsigned long data=0;
  993. unsigned char ch=0;
  994. if(recv(sock,&ch,1,0)>0) {
  995. data=(unsigned long)ch;
  996. if(recv(sock,&ch,1,0)>0) {
  997. data|=(((unsigned long)ch)<<8);
  998. if(recv(sock,&ch,1,0)>0) {
  999. data|=(((unsigned long)ch)<<16);
  1000. if(recv(sock,&ch,1,0)>0) {
  1001. data|=(((unsigned long)ch)<<24);
  1002. (*pDWord)=data;
  1003. result=true;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. return result;
  1009. }
  1010. bool SendULong(SOCKET sock,unsigned long data)
  1011. {
  1012. bool result=false;
  1013. unsigned char ch=(unsigned char)(data&0x000000FFUL);
  1014. if(send(sock,&ch,1,0)==1) {
  1015. ch=(unsigned char)((data>>8)&0x000000FFUL);
  1016. if(send(sock,&ch,1,0)==1) {
  1017. ch=(unsigned char)((data>>16)&0x000000FFUL);
  1018. if(send(sock,&ch,1,0)==1) {
  1019. ch=(unsigned char)((data>>24)&0x000000FFUL);
  1020. if(send(sock,&ch,1,0)==1) {
  1021. result=true;
  1022. }
  1023. }
  1024. }
  1025. }
  1026. return result;
  1027. }
  1028. void process_requests(PCOMMAND_DATA commandData)
  1029. {
  1030. unsigned long requestCode=0;
  1031. while(ReceiveULong(server_sock,&requestCode)) {
  1032. switch(requestCode) {
  1033. case COMMAND_GET_FLOW_PARAMS:
  1034. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  1035. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  1036. commandData->IoctlData.dwCommand=COMMAND_GET_FLOW_PARAMS;
  1037. ioctl(commandData->hSockFD,
  1038. SMSC9500_IOCTL,&(commandData->IfReq));
  1039. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  1040. SendULong(server_sock,1);//1==success
  1041. SendULong(server_sock,commandData->IoctlData.Data[0]);//RxFlowMeasuredMaxThroughput
  1042. SendULong(server_sock,commandData->IoctlData.Data[1]);//RxFlowMeasuredMaxPacketCount
  1043. SendULong(server_sock,commandData->IoctlData.Data[2]);//RxFlowParameters.MaxThroughput
  1044. SendULong(server_sock,commandData->IoctlData.Data[3]);//RxFlowParameters.MaxPacketCount
  1045. SendULong(server_sock,commandData->IoctlData.Data[4]);//RxFlowParameters.PacketCost
  1046. SendULong(server_sock,commandData->IoctlData.Data[5]);//RxFlowParameters.BurstPeriod
  1047. SendULong(server_sock,commandData->IoctlData.Data[6]);//RxFlowMaxWorkLoad
  1048. SendULong(server_sock,commandData->IoctlData.Data[7]);//INT_CFG.INT_DEAS
  1049. } else {
  1050. SendULong(server_sock,0);//0==failed
  1051. }
  1052. break;
  1053. case COMMAND_SET_FLOW_PARAMS:
  1054. {
  1055. unsigned long data=0;
  1056. commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
  1057. commandData->IoctlData.dwSignature=SMSC9500_APP_SIGNATURE;
  1058. commandData->IoctlData.dwCommand=COMMAND_SET_FLOW_PARAMS;
  1059. if(!ReceiveULong(server_sock,&data)) break;
  1060. commandData->IoctlData.Data[0]=data;//RxFlowMeasuredMaxThroughput
  1061. if(!ReceiveULong(server_sock,&data)) break;
  1062. commandData->IoctlData.Data[1]=data;//RxFlowMeasuredMaxPacketCount
  1063. if(!ReceiveULong(server_sock,&data)) break;
  1064. commandData->IoctlData.Data[2]=data;//RxFlowParameters.MaxThroughput
  1065. if(!ReceiveULong(server_sock,&data)) break;
  1066. commandData->IoctlData.Data[3]=data;//RxFlowParameters.MaxPacketCount
  1067. if(!ReceiveULong(server_sock,&data)) break;
  1068. commandData->IoctlData.Data[4]=data;//RxFlowParameters.PacketCost
  1069. if(!ReceiveULong(server_sock,&data)) break;
  1070. commandData->IoctlData.Data[5]=data;//RxFlowParameters.BurstPeriod
  1071. if(!ReceiveULong(server_sock,&data)) break;
  1072. commandData->IoctlData.Data[6]=data;//RxFlowMaxWorkLoad
  1073. if(!ReceiveULong(server_sock,&data)) break;
  1074. commandData->IoctlData.Data[7]=data;//INT_CFG.INT_DEAS
  1075. ioctl(commandData->hSockFD,
  1076. SMSC9500_IOCTL,&(commandData->IfReq));
  1077. if(commandData->IoctlData.dwSignature==SMSC9500_DRIVER_SIGNATURE) {
  1078. SendULong(server_sock,1);//1==success
  1079. } else {
  1080. SendULong(server_sock,0);//0==failed
  1081. }
  1082. }
  1083. break;
  1084. default:
  1085. printf("WARNING, unknown requestCode=0x%08lX\n",requestCode);
  1086. break;
  1087. }
  1088. }
  1089. }
  1090. unsigned long ReadThroughput(char * fileName)
  1091. {
  1092. unsigned long result=0;
  1093. bool clearFlag=true;
  1094. FILE * filePtr=NULL;
  1095. filePtr=fopen(fileName,"r");
  1096. if(filePtr!=NULL) {
  1097. char ch=0;
  1098. while(fread(&ch,1,1,filePtr)!=0) {
  1099. switch(ch) {
  1100. case '0':case '1':case '2':case '3':case '4':
  1101. case '5':case '6':case '7':case '8':case '9':
  1102. if(clearFlag) {
  1103. result=0;
  1104. clearFlag=false;
  1105. }
  1106. result*=10;
  1107. result+=(unsigned long)(ch-'0');
  1108. break;
  1109. case '.':
  1110. break;
  1111. default:
  1112. clearFlag=true;
  1113. break;
  1114. }
  1115. }
  1116. fclose(filePtr);
  1117. } else {
  1118. printf("ReadThroughput: unable to open file\n");
  1119. }
  1120. return result;
  1121. }
  1122. int main(ac,av)
  1123. int ac;
  1124. char * av[];
  1125. {
  1126. int oc=0;
  1127. bool eSet=false;
  1128. char ethName[IFNAMSIZ];
  1129. COMMAND_DATA commandData;
  1130. bool cSet=false;
  1131. bool aSet=false;
  1132. bool fSet = false;
  1133. unsigned long address=0;
  1134. bool dSet=false;
  1135. unsigned long data=0;
  1136. unsigned long commandCode=0;
  1137. char hostName[128];
  1138. bool hSet=false;
  1139. unsigned long portNum=0;
  1140. char *fileName = NULL;
  1141. bool pSet=false;
  1142. iam=av[0];
  1143. ethName[0]=0;
  1144. hostName[0]=0;
  1145. while((oc=getopt(ac,av,"hH:p:e:c:a:d:f:"))!=-1) {
  1146. switch(oc) {
  1147. case 'h'://help
  1148. goto BAD_USAGE;
  1149. case 'H'://Host address
  1150. if(hSet) goto BAD_USAGE;
  1151. strcpy(hostName,optarg);
  1152. hSet=true;
  1153. break;
  1154. case 'p':
  1155. if(pSet) goto BAD_USAGE;
  1156. if(!ParseNumber(optarg,&portNum)) {
  1157. goto BAD_USAGE;
  1158. }
  1159. if(portNum>0xFFFFUL) goto BAD_USAGE;
  1160. pSet=true;
  1161. break;
  1162. case 'e':
  1163. if(eSet) goto BAD_USAGE;
  1164. eSet=true;
  1165. strncpy(ethName,optarg,IFNAMSIZ);
  1166. ethName[IFNAMSIZ-1]=0;
  1167. break;
  1168. case 'c':
  1169. if(cSet) goto BAD_USAGE;
  1170. if(strcmp(optarg,"GET_CONFIG")==0) {
  1171. commandCode=COMMAND_GET_CONFIGURATION;
  1172. } else if(strcmp(optarg,"DUMP_REGS")==0) {
  1173. commandCode=COMMAND_DUMP_LAN_REGS;
  1174. } else if(strcmp(optarg,"DUMP_MAC")==0) {
  1175. commandCode=COMMAND_DUMP_MAC_REGS;
  1176. } else if(strcmp(optarg,"DUMP_PHY")==0) {
  1177. commandCode=COMMAND_DUMP_PHY_REGS;
  1178. } else if(strcmp(optarg,"DUMP_EEPROM")==0) {
  1179. commandCode=COMMAND_DUMP_EEPROM;
  1180. } else if(strcmp(optarg,"DUMP_TEMP")==0) {
  1181. commandCode=COMMAND_DUMP_TEMP;
  1182. } else if(strcmp(optarg,"GET_MAC")==0) {
  1183. commandCode=COMMAND_GET_MAC_ADDRESS;
  1184. } else if(strcmp(optarg,"SET_MAC")==0) {
  1185. commandCode=COMMAND_SET_MAC_ADDRESS;
  1186. } else if(strcmp(optarg,"LOAD_MAC")==0) {
  1187. commandCode=COMMAND_LOAD_MAC_ADDRESS;
  1188. } else if(strcmp(optarg,"SAVE_MAC")==0) {
  1189. commandCode=COMMAND_SAVE_MAC_ADDRESS;
  1190. } else if(strcmp(optarg,"SET_DEBUG")==0) {
  1191. commandCode=COMMAND_SET_DEBUG_MODE;
  1192. } else if(strcmp(optarg,"SET_LINK")==0) {
  1193. commandCode=COMMAND_SET_LINK_MODE;
  1194. } else if(strcmp(optarg,"GET_LINK")==0) {
  1195. commandCode=COMMAND_GET_LINK_MODE;
  1196. } else if(strcmp(optarg,"SET_AMDIX")==0) {
  1197. commandCode=COMMAND_SET_AMDIX_STS;
  1198. } else if(strcmp(optarg,"GET_AMDIX")==0) {
  1199. commandCode=COMMAND_GET_AMDIX_STS;
  1200. } else if(strcmp(optarg,"CHECK_LINK")==0) {
  1201. commandCode=COMMAND_CHECK_LINK;
  1202. } else if(strcmp(optarg,"READ_REG")==0) {
  1203. commandCode=COMMAND_LAN_GET_REG;
  1204. } else if(strcmp(optarg,"WRITE_REG")==0) {
  1205. commandCode=COMMAND_LAN_SET_REG;
  1206. } else if(strcmp(optarg,"READ_MAC")==0) {
  1207. commandCode=COMMAND_MAC_GET_REG;
  1208. } else if(strcmp(optarg,"WRITE_MAC")==0) {
  1209. commandCode=COMMAND_MAC_SET_REG;
  1210. } else if(strcmp(optarg,"READ_PHY")==0) {
  1211. commandCode=COMMAND_PHY_GET_REG;
  1212. } else if(strcmp(optarg,"WRITE_PHY")==0) {
  1213. commandCode=COMMAND_PHY_SET_REG;
  1214. } else if(strcmp(optarg,"READ_EEPROM")==0) {
  1215. commandCode=COMMAND_GET_EEPROM;
  1216. } else if(strcmp(optarg,"WRITE_EEPROM")==0) {
  1217. commandCode=COMMAND_SET_EEPROM;
  1218. } else if(strcmp(optarg,"WRITE_FILE_TO_EEPROM")==0) {
  1219. commandCode=COMMAND_WRITE_EEPROM_FROM_FILE;
  1220. } else if(strcmp(optarg,"READ_EEPROM_TO_FILE")==0) {
  1221. commandCode=COMMAND_WRITE_EEPROM_TO_FILE;
  1222. } else if(strcmp(optarg,"VERIFY_EEPROM_WITH_FILE")==0) {
  1223. commandCode=COMMAND_VERIFY_EEPROM_WITH_FILE;
  1224. } else if(strcmp(optarg,"GET_ERRORS")==0) {
  1225. commandCode=COMMAND_GET_ERRORS;
  1226. }
  1227. #ifdef RW_MEM
  1228. else if(strcmp(optarg,"READ_BYTE")==0) {
  1229. commandCode=COMMAND_READ_BYTE;
  1230. } else if(strcmp(optarg,"READ_WORD")==0) {
  1231. commandCode=COMMAND_READ_WORD;
  1232. } else if(strcmp(optarg,"READ_DWORD")==0) {
  1233. commandCode=COMMAND_READ_DWORD;
  1234. } else if(strcmp(optarg,"WRITE_BYTE")==0) {
  1235. commandCode=COMMAND_WRITE_BYTE;
  1236. } else if(strcmp(optarg,"WRITE_WORD")==0) {
  1237. commandCode=COMMAND_WRITE_WORD;
  1238. } else if(strcmp(optarg,"WRITE_DWORD")==0) {
  1239. commandCode=COMMAND_WRITE_DWORD;
  1240. }
  1241. #endif //RW_MEM
  1242. else {
  1243. goto BAD_USAGE;
  1244. }
  1245. cSet=true;
  1246. break;
  1247. case 'a':
  1248. if(aSet) goto BAD_USAGE;
  1249. if(!ParseNumber(optarg,&address)) {
  1250. goto BAD_USAGE;
  1251. }
  1252. aSet=true;
  1253. break;
  1254. case 'd':
  1255. if(dSet) goto BAD_USAGE;
  1256. if(!ParseNumber(optarg,&data)) {
  1257. goto BAD_USAGE;
  1258. }
  1259. dSet=true;
  1260. break;
  1261. case 'f':
  1262. if(dSet) goto BAD_USAGE;
  1263. if(!ParseString(optarg, &fileName)) {
  1264. goto BAD_USAGE;
  1265. }
  1266. fSet=true;
  1267. break;
  1268. default:
  1269. goto BAD_USAGE;
  1270. }
  1271. }
  1272. if(!Initialize(&commandData,ethName)) {
  1273. return 1;
  1274. }
  1275. switch(commandCode) {
  1276. case COMMAND_GET_CONFIGURATION:
  1277. GetConfiguration(&commandData);
  1278. break;
  1279. case COMMAND_DUMP_LAN_REGS:
  1280. LanDumpRegs(&commandData);
  1281. break;
  1282. case COMMAND_DUMP_MAC_REGS:
  1283. MacDumpRegs(&commandData);
  1284. break;
  1285. case COMMAND_DUMP_PHY_REGS:
  1286. PhyDumpRegs(&commandData);
  1287. break;
  1288. case COMMAND_DUMP_EEPROM:
  1289. DumpEEPROM(&commandData);
  1290. break;
  1291. case COMMAND_GET_MAC_ADDRESS:
  1292. GetMacAddress(&commandData);
  1293. break;
  1294. case COMMAND_SET_MAC_ADDRESS:
  1295. if(!aSet) goto BAD_USAGE;
  1296. if(!dSet) goto BAD_USAGE;
  1297. SetMacAddress(&commandData,address,data);
  1298. break;
  1299. case COMMAND_LOAD_MAC_ADDRESS:
  1300. LoadMacAddress(&commandData);
  1301. break;
  1302. case COMMAND_SAVE_MAC_ADDRESS:
  1303. if(!aSet) goto BAD_USAGE;
  1304. if(!dSet) goto BAD_USAGE;
  1305. SaveMacAddress(&commandData,address,data);
  1306. break;
  1307. case COMMAND_SET_DEBUG_MODE:
  1308. if(!dSet) goto BAD_USAGE;
  1309. SetDebugMode(&commandData,data);
  1310. break;
  1311. case COMMAND_SET_LINK_MODE:
  1312. if(!dSet) goto BAD_USAGE;
  1313. SetLinkMode(&commandData,data);
  1314. break;
  1315. case COMMAND_GET_LINK_MODE:
  1316. GetLinkMode(&commandData);
  1317. break;
  1318. case COMMAND_SET_AMDIX_STS:
  1319. if(!dSet) goto BAD_USAGE;
  1320. SetAutoMdixSts(&commandData,data);
  1321. break;
  1322. case COMMAND_GET_AMDIX_STS:
  1323. GetAutoMdixSts(&commandData);
  1324. break;
  1325. case COMMAND_CHECK_LINK:
  1326. CheckLink(&commandData);
  1327. break;
  1328. case COMMAND_LAN_GET_REG:
  1329. if(!aSet) goto BAD_USAGE;
  1330. LanGetReg(&commandData,address);
  1331. break;
  1332. case COMMAND_LAN_SET_REG:
  1333. if(!aSet) goto BAD_USAGE;
  1334. if(!dSet) goto BAD_USAGE;
  1335. LanSetReg(&commandData,address,data);
  1336. break;
  1337. case COMMAND_MAC_GET_REG:
  1338. if(!aSet) goto BAD_USAGE;
  1339. MacGetReg(&commandData,address);
  1340. break;
  1341. case COMMAND_MAC_SET_REG:
  1342. if(!aSet) goto BAD_USAGE;
  1343. if(!dSet) goto BAD_USAGE;
  1344. MacSetReg(&commandData,address,data);
  1345. break;
  1346. case COMMAND_PHY_GET_REG:
  1347. if(!aSet) goto BAD_USAGE;
  1348. PhyGetReg(&commandData,address);
  1349. break;
  1350. case COMMAND_PHY_SET_REG:
  1351. if(!aSet) goto BAD_USAGE;
  1352. if(!dSet) goto BAD_USAGE;
  1353. PhySetReg(&commandData,address,data);
  1354. break;
  1355. case COMMAND_GET_EEPROM:
  1356. if(!aSet) goto BAD_USAGE;
  1357. GetEeprom(&commandData,address, true);
  1358. break;
  1359. case COMMAND_SET_EEPROM:
  1360. if(!aSet) goto BAD_USAGE;
  1361. if(!dSet) goto BAD_USAGE;
  1362. SetEeprom(&commandData,address,data);
  1363. break;
  1364. case COMMAND_WRITE_EEPROM_FROM_FILE:
  1365. if(!fSet) goto BAD_USAGE;
  1366. UpdateEepromFromFile(&commandData, fileName);
  1367. break;
  1368. case COMMAND_WRITE_EEPROM_TO_FILE:
  1369. if(!fSet) goto BAD_USAGE;
  1370. WriteEepromToFile(&commandData, fileName);
  1371. break;
  1372. case COMMAND_VERIFY_EEPROM_WITH_FILE:
  1373. if(!fSet) goto BAD_USAGE;
  1374. VerifyEepromWithFile(&commandData, fileName);
  1375. break;
  1376. case COMMAND_GET_ERRORS:
  1377. GetErrors(&commandData);
  1378. break;
  1379. #ifdef RW_MEM
  1380. case COMMAND_READ_BYTE:
  1381. if(!aSet) goto BAD_USAGE;
  1382. ReadByte(&commandData,address);
  1383. break;
  1384. case COMMAND_READ_WORD:
  1385. if(!aSet) goto BAD_USAGE;
  1386. ReadWord(&commandData,address);
  1387. break;
  1388. case COMMAND_READ_DWORD:
  1389. if(!aSet) goto BAD_USAGE;
  1390. ReadDWord(&commandData,address);
  1391. break;
  1392. case COMMAND_WRITE_BYTE:
  1393. if(!aSet) goto BAD_USAGE;
  1394. if(!dSet) goto BAD_USAGE;
  1395. WriteByte(&commandData,address,data);
  1396. break;
  1397. case COMMAND_WRITE_WORD:
  1398. if(!aSet) goto BAD_USAGE;
  1399. if(!dSet) goto BAD_USAGE;
  1400. WriteWord(&commandData,address,data);
  1401. break;
  1402. case COMMAND_WRITE_DWORD:
  1403. if(!aSet) goto BAD_USAGE;
  1404. if(!dSet) goto BAD_USAGE;
  1405. WriteDWord(&commandData,address,data);
  1406. break;
  1407. #endif //RW_MEM
  1408. default:
  1409. goto BAD_USAGE;
  1410. }
  1411. return 1;
  1412. BAD_USAGE:
  1413. DisplayUsage();
  1414. return 1;
  1415. }