sdla_ppp.c 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429
  1. /*****************************************************************************
  2. * sdla_ppp.c WANPIPE(tm) Multiprotocol WAN Link Driver. PPP module.
  3. *
  4. * Author: Nenad Corbic <ncorbic@sangoma.com>
  5. *
  6. * Copyright: (c) 1995-2001 Sangoma Technologies Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. * ============================================================================
  13. * Feb 28, 2001 Nenad Corbic o Updated if_tx_timeout() routine for
  14. * 2.4.X kernels.
  15. * Nov 29, 2000 Nenad Corbic o Added the 2.4.x kernel support:
  16. * get_ip_address() function has moved
  17. * into the ppp_poll() routine. It cannot
  18. * be called from an interrupt.
  19. * Nov 07, 2000 Nenad Corbic o Added security features for UDP debugging:
  20. * Deny all and specify allowed requests.
  21. * May 02, 2000 Nenad Corbic o Added the dynamic interface shutdown
  22. * option. When the link goes down, the
  23. * network interface IFF_UP flag is reset.
  24. * Mar 06, 2000 Nenad Corbic o Bug Fix: corrupted mbox recovery.
  25. * Feb 25, 2000 Nenad Corbic o Fixed the FT1 UDP debugger problem.
  26. * Feb 09, 2000 Nenad Coribc o Shutdown bug fix. update() was called
  27. * with NULL dev pointer: no check.
  28. * Jan 24, 2000 Nenad Corbic o Disabled use of CMD complete inter.
  29. * Dev 15, 1999 Nenad Corbic o Fixed up header files for 2.0.X kernels
  30. * Oct 25, 1999 Nenad Corbic o Support for 2.0.X kernels
  31. * Moved dynamic route processing into
  32. * a polling routine.
  33. * Oct 07, 1999 Nenad Corbic o Support for S514 PCI card.
  34. * Gideon Hack o UPD and Updates executed using timer interrupt
  35. * Sep 10, 1999 Nenad Corbic o Fixed up the /proc statistics
  36. * Jul 20, 1999 Nenad Corbic o Remove the polling routines and use
  37. * interrupts instead.
  38. * Sep 17, 1998 Jaspreet Singh o Updates for 2.2.X Kernels.
  39. * Aug 13, 1998 Jaspreet Singh o Improved Line Tracing.
  40. * Jun 22, 1998 David Fong o Added remote IP address assignment
  41. * Mar 15, 1998 Alan Cox o 2.1.8x basic port.
  42. * Apr 16, 1998 Jaspreet Singh o using htons() for the IPX protocol.
  43. * Dec 09, 1997 Jaspreet Singh o Added PAP and CHAP.
  44. * o Implemented new routines like
  45. * ppp_set_inbnd_auth(), ppp_set_outbnd_auth(),
  46. * tokenize() and strstrip().
  47. * Nov 27, 1997 Jaspreet Singh o Added protection against enabling of irqs
  48. * while they have been disabled.
  49. * Nov 24, 1997 Jaspreet Singh o Fixed another RACE condition caused by
  50. * disabling and enabling of irqs.
  51. * o Added new counters for stats on disable/enable
  52. * IRQs.
  53. * Nov 10, 1997 Jaspreet Singh o Initialized 'skb->mac.raw' to 'skb->data'
  54. * before every netif_rx().
  55. * o Free up the device structure in del_if().
  56. * Nov 07, 1997 Jaspreet Singh o Changed the delay to zero for Line tracing
  57. * command.
  58. * Oct 20, 1997 Jaspreet Singh o Added hooks in for Router UP time.
  59. * Oct 16, 1997 Jaspreet Singh o The critical flag is used to maintain flow
  60. * control by avoiding RACE conditions. The
  61. * cli() and restore_flags() are taken out.
  62. * A new structure, "ppp_private_area", is added
  63. * to provide Driver Statistics.
  64. * Jul 21, 1997 Jaspreet Singh o Protected calls to sdla_peek() by adding
  65. * save_flags(), cli() and restore_flags().
  66. * Jul 07, 1997 Jaspreet Singh o Added configurable TTL for UDP packets
  67. * o Added ability to discard mulitcast and
  68. * broacast source addressed packets.
  69. * Jun 27, 1997 Jaspreet Singh o Added FT1 monitor capabilities
  70. * New case (0x25) statement in if_send routine.
  71. * Added a global variable rCount to keep track
  72. * of FT1 status enabled on the board.
  73. * May 22, 1997 Jaspreet Singh o Added change in the PPP_SET_CONFIG command for
  74. * 508 card to reflect changes in the new
  75. * ppp508.sfm for supporting:continous transmission
  76. * of Configure-Request packets without receiving a
  77. * reply
  78. * OR-ed 0x300 to conf_flags
  79. * o Changed connect_tmout from 900 to 0
  80. * May 21, 1997 Jaspreet Singh o Fixed UDP Management for multiple boards
  81. * Apr 25, 1997 Farhan Thawar o added UDP Management stuff
  82. * Mar 11, 1997 Farhan Thawar Version 3.1.1
  83. * o fixed (+1) bug in rx_intr()
  84. * o changed if_send() to return 0 if
  85. * wandev.critical() is true
  86. * o free socket buffer in if_send() if
  87. * returning 0
  88. * Jan 15, 1997 Gene Kozin Version 3.1.0
  89. * o implemented exec() entry point
  90. * Jan 06, 1997 Gene Kozin Initial version.
  91. *****************************************************************************/
  92. #include <linux/module.h>
  93. #include <linux/kernel.h> /* printk(), and other useful stuff */
  94. #include <linux/stddef.h> /* offsetof(), etc. */
  95. #include <linux/errno.h> /* return codes */
  96. #include <linux/string.h> /* inline memset(), etc. */
  97. #include <linux/slab.h> /* kmalloc(), kfree() */
  98. #include <linux/wanrouter.h> /* WAN router definitions */
  99. #include <linux/wanpipe.h> /* WANPIPE common user API definitions */
  100. #include <linux/if_arp.h> /* ARPHRD_* defines */
  101. #include <asm/byteorder.h> /* htons(), etc. */
  102. #include <linux/in.h> /* sockaddr_in */
  103. #include <asm/uaccess.h>
  104. #include <linux/inetdevice.h>
  105. #include <linux/netdevice.h>
  106. #include <linux/if.h>
  107. #include <linux/sdla_ppp.h> /* PPP firmware API definitions */
  108. #include <linux/sdlasfm.h> /* S514 Type Definition */
  109. /****** Defines & Macros ****************************************************/
  110. #define PPP_DFLT_MTU 1500 /* default MTU */
  111. #define PPP_MAX_MTU 4000 /* maximum MTU */
  112. #define PPP_HDR_LEN 1
  113. #define MAX_IP_ERRORS 100
  114. #define CONNECT_TIMEOUT (90*HZ) /* link connection timeout */
  115. #define HOLD_DOWN_TIME (5*HZ) /* link hold down time : Changed from 30 to 5 */
  116. /* For handle_IPXWAN() */
  117. #define CVHexToAscii(b) (((unsigned char)(b) > (unsigned char)9) ? ((unsigned char)'A' + ((unsigned char)(b) - (unsigned char)10)) : ((unsigned char)'0' + (unsigned char)(b)))
  118. /* Macro for enabling/disabling debugging comments */
  119. //#define NEX_DEBUG
  120. #ifdef NEX_DEBUG
  121. #define NEX_PRINTK(format, a...) printk(format, ## a)
  122. #else
  123. #define NEX_PRINTK(format, a...)
  124. #endif /* NEX_DEBUG */
  125. #define DCD(a) ( a & 0x08 ? "HIGH" : "LOW" )
  126. #define CTS(a) ( a & 0x20 ? "HIGH" : "LOW" )
  127. #define LCP(a) ( a == 0x09 ? "OPEN" : "CLOSED" )
  128. #define IP(a) ( a == 0x09 ? "ENABLED" : "DISABLED" )
  129. #define TMR_INT_ENABLED_UPDATE 0x01
  130. #define TMR_INT_ENABLED_PPP_EVENT 0x02
  131. #define TMR_INT_ENABLED_UDP 0x04
  132. #define TMR_INT_ENABLED_CONFIG 0x20
  133. /* Set Configuraton Command Definitions */
  134. #define PERCENT_TX_BUFF 60
  135. #define TIME_BETWEEN_CONF_REQ 30
  136. #define TIME_BETWEEN_PAP_CHAP_REQ 30
  137. #define WAIT_PAP_CHAP_WITHOUT_REPLY 300
  138. #define WAIT_AFTER_DCD_CTS_LOW 5
  139. #define TIME_DCD_CTS_LOW_AFTER_LNK_DOWN 10
  140. #define WAIT_DCD_HIGH_AFTER_ENABLE_COMM 900
  141. #define MAX_CONF_REQ_WITHOUT_REPLY 10
  142. #define MAX_TERM_REQ_WITHOUT_REPLY 2
  143. #define NUM_CONF_NAK_WITHOUT_REPLY 5
  144. #define NUM_AUTH_REQ_WITHOUT_REPLY 10
  145. #define END_OFFSET 0x1F0
  146. /******Data Structures*****************************************************/
  147. /* This structure is placed in the private data area of the device structure.
  148. * The card structure used to occupy the private area but now the following
  149. * structure will incorporate the card structure along with PPP specific data
  150. */
  151. typedef struct ppp_private_area
  152. {
  153. struct net_device *slave;
  154. sdla_t* card;
  155. unsigned long router_start_time; /*router start time in sec */
  156. unsigned long tick_counter; /*used for 5 second counter*/
  157. unsigned mc; /*multicast support on or off*/
  158. unsigned char enable_IPX;
  159. unsigned long network_number;
  160. unsigned char pap;
  161. unsigned char chap;
  162. unsigned char sysname[31]; /* system name for in-bnd auth*/
  163. unsigned char userid[511]; /* list of user ids */
  164. unsigned char passwd[511]; /* list of passwords */
  165. unsigned protocol; /* SKB Protocol */
  166. u32 ip_local; /* Local IP Address */
  167. u32 ip_remote; /* remote IP Address */
  168. u32 ip_local_tmp;
  169. u32 ip_remote_tmp;
  170. unsigned char timer_int_enabled; /* Who enabled the timer inter*/
  171. unsigned char update_comms_stats; /* Used by update function */
  172. unsigned long curr_trace_addr; /* Trace information */
  173. unsigned long start_trace_addr;
  174. unsigned long end_trace_addr;
  175. unsigned char interface_down; /* Brind down interface when channel
  176. goes down */
  177. unsigned long config_wait_timeout; /* After if_open() if in dynamic if mode,
  178. wait a few seconds before configuring */
  179. unsigned short udp_pkt_lgth;
  180. char udp_pkt_src;
  181. char udp_pkt_data[MAX_LGTH_UDP_MGNT_PKT];
  182. /* PPP specific statistics */
  183. if_send_stat_t if_send_stat;
  184. rx_intr_stat_t rx_intr_stat;
  185. pipe_mgmt_stat_t pipe_mgmt_stat;
  186. unsigned long router_up_time;
  187. /* Polling work queue entry. Each interface
  188. * has its own work queue entry, which is used
  189. * to defer events from the interrupt */
  190. struct work_struct poll_work;
  191. struct timer_list poll_delay_timer;
  192. u8 gateway;
  193. u8 config_ppp;
  194. u8 ip_error;
  195. }ppp_private_area_t;
  196. /* variable for keeping track of enabling/disabling FT1 monitor status */
  197. static int rCount = 0;
  198. extern void disable_irq(unsigned int);
  199. extern void enable_irq(unsigned int);
  200. /****** Function Prototypes *************************************************/
  201. /* WAN link driver entry points. These are called by the WAN router module. */
  202. static int update(struct wan_device *wandev);
  203. static int new_if(struct wan_device *wandev, struct net_device *dev,
  204. wanif_conf_t *conf);
  205. static int del_if(struct wan_device *wandev, struct net_device *dev);
  206. /* WANPIPE-specific entry points */
  207. static int wpp_exec (struct sdla *card, void *u_cmd, void *u_data);
  208. /* Network device interface */
  209. static int if_init(struct net_device *dev);
  210. static int if_open(struct net_device *dev);
  211. static int if_close(struct net_device *dev);
  212. static int if_header(struct sk_buff *skb, struct net_device *dev,
  213. unsigned short type,
  214. void *daddr, void *saddr, unsigned len);
  215. static void if_tx_timeout(struct net_device *dev);
  216. static int if_rebuild_hdr(struct sk_buff *skb);
  217. static struct net_device_stats *if_stats(struct net_device *dev);
  218. static int if_send(struct sk_buff *skb, struct net_device *dev);
  219. /* PPP firmware interface functions */
  220. static int ppp_read_version(sdla_t *card, char *str);
  221. static int ppp_set_outbnd_auth(sdla_t *card, ppp_private_area_t *ppp_priv_area);
  222. static int ppp_set_inbnd_auth(sdla_t *card, ppp_private_area_t *ppp_priv_area);
  223. static int ppp_configure(sdla_t *card, void *data);
  224. static int ppp_set_intr_mode(sdla_t *card, unsigned char mode);
  225. static int ppp_comm_enable(sdla_t *card);
  226. static int ppp_comm_disable(sdla_t *card);
  227. static int ppp_comm_disable_shutdown(sdla_t *card);
  228. static int ppp_get_err_stats(sdla_t *card);
  229. static int ppp_send(sdla_t *card, void *data, unsigned len, unsigned proto);
  230. static int ppp_error(sdla_t *card, int err, ppp_mbox_t *mb);
  231. static void wpp_isr(sdla_t *card);
  232. static void rx_intr(sdla_t *card);
  233. static void event_intr(sdla_t *card);
  234. static void timer_intr(sdla_t *card);
  235. /* Background polling routines */
  236. static void process_route(sdla_t *card);
  237. static void retrigger_comm(sdla_t *card);
  238. /* Miscellaneous functions */
  239. static int read_info( sdla_t *card );
  240. static int read_connection_info (sdla_t *card);
  241. static void remove_route( sdla_t *card );
  242. static int config508(struct net_device *dev, sdla_t *card);
  243. static void show_disc_cause(sdla_t * card, unsigned cause);
  244. static int reply_udp( unsigned char *data, unsigned int mbox_len );
  245. static void process_udp_mgmt_pkt(sdla_t *card, struct net_device *dev,
  246. ppp_private_area_t *ppp_priv_area);
  247. static void init_ppp_tx_rx_buff( sdla_t *card );
  248. static int intr_test( sdla_t *card );
  249. static int udp_pkt_type( struct sk_buff *skb , sdla_t *card);
  250. static void init_ppp_priv_struct( ppp_private_area_t *ppp_priv_area);
  251. static void init_global_statistics( sdla_t *card );
  252. static int tokenize(char *str, char **tokens);
  253. static char* strstrip(char *str, char *s);
  254. static int chk_bcast_mcast_addr(sdla_t* card, struct net_device* dev,
  255. struct sk_buff *skb);
  256. static int config_ppp (sdla_t *);
  257. static void ppp_poll(struct net_device *dev);
  258. static void trigger_ppp_poll(struct net_device *dev);
  259. static void ppp_poll_delay (unsigned long dev_ptr);
  260. static int Read_connection_info;
  261. static int Intr_test_counter;
  262. static unsigned short available_buffer_space;
  263. /* IPX functions */
  264. static void switch_net_numbers(unsigned char *sendpacket, unsigned long network_number,
  265. unsigned char incoming);
  266. static int handle_IPXWAN(unsigned char *sendpacket, char *devname, unsigned char enable_PX,
  267. unsigned long network_number, unsigned short proto);
  268. /* Lock Functions */
  269. static void s508_lock (sdla_t *card, unsigned long *smp_flags);
  270. static void s508_unlock (sdla_t *card, unsigned long *smp_flags);
  271. static int store_udp_mgmt_pkt(char udp_pkt_src, sdla_t* card,
  272. struct sk_buff *skb, struct net_device* dev,
  273. ppp_private_area_t* ppp_priv_area );
  274. static unsigned short calc_checksum (char *data, int len);
  275. static void disable_comm (sdla_t *card);
  276. static int detect_and_fix_tx_bug (sdla_t *card);
  277. /****** Public Functions ****************************************************/
  278. /*============================================================================
  279. * PPP protocol initialization routine.
  280. *
  281. * This routine is called by the main WANPIPE module during setup. At this
  282. * point adapter is completely initialized and firmware is running.
  283. * o read firmware version (to make sure it's alive)
  284. * o configure adapter
  285. * o initialize protocol-specific fields of the adapter data space.
  286. *
  287. * Return: 0 o.k.
  288. * < 0 failure.
  289. */
  290. int wpp_init(sdla_t *card, wandev_conf_t *conf)
  291. {
  292. ppp_flags_t *flags;
  293. union
  294. {
  295. char str[80];
  296. } u;
  297. /* Verify configuration ID */
  298. if (conf->config_id != WANCONFIG_PPP) {
  299. printk(KERN_INFO "%s: invalid configuration ID %u!\n",
  300. card->devname, conf->config_id);
  301. return -EINVAL;
  302. }
  303. /* Initialize miscellaneous pointers to structures on the adapter */
  304. switch (card->hw.type) {
  305. case SDLA_S508:
  306. card->mbox =(void*)(card->hw.dpmbase + PPP508_MB_OFFS);
  307. card->flags=(void*)(card->hw.dpmbase + PPP508_FLG_OFFS);
  308. break;
  309. case SDLA_S514:
  310. card->mbox =(void*)(card->hw.dpmbase + PPP514_MB_OFFS);
  311. card->flags=(void*)(card->hw.dpmbase + PPP514_FLG_OFFS);
  312. break;
  313. default:
  314. return -EINVAL;
  315. }
  316. flags = card->flags;
  317. /* Read firmware version. Note that when adapter initializes, it
  318. * clears the mailbox, so it may appear that the first command was
  319. * executed successfully when in fact it was merely erased. To work
  320. * around this, we execute the first command twice.
  321. */
  322. if (ppp_read_version(card, NULL) || ppp_read_version(card, u.str))
  323. return -EIO;
  324. printk(KERN_INFO "%s: running PPP firmware v%s\n",card->devname, u.str);
  325. /* Adjust configuration and set defaults */
  326. card->wandev.mtu = (conf->mtu) ?
  327. min_t(unsigned int, conf->mtu, PPP_MAX_MTU) : PPP_DFLT_MTU;
  328. card->wandev.bps = conf->bps;
  329. card->wandev.interface = conf->interface;
  330. card->wandev.clocking = conf->clocking;
  331. card->wandev.station = conf->station;
  332. card->isr = &wpp_isr;
  333. card->poll = NULL;
  334. card->exec = &wpp_exec;
  335. card->wandev.update = &update;
  336. card->wandev.new_if = &new_if;
  337. card->wandev.del_if = &del_if;
  338. card->wandev.udp_port = conf->udp_port;
  339. card->wandev.ttl = conf->ttl;
  340. card->wandev.state = WAN_DISCONNECTED;
  341. card->disable_comm = &disable_comm;
  342. card->irq_dis_if_send_count = 0;
  343. card->irq_dis_poll_count = 0;
  344. card->u.p.authenticator = conf->u.ppp.authenticator;
  345. card->u.p.ip_mode = conf->u.ppp.ip_mode ?
  346. conf->u.ppp.ip_mode : WANOPT_PPP_STATIC;
  347. card->TracingEnabled = 0;
  348. Read_connection_info = 1;
  349. /* initialize global statistics */
  350. init_global_statistics( card );
  351. if (!card->configured){
  352. int err;
  353. Intr_test_counter = 0;
  354. err = intr_test(card);
  355. if(err || (Intr_test_counter < MAX_INTR_TEST_COUNTER)) {
  356. printk("%s: Interrupt Test Failed, Counter: %i\n",
  357. card->devname, Intr_test_counter);
  358. printk( "%s: Please choose another interrupt\n",card->devname);
  359. return -EIO;
  360. }
  361. printk(KERN_INFO "%s: Interrupt Test Passed, Counter: %i\n",
  362. card->devname, Intr_test_counter);
  363. card->configured = 1;
  364. }
  365. ppp_set_intr_mode(card, PPP_INTR_TIMER);
  366. /* Turn off the transmit and timer interrupt */
  367. flags->imask &= ~PPP_INTR_TIMER;
  368. printk(KERN_INFO "\n");
  369. return 0;
  370. }
  371. /******* WAN Device Driver Entry Points *************************************/
  372. /*============================================================================
  373. * Update device status & statistics.
  374. */
  375. static int update(struct wan_device *wandev)
  376. {
  377. sdla_t* card = wandev->private;
  378. struct net_device* dev;
  379. volatile ppp_private_area_t *ppp_priv_area;
  380. ppp_flags_t *flags = card->flags;
  381. unsigned long timeout;
  382. /* sanity checks */
  383. if ((wandev == NULL) || (wandev->private == NULL))
  384. return -EFAULT;
  385. if (wandev->state == WAN_UNCONFIGURED)
  386. return -ENODEV;
  387. /* Shutdown bug fix. This function can be
  388. * called with NULL dev pointer during
  389. * shutdown
  390. */
  391. if ((dev=card->wandev.dev) == NULL){
  392. return -ENODEV;
  393. }
  394. if ((ppp_priv_area=dev->priv) == NULL){
  395. return -ENODEV;
  396. }
  397. ppp_priv_area->update_comms_stats = 2;
  398. ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_UPDATE;
  399. flags->imask |= PPP_INTR_TIMER;
  400. /* wait a maximum of 1 second for the statistics to be updated */
  401. timeout = jiffies;
  402. for(;;) {
  403. if(ppp_priv_area->update_comms_stats == 0){
  404. break;
  405. }
  406. if ((jiffies - timeout) > (1 * HZ)){
  407. ppp_priv_area->update_comms_stats = 0;
  408. ppp_priv_area->timer_int_enabled &=
  409. ~TMR_INT_ENABLED_UPDATE;
  410. return -EAGAIN;
  411. }
  412. }
  413. return 0;
  414. }
  415. /*============================================================================
  416. * Create new logical channel.
  417. * This routine is called by the router when ROUTER_IFNEW IOCTL is being
  418. * handled.
  419. * o parse media- and hardware-specific configuration
  420. * o make sure that a new channel can be created
  421. * o allocate resources, if necessary
  422. * o prepare network device structure for registaration.
  423. *
  424. * Return: 0 o.k.
  425. * < 0 failure (channel will not be created)
  426. */
  427. static int new_if(struct wan_device *wandev, struct net_device *dev,
  428. wanif_conf_t *conf)
  429. {
  430. sdla_t *card = wandev->private;
  431. ppp_private_area_t *ppp_priv_area;
  432. if (wandev->ndev)
  433. return -EEXIST;
  434. printk(KERN_INFO "%s: Configuring Interface: %s\n",
  435. card->devname, conf->name);
  436. if ((conf->name[0] == '\0') || (strlen(conf->name) > WAN_IFNAME_SZ)) {
  437. printk(KERN_INFO "%s: Invalid interface name!\n",
  438. card->devname);
  439. return -EINVAL;
  440. }
  441. /* allocate and initialize private data */
  442. ppp_priv_area = kmalloc(sizeof(ppp_private_area_t), GFP_KERNEL);
  443. if( ppp_priv_area == NULL )
  444. return -ENOMEM;
  445. memset(ppp_priv_area, 0, sizeof(ppp_private_area_t));
  446. ppp_priv_area->card = card;
  447. /* initialize data */
  448. strcpy(card->u.p.if_name, conf->name);
  449. /* initialize data in ppp_private_area structure */
  450. init_ppp_priv_struct( ppp_priv_area );
  451. ppp_priv_area->mc = conf->mc;
  452. ppp_priv_area->pap = conf->pap;
  453. ppp_priv_area->chap = conf->chap;
  454. /* Option to bring down the interface when
  455. * the link goes down */
  456. if (conf->if_down){
  457. set_bit(DYN_OPT_ON,&ppp_priv_area->interface_down);
  458. printk("%s: Dynamic interface configuration enabled\n",
  459. card->devname);
  460. }
  461. /* If no user ids are specified */
  462. if(!strlen(conf->userid) && (ppp_priv_area->pap||ppp_priv_area->chap)){
  463. kfree(ppp_priv_area);
  464. return -EINVAL;
  465. }
  466. /* If no passwords are specified */
  467. if(!strlen(conf->passwd) && (ppp_priv_area->pap||ppp_priv_area->chap)){
  468. kfree(ppp_priv_area);
  469. return -EINVAL;
  470. }
  471. if(strlen(conf->sysname) > 31){
  472. kfree(ppp_priv_area);
  473. return -EINVAL;
  474. }
  475. /* If no system name is specified */
  476. if(!strlen(conf->sysname) && (card->u.p.authenticator)){
  477. kfree(ppp_priv_area);
  478. return -EINVAL;
  479. }
  480. /* copy the data into the ppp private structure */
  481. memcpy(ppp_priv_area->userid, conf->userid, strlen(conf->userid));
  482. memcpy(ppp_priv_area->passwd, conf->passwd, strlen(conf->passwd));
  483. memcpy(ppp_priv_area->sysname, conf->sysname, strlen(conf->sysname));
  484. ppp_priv_area->enable_IPX = conf->enable_IPX;
  485. if (conf->network_number){
  486. ppp_priv_area->network_number = conf->network_number;
  487. }else{
  488. ppp_priv_area->network_number = 0xDEADBEEF;
  489. }
  490. /* Tells us that if this interface is a
  491. * gateway or not */
  492. if ((ppp_priv_area->gateway = conf->gateway) == WANOPT_YES){
  493. printk(KERN_INFO "%s: Interface %s is set as a gateway.\n",
  494. card->devname,card->u.p.if_name);
  495. }
  496. /* prepare network device data space for registration */
  497. strcpy(dev->name,card->u.p.if_name);
  498. dev->init = &if_init;
  499. dev->priv = ppp_priv_area;
  500. dev->mtu = min_t(unsigned int, dev->mtu, card->wandev.mtu);
  501. /* Initialize the polling work routine */
  502. INIT_WORK(&ppp_priv_area->poll_work, (void*)(void*)ppp_poll, dev);
  503. /* Initialize the polling delay timer */
  504. init_timer(&ppp_priv_area->poll_delay_timer);
  505. ppp_priv_area->poll_delay_timer.data = (unsigned long)dev;
  506. ppp_priv_area->poll_delay_timer.function = ppp_poll_delay;
  507. /* Since we start with dummy IP addresses we can say
  508. * that route exists */
  509. printk(KERN_INFO "\n");
  510. return 0;
  511. }
  512. /*============================================================================
  513. * Delete logical channel.
  514. */
  515. static int del_if(struct wan_device *wandev, struct net_device *dev)
  516. {
  517. return 0;
  518. }
  519. static void disable_comm (sdla_t *card)
  520. {
  521. ppp_comm_disable_shutdown(card);
  522. return;
  523. }
  524. /****** WANPIPE-specific entry points ***************************************/
  525. /*============================================================================
  526. * Execute adapter interface command.
  527. */
  528. //FIXME: Why do we need this ????
  529. static int wpp_exec(struct sdla *card, void *u_cmd, void *u_data)
  530. {
  531. ppp_mbox_t *mbox = card->mbox;
  532. int len;
  533. if (copy_from_user((void*)&mbox->cmd, u_cmd, sizeof(ppp_cmd_t)))
  534. return -EFAULT;
  535. len = mbox->cmd.length;
  536. if (len) {
  537. if( copy_from_user((void*)&mbox->data, u_data, len))
  538. return -EFAULT;
  539. }
  540. /* execute command */
  541. if (!sdla_exec(mbox))
  542. return -EIO;
  543. /* return result */
  544. if( copy_to_user(u_cmd, (void*)&mbox->cmd, sizeof(ppp_cmd_t)))
  545. return -EFAULT;
  546. len = mbox->cmd.length;
  547. if (len && u_data && copy_to_user(u_data, (void*)&mbox->data, len))
  548. return -EFAULT;
  549. return 0;
  550. }
  551. /****** Network Device Interface ********************************************/
  552. /*============================================================================
  553. * Initialize Linux network interface.
  554. *
  555. * This routine is called only once for each interface, during Linux network
  556. * interface registration. Returning anything but zero will fail interface
  557. * registration.
  558. */
  559. static int if_init(struct net_device *dev)
  560. {
  561. ppp_private_area_t *ppp_priv_area = dev->priv;
  562. sdla_t *card = ppp_priv_area->card;
  563. struct wan_device *wandev = &card->wandev;
  564. /* Initialize device driver entry points */
  565. dev->open = &if_open;
  566. dev->stop = &if_close;
  567. dev->hard_header = &if_header;
  568. dev->rebuild_header = &if_rebuild_hdr;
  569. dev->hard_start_xmit = &if_send;
  570. dev->get_stats = &if_stats;
  571. dev->tx_timeout = &if_tx_timeout;
  572. dev->watchdog_timeo = TX_TIMEOUT;
  573. /* Initialize media-specific parameters */
  574. dev->type = ARPHRD_PPP; /* ARP h/w type */
  575. dev->flags |= IFF_POINTOPOINT;
  576. dev->flags |= IFF_NOARP;
  577. /* Enable Mulitcasting if specified by user*/
  578. if (ppp_priv_area->mc == WANOPT_YES){
  579. dev->flags |= IFF_MULTICAST;
  580. }
  581. dev->mtu = wandev->mtu;
  582. dev->hard_header_len = PPP_HDR_LEN; /* media header length */
  583. /* Initialize hardware parameters (just for reference) */
  584. dev->irq = wandev->irq;
  585. dev->dma = wandev->dma;
  586. dev->base_addr = wandev->ioport;
  587. dev->mem_start = wandev->maddr;
  588. dev->mem_end = wandev->maddr + wandev->msize - 1;
  589. /* Set transmit buffer queue length */
  590. dev->tx_queue_len = 100;
  591. SET_MODULE_OWNER(dev);
  592. return 0;
  593. }
  594. /*============================================================================
  595. * Open network interface.
  596. * o enable communications and interrupts.
  597. * o prevent module from unloading by incrementing use count
  598. *
  599. * Return 0 if O.k. or errno.
  600. */
  601. static int if_open(struct net_device *dev)
  602. {
  603. ppp_private_area_t *ppp_priv_area = dev->priv;
  604. sdla_t *card = ppp_priv_area->card;
  605. struct timeval tv;
  606. //unsigned long smp_flags;
  607. if (netif_running(dev))
  608. return -EBUSY;
  609. wanpipe_open(card);
  610. netif_start_queue(dev);
  611. do_gettimeofday( &tv );
  612. ppp_priv_area->router_start_time = tv.tv_sec;
  613. /* We cannot configure the card here because we don't
  614. * have access to the interface IP addresses.
  615. * Once the interface initilization is complete, we will be
  616. * able to access the IP addresses. Therefore,
  617. * configure the ppp link in the poll routine */
  618. set_bit(0,&ppp_priv_area->config_ppp);
  619. ppp_priv_area->config_wait_timeout=jiffies;
  620. /* Start the PPP configuration after 1sec delay.
  621. * This will give the interface initilization time
  622. * to finish its configuration */
  623. mod_timer(&ppp_priv_area->poll_delay_timer, jiffies + HZ);
  624. return 0;
  625. }
  626. /*============================================================================
  627. * Close network interface.
  628. * o if this is the last open, then disable communications and interrupts.
  629. * o reset flags.
  630. */
  631. static int if_close(struct net_device *dev)
  632. {
  633. ppp_private_area_t *ppp_priv_area = dev->priv;
  634. sdla_t *card = ppp_priv_area->card;
  635. netif_stop_queue(dev);
  636. wanpipe_close(card);
  637. del_timer (&ppp_priv_area->poll_delay_timer);
  638. return 0;
  639. }
  640. /*============================================================================
  641. * Build media header.
  642. *
  643. * The trick here is to put packet type (Ethertype) into 'protocol' field of
  644. * the socket buffer, so that we don't forget it. If packet type is not
  645. * supported, set skb->protocol to 0 and discard packet later.
  646. *
  647. * Return: media header length.
  648. */
  649. static int if_header(struct sk_buff *skb, struct net_device *dev,
  650. unsigned short type, void *daddr, void *saddr, unsigned len)
  651. {
  652. switch (type)
  653. {
  654. case ETH_P_IP:
  655. case ETH_P_IPX:
  656. skb->protocol = htons(type);
  657. break;
  658. default:
  659. skb->protocol = 0;
  660. }
  661. return PPP_HDR_LEN;
  662. }
  663. /*============================================================================
  664. * Re-build media header.
  665. *
  666. * Return: 1 physical address resolved.
  667. * 0 physical address not resolved
  668. */
  669. static int if_rebuild_hdr (struct sk_buff *skb)
  670. {
  671. struct net_device *dev = skb->dev;
  672. ppp_private_area_t *ppp_priv_area = dev->priv;
  673. sdla_t *card = ppp_priv_area->card;
  674. printk(KERN_INFO "%s: rebuild_header() called for interface %s!\n",
  675. card->devname, dev->name);
  676. return 1;
  677. }
  678. /*============================================================================
  679. * Handle transmit timeout event from netif watchdog
  680. */
  681. static void if_tx_timeout(struct net_device *dev)
  682. {
  683. ppp_private_area_t* chan = dev->priv;
  684. sdla_t *card = chan->card;
  685. /* If our device stays busy for at least 5 seconds then we will
  686. * kick start the device by making dev->tbusy = 0. We expect
  687. * that our device never stays busy more than 5 seconds. So this
  688. * is only used as a last resort.
  689. */
  690. ++ chan->if_send_stat.if_send_tbusy;
  691. ++card->wandev.stats.collisions;
  692. printk (KERN_INFO "%s: Transmit timed out on %s\n", card->devname,dev->name);
  693. ++chan->if_send_stat.if_send_tbusy_timeout;
  694. netif_wake_queue (dev);
  695. }
  696. /*============================================================================
  697. * Send a packet on a network interface.
  698. * o set tbusy flag (marks start of the transmission) to block a timer-based
  699. * transmit from overlapping.
  700. * o check link state. If link is not up, then drop the packet.
  701. * o execute adapter send command.
  702. * o free socket buffer
  703. *
  704. * Return: 0 complete (socket buffer must be freed)
  705. * non-0 packet may be re-transmitted (tbusy must be set)
  706. *
  707. * Notes:
  708. * 1. This routine is called either by the protocol stack or by the "net
  709. * bottom half" (with interrupts enabled).
  710. * 2. Setting tbusy flag will inhibit further transmit requests from the
  711. * protocol stack and can be used for flow control with protocol layer.
  712. */
  713. static int if_send (struct sk_buff *skb, struct net_device *dev)
  714. {
  715. ppp_private_area_t *ppp_priv_area = dev->priv;
  716. sdla_t *card = ppp_priv_area->card;
  717. unsigned char *sendpacket;
  718. unsigned long smp_flags;
  719. ppp_flags_t *flags = card->flags;
  720. int udp_type;
  721. int err=0;
  722. ++ppp_priv_area->if_send_stat.if_send_entry;
  723. netif_stop_queue(dev);
  724. if (skb == NULL) {
  725. /* If we get here, some higher layer thinks we've missed an
  726. * tx-done interrupt.
  727. */
  728. printk(KERN_INFO "%s: interface %s got kicked!\n",
  729. card->devname, dev->name);
  730. ++ppp_priv_area->if_send_stat.if_send_skb_null;
  731. netif_wake_queue(dev);
  732. return 0;
  733. }
  734. sendpacket = skb->data;
  735. udp_type = udp_pkt_type( skb, card );
  736. if (udp_type == UDP_PTPIPE_TYPE){
  737. if(store_udp_mgmt_pkt(UDP_PKT_FRM_STACK, card, skb, dev,
  738. ppp_priv_area)){
  739. flags->imask |= PPP_INTR_TIMER;
  740. }
  741. ++ppp_priv_area->if_send_stat.if_send_PIPE_request;
  742. netif_start_queue(dev);
  743. return 0;
  744. }
  745. /* Check for broadcast and multicast addresses
  746. * If found, drop (deallocate) a packet and return.
  747. */
  748. if(chk_bcast_mcast_addr(card, dev, skb)){
  749. ++card->wandev.stats.tx_dropped;
  750. dev_kfree_skb_any(skb);
  751. netif_start_queue(dev);
  752. return 0;
  753. }
  754. if(card->hw.type != SDLA_S514){
  755. s508_lock(card,&smp_flags);
  756. }
  757. if (test_and_set_bit(SEND_CRIT, (void*)&card->wandev.critical)) {
  758. printk(KERN_INFO "%s: Critical in if_send: %lx\n",
  759. card->wandev.name,card->wandev.critical);
  760. ++card->wandev.stats.tx_dropped;
  761. ++ppp_priv_area->if_send_stat.if_send_critical_non_ISR;
  762. netif_start_queue(dev);
  763. goto if_send_exit_crit;
  764. }
  765. if (card->wandev.state != WAN_CONNECTED) {
  766. ++ppp_priv_area->if_send_stat.if_send_wan_disconnected;
  767. ++card->wandev.stats.tx_dropped;
  768. netif_start_queue(dev);
  769. } else if (!skb->protocol) {
  770. ++ppp_priv_area->if_send_stat.if_send_protocol_error;
  771. ++card->wandev.stats.tx_errors;
  772. netif_start_queue(dev);
  773. } else {
  774. /*If it's IPX change the network numbers to 0 if they're ours.*/
  775. if( skb->protocol == htons(ETH_P_IPX) ) {
  776. if(ppp_priv_area->enable_IPX) {
  777. switch_net_numbers( skb->data,
  778. ppp_priv_area->network_number, 0);
  779. } else {
  780. ++card->wandev.stats.tx_dropped;
  781. netif_start_queue(dev);
  782. goto if_send_exit_crit;
  783. }
  784. }
  785. if (ppp_send(card, skb->data, skb->len, skb->protocol)) {
  786. netif_stop_queue(dev);
  787. ++ppp_priv_area->if_send_stat.if_send_adptr_bfrs_full;
  788. ++ppp_priv_area->if_send_stat.if_send_tx_int_enabled;
  789. } else {
  790. ++ppp_priv_area->if_send_stat.if_send_bfr_passed_to_adptr;
  791. ++card->wandev.stats.tx_packets;
  792. card->wandev.stats.tx_bytes += skb->len;
  793. netif_start_queue(dev);
  794. dev->trans_start = jiffies;
  795. }
  796. }
  797. if_send_exit_crit:
  798. if (!(err=netif_queue_stopped(dev))){
  799. dev_kfree_skb_any(skb);
  800. }else{
  801. ppp_priv_area->tick_counter = jiffies;
  802. flags->imask |= PPP_INTR_TXRDY; /* unmask Tx interrupts */
  803. }
  804. clear_bit(SEND_CRIT,&card->wandev.critical);
  805. if(card->hw.type != SDLA_S514){
  806. s508_unlock(card,&smp_flags);
  807. }
  808. return err;
  809. }
  810. /*=============================================================================
  811. * Store a UDP management packet for later processing.
  812. */
  813. static int store_udp_mgmt_pkt(char udp_pkt_src, sdla_t* card,
  814. struct sk_buff *skb, struct net_device* dev,
  815. ppp_private_area_t* ppp_priv_area )
  816. {
  817. int udp_pkt_stored = 0;
  818. if(!ppp_priv_area->udp_pkt_lgth && (skb->len<=MAX_LGTH_UDP_MGNT_PKT)){
  819. ppp_priv_area->udp_pkt_lgth = skb->len;
  820. ppp_priv_area->udp_pkt_src = udp_pkt_src;
  821. memcpy(ppp_priv_area->udp_pkt_data, skb->data, skb->len);
  822. ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_UDP;
  823. ppp_priv_area->protocol = skb->protocol;
  824. udp_pkt_stored = 1;
  825. }else{
  826. if (skb->len > MAX_LGTH_UDP_MGNT_PKT){
  827. printk(KERN_INFO "%s: PIPEMON UDP request too long : %i\n",
  828. card->devname, skb->len);
  829. }else{
  830. printk(KERN_INFO "%s: PIPEMON UPD request already pending\n",
  831. card->devname);
  832. }
  833. ppp_priv_area->udp_pkt_lgth = 0;
  834. }
  835. if(udp_pkt_src == UDP_PKT_FRM_STACK){
  836. dev_kfree_skb_any(skb);
  837. }else{
  838. dev_kfree_skb_any(skb);
  839. }
  840. return(udp_pkt_stored);
  841. }
  842. /*============================================================================
  843. * Reply to UDP Management system.
  844. * Return length of reply.
  845. */
  846. static int reply_udp( unsigned char *data, unsigned int mbox_len )
  847. {
  848. unsigned short len, udp_length, temp, ip_length;
  849. unsigned long ip_temp;
  850. int even_bound = 0;
  851. ppp_udp_pkt_t *p_udp_pkt = (ppp_udp_pkt_t *)data;
  852. /* Set length of packet */
  853. len = sizeof(ip_pkt_t)+
  854. sizeof(udp_pkt_t)+
  855. sizeof(wp_mgmt_t)+
  856. sizeof(cblock_t)+
  857. mbox_len;
  858. /* fill in UDP reply */
  859. p_udp_pkt->wp_mgmt.request_reply = UDPMGMT_REPLY;
  860. /* fill in UDP length */
  861. udp_length = sizeof(udp_pkt_t)+
  862. sizeof(wp_mgmt_t)+
  863. sizeof(cblock_t)+
  864. mbox_len;
  865. /* put it on an even boundary */
  866. if ( udp_length & 0x0001 ) {
  867. udp_length += 1;
  868. len += 1;
  869. even_bound=1;
  870. }
  871. temp = (udp_length<<8)|(udp_length>>8);
  872. p_udp_pkt->udp_pkt.udp_length = temp;
  873. /* swap UDP ports */
  874. temp = p_udp_pkt->udp_pkt.udp_src_port;
  875. p_udp_pkt->udp_pkt.udp_src_port =
  876. p_udp_pkt->udp_pkt.udp_dst_port;
  877. p_udp_pkt->udp_pkt.udp_dst_port = temp;
  878. /* add UDP pseudo header */
  879. temp = 0x1100;
  880. *((unsigned short *)(p_udp_pkt->data+mbox_len+even_bound)) = temp;
  881. temp = (udp_length<<8)|(udp_length>>8);
  882. *((unsigned short *)(p_udp_pkt->data+mbox_len+even_bound+2)) = temp;
  883. /* calculate UDP checksum */
  884. p_udp_pkt->udp_pkt.udp_checksum = 0;
  885. p_udp_pkt->udp_pkt.udp_checksum =
  886. calc_checksum(&data[UDP_OFFSET],udp_length+UDP_OFFSET);
  887. /* fill in IP length */
  888. ip_length = udp_length + sizeof(ip_pkt_t);
  889. temp = (ip_length<<8)|(ip_length>>8);
  890. p_udp_pkt->ip_pkt.total_length = temp;
  891. /* swap IP addresses */
  892. ip_temp = p_udp_pkt->ip_pkt.ip_src_address;
  893. p_udp_pkt->ip_pkt.ip_src_address = p_udp_pkt->ip_pkt.ip_dst_address;
  894. p_udp_pkt->ip_pkt.ip_dst_address = ip_temp;
  895. /* fill in IP checksum */
  896. p_udp_pkt->ip_pkt.hdr_checksum = 0;
  897. p_udp_pkt->ip_pkt.hdr_checksum = calc_checksum(data,sizeof(ip_pkt_t));
  898. return len;
  899. } /* reply_udp */
  900. unsigned short calc_checksum (char *data, int len)
  901. {
  902. unsigned short temp;
  903. unsigned long sum=0;
  904. int i;
  905. for( i = 0; i <len; i+=2 ) {
  906. memcpy(&temp,&data[i],2);
  907. sum += (unsigned long)temp;
  908. }
  909. while (sum >> 16 ) {
  910. sum = (sum & 0xffffUL) + (sum >> 16);
  911. }
  912. temp = (unsigned short)sum;
  913. temp = ~temp;
  914. if( temp == 0 )
  915. temp = 0xffff;
  916. return temp;
  917. }
  918. /*
  919. If incoming is 0 (outgoing)- if the net numbers is ours make it 0
  920. if incoming is 1 - if the net number is 0 make it ours
  921. */
  922. static void switch_net_numbers(unsigned char *sendpacket, unsigned long network_number, unsigned char incoming)
  923. {
  924. unsigned long pnetwork_number;
  925. pnetwork_number = (unsigned long)((sendpacket[6] << 24) +
  926. (sendpacket[7] << 16) + (sendpacket[8] << 8) +
  927. sendpacket[9]);
  928. if (!incoming) {
  929. //If the destination network number is ours, make it 0
  930. if( pnetwork_number == network_number) {
  931. sendpacket[6] = sendpacket[7] = sendpacket[8] =
  932. sendpacket[9] = 0x00;
  933. }
  934. } else {
  935. //If the incoming network is 0, make it ours
  936. if( pnetwork_number == 0) {
  937. sendpacket[6] = (unsigned char)(network_number >> 24);
  938. sendpacket[7] = (unsigned char)((network_number &
  939. 0x00FF0000) >> 16);
  940. sendpacket[8] = (unsigned char)((network_number &
  941. 0x0000FF00) >> 8);
  942. sendpacket[9] = (unsigned char)(network_number &
  943. 0x000000FF);
  944. }
  945. }
  946. pnetwork_number = (unsigned long)((sendpacket[18] << 24) +
  947. (sendpacket[19] << 16) + (sendpacket[20] << 8) +
  948. sendpacket[21]);
  949. if( !incoming ) {
  950. //If the source network is ours, make it 0
  951. if( pnetwork_number == network_number) {
  952. sendpacket[18] = sendpacket[19] = sendpacket[20] =
  953. sendpacket[21] = 0x00;
  954. }
  955. } else {
  956. //If the source network is 0, make it ours
  957. if( pnetwork_number == 0 ) {
  958. sendpacket[18] = (unsigned char)(network_number >> 24);
  959. sendpacket[19] = (unsigned char)((network_number &
  960. 0x00FF0000) >> 16);
  961. sendpacket[20] = (unsigned char)((network_number &
  962. 0x0000FF00) >> 8);
  963. sendpacket[21] = (unsigned char)(network_number &
  964. 0x000000FF);
  965. }
  966. }
  967. } /* switch_net_numbers */
  968. /*============================================================================
  969. * Get ethernet-style interface statistics.
  970. * Return a pointer to struct net_device_stats.
  971. */
  972. static struct net_device_stats *if_stats(struct net_device *dev)
  973. {
  974. ppp_private_area_t *ppp_priv_area = dev->priv;
  975. sdla_t* card;
  976. if( ppp_priv_area == NULL )
  977. return NULL;
  978. card = ppp_priv_area->card;
  979. return &card->wandev.stats;
  980. }
  981. /****** PPP Firmware Interface Functions ************************************/
  982. /*============================================================================
  983. * Read firmware code version.
  984. * Put code version as ASCII string in str.
  985. */
  986. static int ppp_read_version(sdla_t *card, char *str)
  987. {
  988. ppp_mbox_t *mb = card->mbox;
  989. int err;
  990. memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
  991. mb->cmd.command = PPP_READ_CODE_VERSION;
  992. err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
  993. if (err != CMD_OK)
  994. ppp_error(card, err, mb);
  995. else if (str) {
  996. int len = mb->cmd.length;
  997. memcpy(str, mb->data, len);
  998. str[len] = '\0';
  999. }
  1000. return err;
  1001. }
  1002. /*===========================================================================
  1003. * Set Out-Bound Authentication.
  1004. */
  1005. static int ppp_set_outbnd_auth (sdla_t *card, ppp_private_area_t *ppp_priv_area)
  1006. {
  1007. ppp_mbox_t *mb = card->mbox;
  1008. int err;
  1009. memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
  1010. memset(&mb->data, 0, (strlen(ppp_priv_area->userid) +
  1011. strlen(ppp_priv_area->passwd) + 2 ) );
  1012. memcpy(mb->data, ppp_priv_area->userid, strlen(ppp_priv_area->userid));
  1013. memcpy((mb->data + strlen(ppp_priv_area->userid) + 1),
  1014. ppp_priv_area->passwd, strlen(ppp_priv_area->passwd));
  1015. mb->cmd.length = strlen(ppp_priv_area->userid) +
  1016. strlen(ppp_priv_area->passwd) + 2 ;
  1017. mb->cmd.command = PPP_SET_OUTBOUND_AUTH;
  1018. err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
  1019. if (err != CMD_OK)
  1020. ppp_error(card, err, mb);
  1021. return err;
  1022. }
  1023. /*===========================================================================
  1024. * Set In-Bound Authentication.
  1025. */
  1026. static int ppp_set_inbnd_auth (sdla_t *card, ppp_private_area_t *ppp_priv_area)
  1027. {
  1028. ppp_mbox_t *mb = card->mbox;
  1029. int err, i;
  1030. char* user_tokens[32];
  1031. char* pass_tokens[32];
  1032. int userids, passwds;
  1033. int add_ptr;
  1034. memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
  1035. memset(&mb->data, 0, 1008);
  1036. memcpy(mb->data, ppp_priv_area->sysname,
  1037. strlen(ppp_priv_area->sysname));
  1038. /* Parse the userid string and the password string and build a string
  1039. to copy it to the data area of the command structure. The string
  1040. will look like "SYS_NAME<NULL>USER1<NULL>PASS1<NULL>USER2<NULL>PASS2
  1041. ....<NULL> "
  1042. */
  1043. userids = tokenize( ppp_priv_area->userid, user_tokens);
  1044. passwds = tokenize( ppp_priv_area->passwd, pass_tokens);
  1045. if (userids != passwds){
  1046. printk(KERN_INFO "%s: Number of passwords does not equal the number of user ids\n", card->devname);
  1047. return 1;
  1048. }
  1049. add_ptr = strlen(ppp_priv_area->sysname) + 1;
  1050. for (i=0; i<userids; i++){
  1051. memcpy((mb->data + add_ptr), user_tokens[i],
  1052. strlen(user_tokens[i]));
  1053. memcpy((mb->data + add_ptr + strlen(user_tokens[i]) + 1),
  1054. pass_tokens[i], strlen(pass_tokens[i]));
  1055. add_ptr = add_ptr + strlen(user_tokens[i]) + 1 +
  1056. strlen(pass_tokens[i]) + 1;
  1057. }
  1058. mb->cmd.length = add_ptr + 1;
  1059. mb->cmd.command = PPP_SET_INBOUND_AUTH;
  1060. err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
  1061. if (err != CMD_OK)
  1062. ppp_error(card, err, mb);
  1063. return err;
  1064. }
  1065. /*============================================================================
  1066. * Tokenize string.
  1067. * Parse a string of the following syntax:
  1068. * <arg1>,<arg2>,...
  1069. * and fill array of tokens with pointers to string elements.
  1070. *
  1071. */
  1072. static int tokenize (char *str, char **tokens)
  1073. {
  1074. int cnt = 0;
  1075. tokens[0] = strsep(&str, "/");
  1076. while (tokens[cnt] && (cnt < 32 - 1))
  1077. {
  1078. tokens[cnt] = strstrip(tokens[cnt], " \t");
  1079. tokens[++cnt] = strsep(&str, "/");
  1080. }
  1081. return cnt;
  1082. }
  1083. /*============================================================================
  1084. * Strip leading and trailing spaces off the string str.
  1085. */
  1086. static char* strstrip (char *str, char* s)
  1087. {
  1088. char *eos = str + strlen(str); /* -> end of string */
  1089. while (*str && strchr(s, *str))
  1090. ++str /* strip leading spaces */
  1091. ;
  1092. while ((eos > str) && strchr(s, *(eos - 1)))
  1093. --eos /* strip trailing spaces */
  1094. ;
  1095. *eos = '\0';
  1096. return str;
  1097. }
  1098. /*============================================================================
  1099. * Configure PPP firmware.
  1100. */
  1101. static int ppp_configure(sdla_t *card, void *data)
  1102. {
  1103. ppp_mbox_t *mb = card->mbox;
  1104. int data_len = sizeof(ppp508_conf_t);
  1105. int err;
  1106. memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
  1107. memcpy(mb->data, data, data_len);
  1108. mb->cmd.length = data_len;
  1109. mb->cmd.command = PPP_SET_CONFIG;
  1110. err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
  1111. if (err != CMD_OK)
  1112. ppp_error(card, err, mb);
  1113. return err;
  1114. }
  1115. /*============================================================================
  1116. * Set interrupt mode.
  1117. */
  1118. static int ppp_set_intr_mode(sdla_t *card, unsigned char mode)
  1119. {
  1120. ppp_mbox_t *mb = card->mbox;
  1121. ppp_intr_info_t *ppp_intr_data = (ppp_intr_info_t *) &mb->data[0];
  1122. int err;
  1123. memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
  1124. ppp_intr_data->i_enable = mode;
  1125. ppp_intr_data->irq = card->hw.irq;
  1126. mb->cmd.length = 2;
  1127. /* If timer has been enabled, set the timer delay to 1sec */
  1128. if (mode & 0x80){
  1129. ppp_intr_data->timer_len = 250; //5;//100; //250;
  1130. mb->cmd.length = 4;
  1131. }
  1132. mb->cmd.command = PPP_SET_INTR_FLAGS;
  1133. err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
  1134. if (err != CMD_OK)
  1135. ppp_error(card, err, mb);
  1136. return err;
  1137. }
  1138. /*============================================================================
  1139. * Enable communications.
  1140. */
  1141. static int ppp_comm_enable(sdla_t *card)
  1142. {
  1143. ppp_mbox_t *mb = card->mbox;
  1144. int err;
  1145. memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
  1146. mb->cmd.command = PPP_COMM_ENABLE;
  1147. err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
  1148. if (err != CMD_OK)
  1149. ppp_error(card, err, mb);
  1150. else
  1151. card->u.p.comm_enabled = 1;
  1152. return err;
  1153. }
  1154. /*============================================================================
  1155. * Disable communications.
  1156. */
  1157. static int ppp_comm_disable(sdla_t *card)
  1158. {
  1159. ppp_mbox_t *mb = card->mbox;
  1160. int err;
  1161. memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
  1162. mb->cmd.command = PPP_COMM_DISABLE;
  1163. err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
  1164. if (err != CMD_OK)
  1165. ppp_error(card, err, mb);
  1166. else
  1167. card->u.p.comm_enabled = 0;
  1168. return err;
  1169. }
  1170. static int ppp_comm_disable_shutdown(sdla_t *card)
  1171. {
  1172. ppp_mbox_t *mb = card->mbox;
  1173. ppp_intr_info_t *ppp_intr_data;
  1174. int err;
  1175. if (!mb){
  1176. return 1;
  1177. }
  1178. ppp_intr_data = (ppp_intr_info_t *) &mb->data[0];
  1179. /* Disable all interrupts */
  1180. memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
  1181. ppp_intr_data->i_enable = 0;
  1182. ppp_intr_data->irq = card->hw.irq;
  1183. mb->cmd.length = 2;
  1184. mb->cmd.command = PPP_SET_INTR_FLAGS;
  1185. err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
  1186. /* Disable communicatinons */
  1187. memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
  1188. mb->cmd.command = PPP_COMM_DISABLE;
  1189. err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
  1190. card->u.p.comm_enabled = 0;
  1191. return 0;
  1192. }
  1193. /*============================================================================
  1194. * Get communications error statistics.
  1195. */
  1196. static int ppp_get_err_stats(sdla_t *card)
  1197. {
  1198. ppp_mbox_t *mb = card->mbox;
  1199. int err;
  1200. memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
  1201. mb->cmd.command = PPP_READ_ERROR_STATS;
  1202. err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
  1203. if (err == CMD_OK) {
  1204. ppp_err_stats_t* stats = (void*)mb->data;
  1205. card->wandev.stats.rx_over_errors = stats->rx_overrun;
  1206. card->wandev.stats.rx_crc_errors = stats->rx_bad_crc;
  1207. card->wandev.stats.rx_missed_errors = stats->rx_abort;
  1208. card->wandev.stats.rx_length_errors = stats->rx_lost;
  1209. card->wandev.stats.tx_aborted_errors = stats->tx_abort;
  1210. } else
  1211. ppp_error(card, err, mb);
  1212. return err;
  1213. }
  1214. /*============================================================================
  1215. * Send packet.
  1216. * Return: 0 - o.k.
  1217. * 1 - no transmit buffers available
  1218. */
  1219. static int ppp_send (sdla_t *card, void *data, unsigned len, unsigned proto)
  1220. {
  1221. ppp_buf_ctl_t *txbuf = card->u.p.txbuf;
  1222. if (txbuf->flag)
  1223. return 1;
  1224. sdla_poke(&card->hw, txbuf->buf.ptr, data, len);
  1225. txbuf->length = len; /* frame length */
  1226. if (proto == htons(ETH_P_IPX))
  1227. txbuf->proto = 0x01; /* protocol ID */
  1228. else
  1229. txbuf->proto = 0x00; /* protocol ID */
  1230. txbuf->flag = 1; /* start transmission */
  1231. /* Update transmit buffer control fields */
  1232. card->u.p.txbuf = ++txbuf;
  1233. if ((void*)txbuf > card->u.p.txbuf_last)
  1234. card->u.p.txbuf = card->u.p.txbuf_base;
  1235. return 0;
  1236. }
  1237. /****** Firmware Error Handler **********************************************/
  1238. /*============================================================================
  1239. * Firmware error handler.
  1240. * This routine is called whenever firmware command returns non-zero
  1241. * return code.
  1242. *
  1243. * Return zero if previous command has to be cancelled.
  1244. */
  1245. static int ppp_error(sdla_t *card, int err, ppp_mbox_t *mb)
  1246. {
  1247. unsigned cmd = mb->cmd.command;
  1248. switch (err) {
  1249. case CMD_TIMEOUT:
  1250. printk(KERN_ERR "%s: command 0x%02X timed out!\n",
  1251. card->devname, cmd);
  1252. break;
  1253. default:
  1254. printk(KERN_INFO "%s: command 0x%02X returned 0x%02X!\n"
  1255. , card->devname, cmd, err);
  1256. }
  1257. return 0;
  1258. }
  1259. /****** Interrupt Handlers **************************************************/
  1260. /*============================================================================
  1261. * PPP interrupt service routine.
  1262. */
  1263. static void wpp_isr (sdla_t *card)
  1264. {
  1265. ppp_flags_t *flags = card->flags;
  1266. char *ptr = &flags->iflag;
  1267. struct net_device *dev = card->wandev.dev;
  1268. int i;
  1269. card->in_isr = 1;
  1270. ++card->statistics.isr_entry;
  1271. if (!dev && flags->iflag != PPP_INTR_CMD){
  1272. card->in_isr = 0;
  1273. flags->iflag = 0;
  1274. return;
  1275. }
  1276. if (test_bit(PERI_CRIT, (void*)&card->wandev.critical)) {
  1277. card->in_isr = 0;
  1278. flags->iflag = 0;
  1279. return;
  1280. }
  1281. if(card->hw.type != SDLA_S514){
  1282. if (test_bit(SEND_CRIT, (void*)&card->wandev.critical)) {
  1283. ++card->statistics.isr_already_critical;
  1284. printk (KERN_INFO "%s: Critical while in ISR!\n",
  1285. card->devname);
  1286. card->in_isr = 0;
  1287. flags->iflag = 0;
  1288. return;
  1289. }
  1290. }
  1291. switch (flags->iflag) {
  1292. case PPP_INTR_RXRDY: /* receive interrupt 0x01 (bit 0)*/
  1293. ++card->statistics.isr_rx;
  1294. rx_intr(card);
  1295. break;
  1296. case PPP_INTR_TXRDY: /* transmit interrupt 0x02 (bit 1)*/
  1297. ++card->statistics.isr_tx;
  1298. flags->imask &= ~PPP_INTR_TXRDY;
  1299. netif_wake_queue(dev);
  1300. break;
  1301. case PPP_INTR_CMD: /* interface command completed */
  1302. ++Intr_test_counter;
  1303. ++card->statistics.isr_intr_test;
  1304. break;
  1305. case PPP_INTR_MODEM: /* modem status change (DCD, CTS) 0x04 (bit 2)*/
  1306. case PPP_INTR_DISC: /* Data link disconnected 0x10 (bit 4)*/
  1307. case PPP_INTR_OPEN: /* Data link open 0x20 (bit 5)*/
  1308. case PPP_INTR_DROP_DTR: /* DTR drop timeout expired 0x40 bit 6 */
  1309. event_intr(card);
  1310. break;
  1311. case PPP_INTR_TIMER:
  1312. timer_intr(card);
  1313. break;
  1314. default: /* unexpected interrupt */
  1315. ++card->statistics.isr_spurious;
  1316. printk(KERN_INFO "%s: spurious interrupt 0x%02X!\n",
  1317. card->devname, flags->iflag);
  1318. printk(KERN_INFO "%s: ID Bytes = ",card->devname);
  1319. for(i = 0; i < 8; i ++)
  1320. printk(KERN_INFO "0x%02X ", *(ptr + 0x28 + i));
  1321. printk(KERN_INFO "\n");
  1322. }
  1323. card->in_isr = 0;
  1324. flags->iflag = 0;
  1325. return;
  1326. }
  1327. /*============================================================================
  1328. * Receive interrupt handler.
  1329. */
  1330. static void rx_intr(sdla_t *card)
  1331. {
  1332. ppp_buf_ctl_t *rxbuf = card->rxmb;
  1333. struct net_device *dev = card->wandev.dev;
  1334. ppp_private_area_t *ppp_priv_area;
  1335. struct sk_buff *skb;
  1336. unsigned len;
  1337. void *buf;
  1338. int i;
  1339. ppp_flags_t *flags = card->flags;
  1340. char *ptr = &flags->iflag;
  1341. int udp_type;
  1342. if (rxbuf->flag != 0x01) {
  1343. printk(KERN_INFO
  1344. "%s: corrupted Rx buffer @ 0x%X, flag = 0x%02X!\n",
  1345. card->devname, (unsigned)rxbuf, rxbuf->flag);
  1346. printk(KERN_INFO "%s: ID Bytes = ",card->devname);
  1347. for(i = 0; i < 8; i ++)
  1348. printk(KERN_INFO "0x%02X ", *(ptr + 0x28 + i));
  1349. printk(KERN_INFO "\n");
  1350. ++card->statistics.rx_intr_corrupt_rx_bfr;
  1351. /* Bug Fix: Mar 6 2000
  1352. * If we get a corrupted mailbox, it means that driver
  1353. * is out of sync with the firmware. There is no recovery.
  1354. * If we don't turn off all interrupts for this card
  1355. * the machine will crash.
  1356. */
  1357. printk(KERN_INFO "%s: Critical router failure ...!!!\n", card->devname);
  1358. printk(KERN_INFO "Please contact Sangoma Technologies !\n");
  1359. ppp_set_intr_mode(card,0);
  1360. return;
  1361. }
  1362. if (dev && netif_running(dev) && dev->priv){
  1363. len = rxbuf->length;
  1364. ppp_priv_area = dev->priv;
  1365. /* Allocate socket buffer */
  1366. skb = dev_alloc_skb(len);
  1367. if (skb != NULL) {
  1368. /* Copy data to the socket buffer */
  1369. unsigned addr = rxbuf->buf.ptr;
  1370. if ((addr + len) > card->u.p.rx_top + 1) {
  1371. unsigned tmp = card->u.p.rx_top - addr + 1;
  1372. buf = skb_put(skb, tmp);
  1373. sdla_peek(&card->hw, addr, buf, tmp);
  1374. addr = card->u.p.rx_base;
  1375. len -= tmp;
  1376. }
  1377. buf = skb_put(skb, len);
  1378. sdla_peek(&card->hw, addr, buf, len);
  1379. /* Decapsulate packet */
  1380. switch (rxbuf->proto) {
  1381. case 0x00:
  1382. skb->protocol = htons(ETH_P_IP);
  1383. break;
  1384. case 0x01:
  1385. skb->protocol = htons(ETH_P_IPX);
  1386. break;
  1387. }
  1388. udp_type = udp_pkt_type( skb, card );
  1389. if (udp_type == UDP_PTPIPE_TYPE){
  1390. /* Handle a UDP Request in Timer Interrupt */
  1391. if(store_udp_mgmt_pkt(UDP_PKT_FRM_NETWORK, card, skb, dev,
  1392. ppp_priv_area)){
  1393. flags->imask |= PPP_INTR_TIMER;
  1394. }
  1395. ++ppp_priv_area->rx_intr_stat.rx_intr_PIPE_request;
  1396. } else if (handle_IPXWAN(skb->data,card->devname,
  1397. ppp_priv_area->enable_IPX,
  1398. ppp_priv_area->network_number,
  1399. skb->protocol)) {
  1400. /* Handle an IPXWAN packet */
  1401. if( ppp_priv_area->enable_IPX) {
  1402. /* Make sure we are not already sending */
  1403. if (!test_bit(SEND_CRIT, &card->wandev.critical)){
  1404. ppp_send(card, skb->data, skb->len, htons(ETH_P_IPX));
  1405. }
  1406. dev_kfree_skb_any(skb);
  1407. } else {
  1408. ++card->wandev.stats.rx_dropped;
  1409. }
  1410. } else {
  1411. /* Pass data up the protocol stack */
  1412. skb->dev = dev;
  1413. skb->mac.raw = skb->data;
  1414. ++card->wandev.stats.rx_packets;
  1415. card->wandev.stats.rx_bytes += skb->len;
  1416. ++ppp_priv_area->rx_intr_stat.rx_intr_bfr_passed_to_stack;
  1417. netif_rx(skb);
  1418. dev->last_rx = jiffies;
  1419. }
  1420. } else {
  1421. if (net_ratelimit()){
  1422. printk(KERN_INFO "%s: no socket buffers available!\n",
  1423. card->devname);
  1424. }
  1425. ++card->wandev.stats.rx_dropped;
  1426. ++ppp_priv_area->rx_intr_stat.rx_intr_no_socket;
  1427. }
  1428. } else {
  1429. ++card->statistics.rx_intr_dev_not_started;
  1430. }
  1431. /* Release buffer element and calculate a pointer to the next one */
  1432. rxbuf->flag = 0x00;
  1433. card->rxmb = ++rxbuf;
  1434. if ((void*)rxbuf > card->u.p.rxbuf_last)
  1435. card->rxmb = card->u.p.rxbuf_base;
  1436. }
  1437. void event_intr (sdla_t *card)
  1438. {
  1439. struct net_device* dev = card->wandev.dev;
  1440. ppp_private_area_t* ppp_priv_area = dev->priv;
  1441. volatile ppp_flags_t *flags = card->flags;
  1442. switch (flags->iflag){
  1443. case PPP_INTR_MODEM: /* modem status change (DCD, CTS) 0x04 (bit 2)*/
  1444. if (net_ratelimit()){
  1445. printk (KERN_INFO "%s: Modem status: DCD=%s CTS=%s\n",
  1446. card->devname, DCD(flags->mstatus), CTS(flags->mstatus));
  1447. }
  1448. break;
  1449. case PPP_INTR_DISC: /* Data link disconnected 0x10 (bit 4)*/
  1450. NEX_PRINTK (KERN_INFO "Data link disconnected intr Cause %X\n",
  1451. flags->disc_cause);
  1452. if (flags->disc_cause &
  1453. (PPP_LOCAL_TERMINATION | PPP_DCD_CTS_DROP |
  1454. PPP_REMOTE_TERMINATION)) {
  1455. if (card->u.p.ip_mode == WANOPT_PPP_PEER) {
  1456. set_bit(0,&Read_connection_info);
  1457. }
  1458. wanpipe_set_state(card, WAN_DISCONNECTED);
  1459. show_disc_cause(card, flags->disc_cause);
  1460. ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_PPP_EVENT;
  1461. flags->imask |= PPP_INTR_TIMER;
  1462. trigger_ppp_poll(dev);
  1463. }
  1464. break;
  1465. case PPP_INTR_OPEN: /* Data link open 0x20 (bit 5)*/
  1466. NEX_PRINTK (KERN_INFO "%s: PPP Link Open, LCP=%s IP=%s\n",
  1467. card->devname,LCP(flags->lcp_state),
  1468. IP(flags->ip_state));
  1469. if (flags->lcp_state == 0x09 &&
  1470. (flags->ip_state == 0x09 || flags->ipx_state == 0x09)){
  1471. /* Initialize the polling timer and set the state
  1472. * to WAN_CONNNECTED */
  1473. /* BUG FIX: When the protocol restarts, during heavy
  1474. * traffic, board tx buffers and driver tx buffers
  1475. * can go out of sync. This checks the condition
  1476. * and if the tx buffers are out of sync, the
  1477. * protocols are restarted.
  1478. * I don't know why the board tx buffer is out
  1479. * of sync. It could be that a packets is tx
  1480. * while the link is down, but that is not
  1481. * possible. The other possiblility is that the
  1482. * firmware doesn't reinitialize properly.
  1483. * FIXME: A better fix should be found.
  1484. */
  1485. if (detect_and_fix_tx_bug(card)){
  1486. ppp_comm_disable(card);
  1487. wanpipe_set_state(card, WAN_DISCONNECTED);
  1488. ppp_priv_area->timer_int_enabled |=
  1489. TMR_INT_ENABLED_PPP_EVENT;
  1490. flags->imask |= PPP_INTR_TIMER;
  1491. break;
  1492. }
  1493. card->state_tick = jiffies;
  1494. wanpipe_set_state(card, WAN_CONNECTED);
  1495. NEX_PRINTK(KERN_INFO "CON: L Tx: %lx B Tx: %lx || L Rx %lx B Rx %lx\n",
  1496. (unsigned long)card->u.p.txbuf, *card->u.p.txbuf_next,
  1497. (unsigned long)card->rxmb, *card->u.p.rxbuf_next);
  1498. /* Tell timer interrupt that PPP event occurred */
  1499. ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_PPP_EVENT;
  1500. flags->imask |= PPP_INTR_TIMER;
  1501. /* If we are in PEER mode, we must first obtain the
  1502. * IP information and then go into the poll routine */
  1503. if (card->u.p.ip_mode != WANOPT_PPP_PEER){
  1504. trigger_ppp_poll(dev);
  1505. }
  1506. }
  1507. break;
  1508. case PPP_INTR_DROP_DTR: /* DTR drop timeout expired 0x40 bit 6 */
  1509. NEX_PRINTK(KERN_INFO "DTR Drop Timeout Interrrupt \n");
  1510. if (card->u.p.ip_mode == WANOPT_PPP_PEER) {
  1511. set_bit(0,&Read_connection_info);
  1512. }
  1513. wanpipe_set_state(card, WAN_DISCONNECTED);
  1514. show_disc_cause(card, flags->disc_cause);
  1515. ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_PPP_EVENT;
  1516. flags->imask |= PPP_INTR_TIMER;
  1517. trigger_ppp_poll(dev);
  1518. break;
  1519. default:
  1520. printk(KERN_INFO "%s: Error, Invalid PPP Event\n",card->devname);
  1521. }
  1522. }
  1523. /* TIMER INTERRUPT */
  1524. void timer_intr (sdla_t *card)
  1525. {
  1526. struct net_device* dev = card->wandev.dev;
  1527. ppp_private_area_t* ppp_priv_area = dev->priv;
  1528. ppp_flags_t *flags = card->flags;
  1529. if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_CONFIG){
  1530. if (!config_ppp(card)){
  1531. ppp_priv_area->timer_int_enabled &=
  1532. ~TMR_INT_ENABLED_CONFIG;
  1533. }
  1534. }
  1535. /* Update statistics */
  1536. if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_UPDATE){
  1537. ppp_get_err_stats(card);
  1538. if(!(--ppp_priv_area->update_comms_stats)){
  1539. ppp_priv_area->timer_int_enabled &=
  1540. ~TMR_INT_ENABLED_UPDATE;
  1541. }
  1542. }
  1543. /* PPIPEMON UDP request */
  1544. if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_UDP){
  1545. process_udp_mgmt_pkt(card,dev, ppp_priv_area);
  1546. ppp_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_UDP;
  1547. }
  1548. /* PPP Event */
  1549. if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_PPP_EVENT){
  1550. if (card->wandev.state == WAN_DISCONNECTED){
  1551. retrigger_comm(card);
  1552. }
  1553. /* If the state is CONNECTING, it means that communicatins were
  1554. * enabled. When the remote side enables its comminication we
  1555. * should get an interrupt PPP_INTR_OPEN, thus turn off polling
  1556. */
  1557. else if (card->wandev.state == WAN_CONNECTING){
  1558. /* Turn off the timer interrupt */
  1559. ppp_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_PPP_EVENT;
  1560. }
  1561. /* If state is connected and we are in PEER mode
  1562. * poll for an IP address which will be provided by remote end.
  1563. */
  1564. else if ((card->wandev.state == WAN_CONNECTED &&
  1565. card->u.p.ip_mode == WANOPT_PPP_PEER) &&
  1566. test_bit(0,&Read_connection_info)){
  1567. card->state_tick = jiffies;
  1568. if (read_connection_info (card)){
  1569. printk(KERN_INFO "%s: Failed to read PEER IP Addresses\n",
  1570. card->devname);
  1571. }else{
  1572. clear_bit(0,&Read_connection_info);
  1573. set_bit(1,&Read_connection_info);
  1574. trigger_ppp_poll(dev);
  1575. }
  1576. }else{
  1577. //FIXME Put the comment back int
  1578. ppp_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_PPP_EVENT;
  1579. }
  1580. }/* End of PPP_EVENT */
  1581. /* Only disable the timer interrupt if there are no udp, statistic */
  1582. /* updates or events pending */
  1583. if(!ppp_priv_area->timer_int_enabled) {
  1584. flags->imask &= ~PPP_INTR_TIMER;
  1585. }
  1586. }
  1587. static int handle_IPXWAN(unsigned char *sendpacket, char *devname, unsigned char enable_IPX, unsigned long network_number, unsigned short proto)
  1588. {
  1589. int i;
  1590. if( proto == htons(ETH_P_IPX) ) {
  1591. //It's an IPX packet
  1592. if(!enable_IPX) {
  1593. //Return 1 so we don't pass it up the stack.
  1594. return 1;
  1595. }
  1596. } else {
  1597. //It's not IPX so pass it up the stack.
  1598. return 0;
  1599. }
  1600. if( sendpacket[16] == 0x90 &&
  1601. sendpacket[17] == 0x04)
  1602. {
  1603. //It's IPXWAN
  1604. if( sendpacket[2] == 0x02 &&
  1605. sendpacket[34] == 0x00)
  1606. {
  1607. //It's a timer request packet
  1608. printk(KERN_INFO "%s: Received IPXWAN Timer Request packet\n",devname);
  1609. //Go through the routing options and answer no to every
  1610. //option except Unnumbered RIP/SAP
  1611. for(i = 41; sendpacket[i] == 0x00; i += 5)
  1612. {
  1613. //0x02 is the option for Unnumbered RIP/SAP
  1614. if( sendpacket[i + 4] != 0x02)
  1615. {
  1616. sendpacket[i + 1] = 0;
  1617. }
  1618. }
  1619. //Skip over the extended Node ID option
  1620. if( sendpacket[i] == 0x04 )
  1621. {
  1622. i += 8;
  1623. }
  1624. //We also want to turn off all header compression opt.
  1625. for(; sendpacket[i] == 0x80 ;)
  1626. {
  1627. sendpacket[i + 1] = 0;
  1628. i += (sendpacket[i + 2] << 8) + (sendpacket[i + 3]) + 4;
  1629. }
  1630. //Set the packet type to timer response
  1631. sendpacket[34] = 0x01;
  1632. printk(KERN_INFO "%s: Sending IPXWAN Timer Response\n",devname);
  1633. }
  1634. else if( sendpacket[34] == 0x02 )
  1635. {
  1636. //This is an information request packet
  1637. printk(KERN_INFO "%s: Received IPXWAN Information Request packet\n",devname);
  1638. //Set the packet type to information response
  1639. sendpacket[34] = 0x03;
  1640. //Set the router name
  1641. sendpacket[51] = 'P';
  1642. sendpacket[52] = 'T';
  1643. sendpacket[53] = 'P';
  1644. sendpacket[54] = 'I';
  1645. sendpacket[55] = 'P';
  1646. sendpacket[56] = 'E';
  1647. sendpacket[57] = '-';
  1648. sendpacket[58] = CVHexToAscii(network_number >> 28);
  1649. sendpacket[59] = CVHexToAscii((network_number & 0x0F000000)>> 24);
  1650. sendpacket[60] = CVHexToAscii((network_number & 0x00F00000)>> 20);
  1651. sendpacket[61] = CVHexToAscii((network_number & 0x000F0000)>> 16);
  1652. sendpacket[62] = CVHexToAscii((network_number & 0x0000F000)>> 12);
  1653. sendpacket[63] = CVHexToAscii((network_number & 0x00000F00)>> 8);
  1654. sendpacket[64] = CVHexToAscii((network_number & 0x000000F0)>> 4);
  1655. sendpacket[65] = CVHexToAscii(network_number & 0x0000000F);
  1656. for(i = 66; i < 99; i+= 1)
  1657. {
  1658. sendpacket[i] = 0;
  1659. }
  1660. printk(KERN_INFO "%s: Sending IPXWAN Information Response packet\n",devname);
  1661. }
  1662. else
  1663. {
  1664. printk(KERN_INFO "%s: Unknown IPXWAN packet!\n",devname);
  1665. return 0;
  1666. }
  1667. //Set the WNodeID to our network address
  1668. sendpacket[35] = (unsigned char)(network_number >> 24);
  1669. sendpacket[36] = (unsigned char)((network_number & 0x00FF0000) >> 16);
  1670. sendpacket[37] = (unsigned char)((network_number & 0x0000FF00) >> 8);
  1671. sendpacket[38] = (unsigned char)(network_number & 0x000000FF);
  1672. return 1;
  1673. } else {
  1674. //If we get here it's an IPX-data packet, so it'll get passed up the stack.
  1675. //switch the network numbers
  1676. switch_net_numbers(sendpacket, network_number, 1);
  1677. return 0;
  1678. }
  1679. }
  1680. /****** Background Polling Routines ****************************************/
  1681. /* All polling functions are invoked by the TIMER interrupt in the wpp_isr
  1682. * routine.
  1683. */
  1684. /*============================================================================
  1685. * Monitor active link phase.
  1686. */
  1687. static void process_route (sdla_t *card)
  1688. {
  1689. ppp_flags_t *flags = card->flags;
  1690. struct net_device *dev = card->wandev.dev;
  1691. ppp_private_area_t *ppp_priv_area = dev->priv;
  1692. if ((card->u.p.ip_mode == WANOPT_PPP_PEER) &&
  1693. (flags->ip_state == 0x09)){
  1694. /* We get ip_local from the firmware in PEER mode.
  1695. * Therefore, if ip_local is 0, we failed to obtain
  1696. * the remote IP address. */
  1697. if (ppp_priv_area->ip_local == 0)
  1698. return;
  1699. printk(KERN_INFO "%s: IPCP State Opened.\n", card->devname);
  1700. if (read_info( card )) {
  1701. printk(KERN_INFO
  1702. "%s: An error occurred in IP assignment.\n",
  1703. card->devname);
  1704. } else {
  1705. struct in_device *in_dev = dev->ip_ptr;
  1706. if (in_dev != NULL ) {
  1707. struct in_ifaddr *ifa = in_dev->ifa_list;
  1708. printk(KERN_INFO "%s: Assigned Lcl. Addr: %u.%u.%u.%u\n",
  1709. card->devname, NIPQUAD(ifa->ifa_local));
  1710. printk(KERN_INFO "%s: Assigned Rmt. Addr: %u.%u.%u.%u\n",
  1711. card->devname, NIPQUAD(ifa->ifa_address));
  1712. }else{
  1713. printk(KERN_INFO
  1714. "%s: Error: Failed to add a route for PPP interface %s\n",
  1715. card->devname,dev->name);
  1716. }
  1717. }
  1718. }
  1719. }
  1720. /*============================================================================
  1721. * Monitor physical link disconnected phase.
  1722. * o if interface is up and the hold-down timeout has expired, then retry
  1723. * connection.
  1724. */
  1725. static void retrigger_comm(sdla_t *card)
  1726. {
  1727. struct net_device *dev = card->wandev.dev;
  1728. if (dev && ((jiffies - card->state_tick) > HOLD_DOWN_TIME)) {
  1729. wanpipe_set_state(card, WAN_CONNECTING);
  1730. if(ppp_comm_enable(card) == CMD_OK){
  1731. init_ppp_tx_rx_buff( card );
  1732. }
  1733. }
  1734. }
  1735. /****** Miscellaneous Functions *********************************************/
  1736. /*============================================================================
  1737. * Configure S508 adapter.
  1738. */
  1739. static int config508(struct net_device *dev, sdla_t *card)
  1740. {
  1741. ppp508_conf_t cfg;
  1742. struct in_device *in_dev = dev->ip_ptr;
  1743. ppp_private_area_t *ppp_priv_area = dev->priv;
  1744. /* Prepare PPP configuration structure */
  1745. memset(&cfg, 0, sizeof(ppp508_conf_t));
  1746. if (card->wandev.clocking)
  1747. cfg.line_speed = card->wandev.bps;
  1748. if (card->wandev.interface == WANOPT_RS232)
  1749. cfg.conf_flags |= INTERFACE_LEVEL_RS232;
  1750. cfg.conf_flags |= DONT_TERMINATE_LNK_MAX_CONFIG; /*send Configure-Request packets forever*/
  1751. cfg.txbuf_percent = PERCENT_TX_BUFF; /* % of Tx bufs */
  1752. cfg.mtu_local = card->wandev.mtu;
  1753. cfg.mtu_remote = card->wandev.mtu; /* Default */
  1754. cfg.restart_tmr = TIME_BETWEEN_CONF_REQ; /* 30 = 3sec */
  1755. cfg.auth_rsrt_tmr = TIME_BETWEEN_PAP_CHAP_REQ; /* 30 = 3sec */
  1756. cfg.auth_wait_tmr = WAIT_PAP_CHAP_WITHOUT_REPLY; /* 300 = 30s */
  1757. cfg.mdm_fail_tmr = WAIT_AFTER_DCD_CTS_LOW; /* 5 = 0.5s */
  1758. cfg.dtr_drop_tmr = TIME_DCD_CTS_LOW_AFTER_LNK_DOWN; /* 10 = 1s */
  1759. cfg.connect_tmout = WAIT_DCD_HIGH_AFTER_ENABLE_COMM; /* 900 = 90s */
  1760. cfg.conf_retry = MAX_CONF_REQ_WITHOUT_REPLY; /* 10 = 1s */
  1761. cfg.term_retry = MAX_TERM_REQ_WITHOUT_REPLY; /* 2 times */
  1762. cfg.fail_retry = NUM_CONF_NAK_WITHOUT_REPLY; /* 5 times */
  1763. cfg.auth_retry = NUM_AUTH_REQ_WITHOUT_REPLY; /* 10 times */
  1764. if( !card->u.p.authenticator ) {
  1765. printk(KERN_INFO "%s: Device is not configured as an authenticator\n",
  1766. card->devname);
  1767. cfg.auth_options = NO_AUTHENTICATION;
  1768. }else{
  1769. printk(KERN_INFO "%s: Device is configured as an authenticator\n",
  1770. card->devname);
  1771. cfg.auth_options = INBOUND_AUTH;
  1772. }
  1773. if( ppp_priv_area->pap == WANOPT_YES){
  1774. cfg.auth_options |=PAP_AUTH;
  1775. printk(KERN_INFO "%s: Pap enabled\n", card->devname);
  1776. }
  1777. if( ppp_priv_area->chap == WANOPT_YES){
  1778. cfg.auth_options |= CHAP_AUTH;
  1779. printk(KERN_INFO "%s: Chap enabled\n", card->devname);
  1780. }
  1781. if (ppp_priv_area->enable_IPX == WANOPT_YES){
  1782. printk(KERN_INFO "%s: Enabling IPX Protocol\n",card->devname);
  1783. cfg.ipx_options = ENABLE_IPX | ROUTING_PROT_DEFAULT;
  1784. }else{
  1785. cfg.ipx_options = DISABLE_IPX;
  1786. }
  1787. switch (card->u.p.ip_mode) {
  1788. case WANOPT_PPP_STATIC:
  1789. printk(KERN_INFO "%s: PPP IP Mode: STATIC\n",card->devname);
  1790. cfg.ip_options = L_AND_R_IP_NO_ASSIG |
  1791. ENABLE_IP;
  1792. cfg.ip_local = in_dev->ifa_list->ifa_local;
  1793. cfg.ip_remote = in_dev->ifa_list->ifa_address;
  1794. /* Debugging code used to check that IP addresses
  1795. * obtained from the kernel are correct */
  1796. NEX_PRINTK(KERN_INFO "Local %u.%u.%u.%u Remote %u.%u.%u.%u Name %s\n",
  1797. NIPQUAD(ip_local),NIPQUAD(ip_remote), dev->name);
  1798. break;
  1799. case WANOPT_PPP_HOST:
  1800. printk(KERN_INFO "%s: PPP IP Mode: HOST\n",card->devname);
  1801. cfg.ip_options = L_IP_LOCAL_ASSIG |
  1802. R_IP_LOCAL_ASSIG |
  1803. ENABLE_IP;
  1804. cfg.ip_local = in_dev->ifa_list->ifa_local;
  1805. cfg.ip_remote = in_dev->ifa_list->ifa_address;
  1806. /* Debugging code used to check that IP addresses
  1807. * obtained from the kernel are correct */
  1808. NEX_PRINTK (KERN_INFO "Local %u.%u.%u.%u Remote %u.%u.%u.%u Name %s\n",
  1809. NIPQUAD(ip_local),NIPQUAD(ip_remote), dev->name);
  1810. break;
  1811. case WANOPT_PPP_PEER:
  1812. printk(KERN_INFO "%s: PPP IP Mode: PEER\n",card->devname);
  1813. cfg.ip_options = L_IP_REMOTE_ASSIG |
  1814. R_IP_REMOTE_ASSIG |
  1815. ENABLE_IP;
  1816. cfg.ip_local = 0x00;
  1817. cfg.ip_remote = 0x00;
  1818. break;
  1819. default:
  1820. printk(KERN_INFO "%s: ERROR: Unsupported PPP Mode Selected\n",
  1821. card->devname);
  1822. printk(KERN_INFO "%s: PPP IP Modes: STATIC, PEER or HOST\n",
  1823. card->devname);
  1824. return 1;
  1825. }
  1826. return ppp_configure(card, &cfg);
  1827. }
  1828. /*============================================================================
  1829. * Show disconnection cause.
  1830. */
  1831. static void show_disc_cause(sdla_t *card, unsigned cause)
  1832. {
  1833. if (cause & 0x0802)
  1834. printk(KERN_INFO "%s: link terminated by peer\n",
  1835. card->devname);
  1836. else if (cause & 0x0004)
  1837. printk(KERN_INFO "%s: link terminated by user\n",
  1838. card->devname);
  1839. else if (cause & 0x0008)
  1840. printk(KERN_INFO "%s: authentication failed\n", card->devname);
  1841. else if (cause & 0x0010)
  1842. printk(KERN_INFO
  1843. "%s: authentication protocol negotiation failed\n",
  1844. card->devname);
  1845. else if (cause & 0x0020)
  1846. printk(KERN_INFO
  1847. "%s: peer's request for authentication rejected\n",
  1848. card->devname);
  1849. else if (cause & 0x0040)
  1850. printk(KERN_INFO "%s: MRU option rejected by peer\n",
  1851. card->devname);
  1852. else if (cause & 0x0080)
  1853. printk(KERN_INFO "%s: peer's MRU was too small\n",
  1854. card->devname);
  1855. else if (cause & 0x0100)
  1856. printk(KERN_INFO "%s: failed to negotiate peer's LCP options\n",
  1857. card->devname);
  1858. else if (cause & 0x0200)
  1859. printk(KERN_INFO "%s: failed to negotiate peer's IPCP options\n"
  1860. , card->devname);
  1861. else if (cause & 0x0400)
  1862. printk(KERN_INFO
  1863. "%s: failed to negotiate peer's IPXCP options\n",
  1864. card->devname);
  1865. }
  1866. /*=============================================================================
  1867. * Process UDP call of type PTPIPEAB.
  1868. */
  1869. static void process_udp_mgmt_pkt(sdla_t *card, struct net_device *dev,
  1870. ppp_private_area_t *ppp_priv_area )
  1871. {
  1872. unsigned char buf2[5];
  1873. unsigned char *buf;
  1874. unsigned int frames, len;
  1875. struct sk_buff *new_skb;
  1876. unsigned short data_length, buffer_length, real_len;
  1877. unsigned long data_ptr;
  1878. int udp_mgmt_req_valid = 1;
  1879. ppp_mbox_t *mbox = card->mbox;
  1880. struct timeval tv;
  1881. int err;
  1882. ppp_udp_pkt_t *ppp_udp_pkt = (ppp_udp_pkt_t*)&ppp_priv_area->udp_pkt_data;
  1883. memcpy(&buf2, &card->wandev.udp_port, 2 );
  1884. if(ppp_priv_area->udp_pkt_src == UDP_PKT_FRM_NETWORK) {
  1885. switch(ppp_udp_pkt->cblock.command) {
  1886. case PPIPE_GET_IBA_DATA:
  1887. case PPP_READ_CONFIG:
  1888. case PPP_GET_CONNECTION_INFO:
  1889. case PPIPE_ROUTER_UP_TIME:
  1890. case PPP_READ_STATISTICS:
  1891. case PPP_READ_ERROR_STATS:
  1892. case PPP_READ_PACKET_STATS:
  1893. case PPP_READ_LCP_STATS:
  1894. case PPP_READ_IPCP_STATS:
  1895. case PPP_READ_IPXCP_STATS:
  1896. case PPP_READ_PAP_STATS:
  1897. case PPP_READ_CHAP_STATS:
  1898. case PPP_READ_CODE_VERSION:
  1899. udp_mgmt_req_valid = 1;
  1900. break;
  1901. default:
  1902. udp_mgmt_req_valid = 0;
  1903. break;
  1904. }
  1905. }
  1906. if(!udp_mgmt_req_valid) {
  1907. /* set length to 0 */
  1908. ppp_udp_pkt->cblock.length = 0x00;
  1909. /* set return code */
  1910. ppp_udp_pkt->cblock.result = 0xCD;
  1911. ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_direction_err;
  1912. if (net_ratelimit()){
  1913. printk(KERN_INFO
  1914. "%s: Warning, Illegal UDP command attempted from network: %x\n",
  1915. card->devname,ppp_udp_pkt->cblock.command);
  1916. }
  1917. } else {
  1918. /* Initialize the trace element */
  1919. trace_element_t trace_element;
  1920. switch (ppp_udp_pkt->cblock.command){
  1921. /* PPIPE_ENABLE_TRACING */
  1922. case PPIPE_ENABLE_TRACING:
  1923. if (!card->TracingEnabled) {
  1924. /* OPERATE_DATALINE_MONITOR */
  1925. mbox->cmd.command = PPP_DATALINE_MONITOR;
  1926. mbox->cmd.length = 0x01;
  1927. mbox->data[0] = ppp_udp_pkt->data[0];
  1928. err = sdla_exec(mbox) ?
  1929. mbox->cmd.result : CMD_TIMEOUT;
  1930. if (err != CMD_OK) {
  1931. ppp_error(card, err, mbox);
  1932. card->TracingEnabled = 0;
  1933. /* set the return code */
  1934. ppp_udp_pkt->cblock.result = mbox->cmd.result;
  1935. mbox->cmd.length = 0;
  1936. break;
  1937. }
  1938. sdla_peek(&card->hw, 0xC000, &buf2, 2);
  1939. ppp_priv_area->curr_trace_addr = 0;
  1940. memcpy(&ppp_priv_area->curr_trace_addr, &buf2, 2);
  1941. ppp_priv_area->start_trace_addr =
  1942. ppp_priv_area->curr_trace_addr;
  1943. ppp_priv_area->end_trace_addr =
  1944. ppp_priv_area->start_trace_addr + END_OFFSET;
  1945. /* MAX_SEND_BUFFER_SIZE - 28 (IP header)
  1946. - 32 (ppipemon CBLOCK) */
  1947. available_buffer_space = MAX_LGTH_UDP_MGNT_PKT -
  1948. sizeof(ip_pkt_t)-
  1949. sizeof(udp_pkt_t)-
  1950. sizeof(wp_mgmt_t)-
  1951. sizeof(cblock_t);
  1952. }
  1953. ppp_udp_pkt->cblock.result = 0;
  1954. mbox->cmd.length = 0;
  1955. card->TracingEnabled = 1;
  1956. break;
  1957. /* PPIPE_DISABLE_TRACING */
  1958. case PPIPE_DISABLE_TRACING:
  1959. if(card->TracingEnabled) {
  1960. /* OPERATE_DATALINE_MONITOR */
  1961. mbox->cmd.command = 0x33;
  1962. mbox->cmd.length = 1;
  1963. mbox->data[0] = 0x00;
  1964. err = sdla_exec(mbox) ?
  1965. mbox->cmd.result : CMD_TIMEOUT;
  1966. }
  1967. /*set return code*/
  1968. ppp_udp_pkt->cblock.result = 0;
  1969. mbox->cmd.length = 0;
  1970. card->TracingEnabled = 0;
  1971. break;
  1972. /* PPIPE_GET_TRACE_INFO */
  1973. case PPIPE_GET_TRACE_INFO:
  1974. if(!card->TracingEnabled) {
  1975. /* set return code */
  1976. ppp_udp_pkt->cblock.result = 1;
  1977. mbox->cmd.length = 0;
  1978. }
  1979. buffer_length = 0;
  1980. /* frames < 62, where 62 is the number of trace
  1981. information elements. There is in total 496
  1982. bytes of space and each trace information
  1983. element is 8 bytes.
  1984. */
  1985. for ( frames=0; frames<62; frames++) {
  1986. trace_pkt_t *trace_pkt = (trace_pkt_t *)
  1987. &ppp_udp_pkt->data[buffer_length];
  1988. /* Read the whole trace packet */
  1989. sdla_peek(&card->hw, ppp_priv_area->curr_trace_addr,
  1990. &trace_element, sizeof(trace_element_t));
  1991. /* no data on board so exit */
  1992. if( trace_element.opp_flag == 0x00 )
  1993. break;
  1994. data_ptr = trace_element.trace_data_ptr;
  1995. /* See if there is actual data on the trace buffer */
  1996. if (data_ptr){
  1997. data_length = trace_element.trace_length;
  1998. }else{
  1999. data_length = 0;
  2000. ppp_udp_pkt->data[0] |= 0x02;
  2001. }
  2002. //FIXME: Do we need this check
  2003. if ((available_buffer_space - buffer_length)
  2004. < (sizeof(trace_element_t)+1)){
  2005. /*indicate we have more frames
  2006. * on board and exit
  2007. */
  2008. ppp_udp_pkt->data[0] |= 0x02;
  2009. break;
  2010. }
  2011. trace_pkt->status = trace_element.trace_type;
  2012. trace_pkt->time_stamp = trace_element.trace_time_stamp;
  2013. trace_pkt->real_length = trace_element.trace_length;
  2014. real_len = trace_element.trace_length;
  2015. if(data_ptr == 0){
  2016. trace_pkt->data_avail = 0x00;
  2017. }else{
  2018. /* we can take it next time */
  2019. if ((available_buffer_space - buffer_length)<
  2020. (real_len + sizeof(trace_pkt_t))){
  2021. ppp_udp_pkt->data[0] |= 0x02;
  2022. break;
  2023. }
  2024. trace_pkt->data_avail = 0x01;
  2025. /* get the data */
  2026. sdla_peek(&card->hw, data_ptr,
  2027. &trace_pkt->data,
  2028. real_len);
  2029. }
  2030. /* zero the opp flag to
  2031. show we got the frame */
  2032. buf2[0] = 0x00;
  2033. sdla_poke(&card->hw, ppp_priv_area->curr_trace_addr,
  2034. &buf2, 1);
  2035. /* now move onto the next
  2036. frame */
  2037. ppp_priv_area->curr_trace_addr += 8;
  2038. /* check if we passed the last address */
  2039. if ( ppp_priv_area->curr_trace_addr >=
  2040. ppp_priv_area->end_trace_addr){
  2041. ppp_priv_area->curr_trace_addr =
  2042. ppp_priv_area->start_trace_addr;
  2043. }
  2044. /* update buffer length and make sure its even */
  2045. if ( trace_pkt->data_avail == 0x01 ) {
  2046. buffer_length += real_len - 1;
  2047. }
  2048. /* for the header */
  2049. buffer_length += 8;
  2050. if( buffer_length & 0x0001 )
  2051. buffer_length += 1;
  2052. }
  2053. /* ok now set the total number of frames passed
  2054. in the high 5 bits */
  2055. ppp_udp_pkt->data[0] |= (frames << 2);
  2056. /* set the data length */
  2057. mbox->cmd.length = buffer_length;
  2058. ppp_udp_pkt->cblock.length = buffer_length;
  2059. /* set return code */
  2060. ppp_udp_pkt->cblock.result = 0;
  2061. break;
  2062. /* PPIPE_GET_IBA_DATA */
  2063. case PPIPE_GET_IBA_DATA:
  2064. mbox->cmd.length = 0x09;
  2065. sdla_peek(&card->hw, 0xF003, &ppp_udp_pkt->data,
  2066. mbox->cmd.length);
  2067. /* set the length of the data */
  2068. ppp_udp_pkt->cblock.length = 0x09;
  2069. /* set return code */
  2070. ppp_udp_pkt->cblock.result = 0x00;
  2071. ppp_udp_pkt->cblock.result = 0;
  2072. break;
  2073. /* PPIPE_FT1_READ_STATUS */
  2074. case PPIPE_FT1_READ_STATUS:
  2075. sdla_peek(&card->hw, 0xF020, &ppp_udp_pkt->data[0], 2);
  2076. ppp_udp_pkt->cblock.length = mbox->cmd.length = 2;
  2077. ppp_udp_pkt->cblock.result = 0;
  2078. break;
  2079. case PPIPE_FLUSH_DRIVER_STATS:
  2080. init_ppp_priv_struct( ppp_priv_area );
  2081. init_global_statistics( card );
  2082. mbox->cmd.length = 0;
  2083. ppp_udp_pkt->cblock.result = 0;
  2084. break;
  2085. case PPIPE_ROUTER_UP_TIME:
  2086. do_gettimeofday( &tv );
  2087. ppp_priv_area->router_up_time = tv.tv_sec -
  2088. ppp_priv_area->router_start_time;
  2089. *(unsigned long *)&ppp_udp_pkt->data = ppp_priv_area->router_up_time;
  2090. mbox->cmd.length = 4;
  2091. ppp_udp_pkt->cblock.result = 0;
  2092. break;
  2093. /* PPIPE_DRIVER_STATISTICS */
  2094. case PPIPE_DRIVER_STAT_IFSEND:
  2095. memcpy(&ppp_udp_pkt->data, &ppp_priv_area->if_send_stat,
  2096. sizeof(if_send_stat_t));
  2097. ppp_udp_pkt->cblock.result = 0;
  2098. ppp_udp_pkt->cblock.length = sizeof(if_send_stat_t);
  2099. mbox->cmd.length = sizeof(if_send_stat_t);
  2100. break;
  2101. case PPIPE_DRIVER_STAT_INTR:
  2102. memcpy(&ppp_udp_pkt->data, &card->statistics,
  2103. sizeof(global_stats_t));
  2104. memcpy(&ppp_udp_pkt->data+sizeof(global_stats_t),
  2105. &ppp_priv_area->rx_intr_stat,
  2106. sizeof(rx_intr_stat_t));
  2107. ppp_udp_pkt->cblock.result = 0;
  2108. ppp_udp_pkt->cblock.length = sizeof(global_stats_t)+
  2109. sizeof(rx_intr_stat_t);
  2110. mbox->cmd.length = ppp_udp_pkt->cblock.length;
  2111. break;
  2112. case PPIPE_DRIVER_STAT_GEN:
  2113. memcpy( &ppp_udp_pkt->data,
  2114. &ppp_priv_area->pipe_mgmt_stat,
  2115. sizeof(pipe_mgmt_stat_t));
  2116. memcpy(&ppp_udp_pkt->data+sizeof(pipe_mgmt_stat_t),
  2117. &card->statistics, sizeof(global_stats_t));
  2118. ppp_udp_pkt->cblock.result = 0;
  2119. ppp_udp_pkt->cblock.length = sizeof(global_stats_t)+
  2120. sizeof(rx_intr_stat_t);
  2121. mbox->cmd.length = ppp_udp_pkt->cblock.length;
  2122. break;
  2123. /* FT1 MONITOR STATUS */
  2124. case FT1_MONITOR_STATUS_CTRL:
  2125. /* Enable FT1 MONITOR STATUS */
  2126. if( ppp_udp_pkt->data[0] == 1) {
  2127. if( rCount++ != 0 ) {
  2128. ppp_udp_pkt->cblock.result = 0;
  2129. mbox->cmd.length = 1;
  2130. break;
  2131. }
  2132. }
  2133. /* Disable FT1 MONITOR STATUS */
  2134. if( ppp_udp_pkt->data[0] == 0) {
  2135. if( --rCount != 0) {
  2136. ppp_udp_pkt->cblock.result = 0;
  2137. mbox->cmd.length = 1;
  2138. break;
  2139. }
  2140. }
  2141. goto udp_dflt_cmd;
  2142. /* WARNING: FIXME: This should be fixed.
  2143. * The FT1 Status Ctrl doesn't have a break
  2144. * statment. Thus, no code must be inserted
  2145. * HERE: between default and above case statement */
  2146. default:
  2147. udp_dflt_cmd:
  2148. /* it's a board command */
  2149. mbox->cmd.command = ppp_udp_pkt->cblock.command;
  2150. mbox->cmd.length = ppp_udp_pkt->cblock.length;
  2151. if(mbox->cmd.length) {
  2152. memcpy(&mbox->data,(unsigned char *)ppp_udp_pkt->data,
  2153. mbox->cmd.length);
  2154. }
  2155. /* run the command on the board */
  2156. err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
  2157. if (err != CMD_OK) {
  2158. ppp_error(card, err, mbox);
  2159. ++ppp_priv_area->pipe_mgmt_stat.
  2160. UDP_PIPE_mgmt_adptr_cmnd_timeout;
  2161. break;
  2162. }
  2163. ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_adptr_cmnd_OK;
  2164. /* copy the result back to our buffer */
  2165. memcpy(&ppp_udp_pkt->cblock,mbox, sizeof(cblock_t));
  2166. if(mbox->cmd.length) {
  2167. memcpy(&ppp_udp_pkt->data,&mbox->data,mbox->cmd.length);
  2168. }
  2169. } /* end of switch */
  2170. } /* end of else */
  2171. /* Fill UDP TTL */
  2172. ppp_udp_pkt->ip_pkt.ttl = card->wandev.ttl;
  2173. len = reply_udp(ppp_priv_area->udp_pkt_data, mbox->cmd.length);
  2174. if (ppp_priv_area->udp_pkt_src == UDP_PKT_FRM_NETWORK) {
  2175. /* Make sure we are not already sending */
  2176. if (!test_bit(SEND_CRIT,&card->wandev.critical)){
  2177. ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_passed_to_adptr;
  2178. ppp_send(card,ppp_priv_area->udp_pkt_data,len,ppp_priv_area->protocol);
  2179. }
  2180. } else {
  2181. /* Pass it up the stack
  2182. Allocate socket buffer */
  2183. if ((new_skb = dev_alloc_skb(len)) != NULL) {
  2184. /* copy data into new_skb */
  2185. buf = skb_put(new_skb, len);
  2186. memcpy(buf,ppp_priv_area->udp_pkt_data, len);
  2187. ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_passed_to_stack;
  2188. /* Decapsulate packet and pass it up the protocol
  2189. stack */
  2190. new_skb->protocol = htons(ETH_P_IP);
  2191. new_skb->dev = dev;
  2192. new_skb->mac.raw = new_skb->data;
  2193. netif_rx(new_skb);
  2194. dev->last_rx = jiffies;
  2195. } else {
  2196. ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_no_socket;
  2197. printk(KERN_INFO "no socket buffers available!\n");
  2198. }
  2199. }
  2200. ppp_priv_area->udp_pkt_lgth = 0;
  2201. return;
  2202. }
  2203. /*=============================================================================
  2204. * Initial the ppp_private_area structure.
  2205. */
  2206. static void init_ppp_priv_struct( ppp_private_area_t *ppp_priv_area )
  2207. {
  2208. memset(&ppp_priv_area->if_send_stat, 0, sizeof(if_send_stat_t));
  2209. memset(&ppp_priv_area->rx_intr_stat, 0, sizeof(rx_intr_stat_t));
  2210. memset(&ppp_priv_area->pipe_mgmt_stat, 0, sizeof(pipe_mgmt_stat_t));
  2211. }
  2212. /*============================================================================
  2213. * Initialize Global Statistics
  2214. */
  2215. static void init_global_statistics( sdla_t *card )
  2216. {
  2217. memset(&card->statistics, 0, sizeof(global_stats_t));
  2218. }
  2219. /*============================================================================
  2220. * Initialize Receive and Transmit Buffers.
  2221. */
  2222. static void init_ppp_tx_rx_buff( sdla_t *card )
  2223. {
  2224. ppp508_buf_info_t* info;
  2225. if (card->hw.type == SDLA_S514) {
  2226. info = (void*)(card->hw.dpmbase + PPP514_BUF_OFFS);
  2227. card->u.p.txbuf_base = (void*)(card->hw.dpmbase +
  2228. info->txb_ptr);
  2229. card->u.p.txbuf_last = (ppp_buf_ctl_t*)card->u.p.txbuf_base +
  2230. (info->txb_num - 1);
  2231. card->u.p.rxbuf_base = (void*)(card->hw.dpmbase +
  2232. info->rxb_ptr);
  2233. card->u.p.rxbuf_last = (ppp_buf_ctl_t*)card->u.p.rxbuf_base +
  2234. (info->rxb_num - 1);
  2235. } else {
  2236. info = (void*)(card->hw.dpmbase + PPP508_BUF_OFFS);
  2237. card->u.p.txbuf_base = (void*)(card->hw.dpmbase +
  2238. (info->txb_ptr - PPP508_MB_VECT));
  2239. card->u.p.txbuf_last = (ppp_buf_ctl_t*)card->u.p.txbuf_base +
  2240. (info->txb_num - 1);
  2241. card->u.p.rxbuf_base = (void*)(card->hw.dpmbase +
  2242. (info->rxb_ptr - PPP508_MB_VECT));
  2243. card->u.p.rxbuf_last = (ppp_buf_ctl_t*)card->u.p.rxbuf_base +
  2244. (info->rxb_num - 1);
  2245. }
  2246. card->u.p.txbuf_next = (unsigned long*)&info->txb_nxt;
  2247. card->u.p.rxbuf_next = (unsigned long*)&info->rxb1_ptr;
  2248. card->u.p.rx_base = info->rxb_base;
  2249. card->u.p.rx_top = info->rxb_end;
  2250. card->u.p.txbuf = card->u.p.txbuf_base;
  2251. card->rxmb = card->u.p.rxbuf_base;
  2252. }
  2253. /*=============================================================================
  2254. * Read Connection Information (ie for Remote IP address assginment).
  2255. * Called when ppp interface connected.
  2256. */
  2257. static int read_info( sdla_t *card )
  2258. {
  2259. struct net_device *dev = card->wandev.dev;
  2260. ppp_private_area_t *ppp_priv_area = dev->priv;
  2261. int err;
  2262. struct ifreq if_info;
  2263. struct sockaddr_in *if_data1, *if_data2;
  2264. mm_segment_t fs;
  2265. /* Set Local and remote addresses */
  2266. memset(&if_info, 0, sizeof(if_info));
  2267. strcpy(if_info.ifr_name, dev->name);
  2268. fs = get_fs();
  2269. set_fs(get_ds()); /* get user space block */
  2270. /* Change the local and remote ip address of the interface.
  2271. * This will also add in the destination route.
  2272. */
  2273. if_data1 = (struct sockaddr_in *)&if_info.ifr_addr;
  2274. if_data1->sin_addr.s_addr = ppp_priv_area->ip_local;
  2275. if_data1->sin_family = AF_INET;
  2276. err = devinet_ioctl( SIOCSIFADDR, &if_info );
  2277. if_data2 = (struct sockaddr_in *)&if_info.ifr_dstaddr;
  2278. if_data2->sin_addr.s_addr = ppp_priv_area->ip_remote;
  2279. if_data2->sin_family = AF_INET;
  2280. err = devinet_ioctl( SIOCSIFDSTADDR, &if_info );
  2281. set_fs(fs); /* restore old block */
  2282. if (err) {
  2283. printk (KERN_INFO "%s: Adding of route failed: %i\n",
  2284. card->devname,err);
  2285. printk (KERN_INFO "%s: Local : %u.%u.%u.%u\n",
  2286. card->devname,NIPQUAD(ppp_priv_area->ip_local));
  2287. printk (KERN_INFO "%s: Remote: %u.%u.%u.%u\n",
  2288. card->devname,NIPQUAD(ppp_priv_area->ip_remote));
  2289. }
  2290. return err;
  2291. }
  2292. /*=============================================================================
  2293. * Remove Dynamic Route.
  2294. * Called when ppp interface disconnected.
  2295. */
  2296. static void remove_route( sdla_t *card )
  2297. {
  2298. struct net_device *dev = card->wandev.dev;
  2299. long ip_addr;
  2300. int err;
  2301. mm_segment_t fs;
  2302. struct ifreq if_info;
  2303. struct sockaddr_in *if_data1;
  2304. struct in_device *in_dev = dev->ip_ptr;
  2305. struct in_ifaddr *ifa = in_dev->ifa_list;
  2306. ip_addr = ifa->ifa_local;
  2307. /* Set Local and remote addresses */
  2308. memset(&if_info, 0, sizeof(if_info));
  2309. strcpy(if_info.ifr_name, dev->name);
  2310. fs = get_fs();
  2311. set_fs(get_ds()); /* get user space block */
  2312. /* Change the local ip address of the interface to 0.
  2313. * This will also delete the destination route.
  2314. */
  2315. if_data1 = (struct sockaddr_in *)&if_info.ifr_addr;
  2316. if_data1->sin_addr.s_addr = 0;
  2317. if_data1->sin_family = AF_INET;
  2318. err = devinet_ioctl( SIOCSIFADDR, &if_info );
  2319. set_fs(fs); /* restore old block */
  2320. if (err) {
  2321. printk (KERN_INFO "%s: Deleting dynamic route failed %d!\n",
  2322. card->devname, err);
  2323. return;
  2324. }else{
  2325. printk (KERN_INFO "%s: PPP Deleting dynamic route %u.%u.%u.%u successfuly\n",
  2326. card->devname, NIPQUAD(ip_addr));
  2327. }
  2328. return;
  2329. }
  2330. /*=============================================================================
  2331. * Perform the Interrupt Test by running the READ_CODE_VERSION command MAX_INTR
  2332. * _TEST_COUNTER times.
  2333. */
  2334. static int intr_test( sdla_t *card )
  2335. {
  2336. ppp_mbox_t *mb = card->mbox;
  2337. int err,i;
  2338. err = ppp_set_intr_mode( card, 0x08 );
  2339. if (err == CMD_OK) {
  2340. for (i = 0; i < MAX_INTR_TEST_COUNTER; i ++) {
  2341. /* Run command READ_CODE_VERSION */
  2342. memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
  2343. mb->cmd.length = 0;
  2344. mb->cmd.command = PPP_READ_CODE_VERSION;
  2345. err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
  2346. if (err != CMD_OK)
  2347. ppp_error(card, err, mb);
  2348. }
  2349. }
  2350. else return err;
  2351. err = ppp_set_intr_mode( card, 0 );
  2352. if (err != CMD_OK)
  2353. return err;
  2354. return 0;
  2355. }
  2356. /*==============================================================================
  2357. * Determine what type of UDP call it is. DRVSTATS or PTPIPEAB ?
  2358. */
  2359. static int udp_pkt_type( struct sk_buff *skb, sdla_t *card )
  2360. {
  2361. unsigned char *sendpacket;
  2362. unsigned char buf2[5];
  2363. ppp_udp_pkt_t *ppp_udp_pkt = (ppp_udp_pkt_t *)skb->data;
  2364. sendpacket = skb->data;
  2365. memcpy(&buf2, &card->wandev.udp_port, 2);
  2366. if( ppp_udp_pkt->ip_pkt.ver_inet_hdr_length == 0x45 && /* IP packet */
  2367. sendpacket[9] == 0x11 && /* UDP packet */
  2368. sendpacket[22] == buf2[1] && /* UDP Port */
  2369. sendpacket[23] == buf2[0] &&
  2370. sendpacket[36] == 0x01 ) {
  2371. if ( sendpacket[28] == 0x50 && /* PTPIPEAB: Signature */
  2372. sendpacket[29] == 0x54 &&
  2373. sendpacket[30] == 0x50 &&
  2374. sendpacket[31] == 0x49 &&
  2375. sendpacket[32] == 0x50 &&
  2376. sendpacket[33] == 0x45 &&
  2377. sendpacket[34] == 0x41 &&
  2378. sendpacket[35] == 0x42 ){
  2379. return UDP_PTPIPE_TYPE;
  2380. } else if(sendpacket[28] == 0x44 && /* DRVSTATS: Signature */
  2381. sendpacket[29] == 0x52 &&
  2382. sendpacket[30] == 0x56 &&
  2383. sendpacket[31] == 0x53 &&
  2384. sendpacket[32] == 0x54 &&
  2385. sendpacket[33] == 0x41 &&
  2386. sendpacket[34] == 0x54 &&
  2387. sendpacket[35] == 0x53 ){
  2388. return UDP_DRVSTATS_TYPE;
  2389. } else
  2390. return UDP_INVALID_TYPE;
  2391. } else
  2392. return UDP_INVALID_TYPE;
  2393. }
  2394. /*============================================================================
  2395. * Check to see if the packet to be transmitted contains a broadcast or
  2396. * multicast source IP address.
  2397. */
  2398. static int chk_bcast_mcast_addr(sdla_t *card, struct net_device* dev,
  2399. struct sk_buff *skb)
  2400. {
  2401. u32 src_ip_addr;
  2402. u32 broadcast_ip_addr = 0;
  2403. struct in_device *in_dev;
  2404. /* read the IP source address from the outgoing packet */
  2405. src_ip_addr = *(u32 *)(skb->data + 12);
  2406. /* read the IP broadcast address for the device */
  2407. in_dev = dev->ip_ptr;
  2408. if(in_dev != NULL) {
  2409. struct in_ifaddr *ifa= in_dev->ifa_list;
  2410. if(ifa != NULL)
  2411. broadcast_ip_addr = ifa->ifa_broadcast;
  2412. else
  2413. return 0;
  2414. }
  2415. /* check if the IP Source Address is a Broadcast address */
  2416. if((dev->flags & IFF_BROADCAST) && (src_ip_addr == broadcast_ip_addr)) {
  2417. printk(KERN_INFO "%s: Broadcast Source Address silently discarded\n",
  2418. card->devname);
  2419. return 1;
  2420. }
  2421. /* check if the IP Source Address is a Multicast address */
  2422. if((ntohl(src_ip_addr) >= 0xE0000001) &&
  2423. (ntohl(src_ip_addr) <= 0xFFFFFFFE)) {
  2424. printk(KERN_INFO "%s: Multicast Source Address silently discarded\n",
  2425. card->devname);
  2426. return 1;
  2427. }
  2428. return 0;
  2429. }
  2430. void s508_lock (sdla_t *card, unsigned long *smp_flags)
  2431. {
  2432. spin_lock_irqsave(&card->wandev.lock, *smp_flags);
  2433. }
  2434. void s508_unlock (sdla_t *card, unsigned long *smp_flags)
  2435. {
  2436. spin_unlock_irqrestore(&card->wandev.lock, *smp_flags);
  2437. }
  2438. static int read_connection_info (sdla_t *card)
  2439. {
  2440. ppp_mbox_t *mb = card->mbox;
  2441. struct net_device *dev = card->wandev.dev;
  2442. ppp_private_area_t *ppp_priv_area = dev->priv;
  2443. ppp508_connect_info_t *ppp508_connect_info;
  2444. int err;
  2445. memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
  2446. mb->cmd.length = 0;
  2447. mb->cmd.command = PPP_GET_CONNECTION_INFO;
  2448. err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
  2449. if (err != CMD_OK) {
  2450. ppp_error(card, err, mb);
  2451. ppp_priv_area->ip_remote = 0;
  2452. ppp_priv_area->ip_local = 0;
  2453. }
  2454. else {
  2455. ppp508_connect_info = (ppp508_connect_info_t *)mb->data;
  2456. ppp_priv_area->ip_remote = ppp508_connect_info->ip_remote;
  2457. ppp_priv_area->ip_local = ppp508_connect_info->ip_local;
  2458. NEX_PRINTK(KERN_INFO "READ CONNECTION GOT IP ADDRESS %x, %x\n",
  2459. ppp_priv_area->ip_remote,
  2460. ppp_priv_area->ip_local);
  2461. }
  2462. return err;
  2463. }
  2464. /*===============================================================================
  2465. * config_ppp
  2466. *
  2467. * Configure the ppp protocol and enable communications.
  2468. *
  2469. * The if_open function binds this function to the poll routine.
  2470. * Therefore, this function will run every time the ppp interface
  2471. * is brought up.
  2472. *
  2473. * If the communications are not enabled, proceed to configure
  2474. * the card and enable communications.
  2475. *
  2476. * If the communications are enabled, it means that the interface
  2477. * was shutdown by ether the user or driver. In this case, we
  2478. * have to check that the IP addresses have not changed. If
  2479. * the IP addresses changed, we have to reconfigure the firmware
  2480. * and update the changed IP addresses. Otherwise, just exit.
  2481. */
  2482. static int config_ppp (sdla_t *card)
  2483. {
  2484. struct net_device *dev = card->wandev.dev;
  2485. ppp_flags_t *flags = card->flags;
  2486. ppp_private_area_t *ppp_priv_area = dev->priv;
  2487. if (card->u.p.comm_enabled){
  2488. if (ppp_priv_area->ip_local_tmp != ppp_priv_area->ip_local ||
  2489. ppp_priv_area->ip_remote_tmp != ppp_priv_area->ip_remote){
  2490. /* The IP addersses have changed, we must
  2491. * stop the communications and reconfigure
  2492. * the card. Reason: the firmware must know
  2493. * the local and remote IP addresses. */
  2494. disable_comm(card);
  2495. wanpipe_set_state(card, WAN_DISCONNECTED);
  2496. printk(KERN_INFO
  2497. "%s: IP addresses changed!\n",
  2498. card->devname);
  2499. printk(KERN_INFO "%s: Restarting communications ...\n",
  2500. card->devname);
  2501. }else{
  2502. /* IP addresses are the same and the link is up,
  2503. * we don't have to do anything here. Therefore, exit */
  2504. return 0;
  2505. }
  2506. }
  2507. /* Record the new IP addreses */
  2508. ppp_priv_area->ip_local = ppp_priv_area->ip_local_tmp;
  2509. ppp_priv_area->ip_remote = ppp_priv_area->ip_remote_tmp;
  2510. if (config508(dev, card)){
  2511. printk(KERN_INFO "%s: Failed to configure PPP device\n",
  2512. card->devname);
  2513. return 0;
  2514. }
  2515. if (ppp_set_intr_mode(card, PPP_INTR_RXRDY|
  2516. PPP_INTR_TXRDY|
  2517. PPP_INTR_MODEM|
  2518. PPP_INTR_DISC |
  2519. PPP_INTR_OPEN |
  2520. PPP_INTR_DROP_DTR |
  2521. PPP_INTR_TIMER)) {
  2522. printk(KERN_INFO "%s: Failed to configure board interrupts !\n",
  2523. card->devname);
  2524. return 0;
  2525. }
  2526. /* Turn off the transmit and timer interrupt */
  2527. flags->imask &= ~(PPP_INTR_TXRDY | PPP_INTR_TIMER) ;
  2528. /* If you are not the authenticator and any one of the protocol is
  2529. * enabled then we call the set_out_bound_authentication.
  2530. */
  2531. if ( !card->u.p.authenticator && (ppp_priv_area->pap || ppp_priv_area->chap)) {
  2532. if ( ppp_set_outbnd_auth(card, ppp_priv_area) ){
  2533. printk(KERN_INFO "%s: Outbound authentication failed !\n",
  2534. card->devname);
  2535. return 0;
  2536. }
  2537. }
  2538. /* If you are the authenticator and any one of the protocol is enabled
  2539. * then we call the set_in_bound_authentication.
  2540. */
  2541. if (card->u.p.authenticator && (ppp_priv_area->pap || ppp_priv_area->chap)){
  2542. if (ppp_set_inbnd_auth(card, ppp_priv_area)){
  2543. printk(KERN_INFO "%s: Inbound authentication failed !\n",
  2544. card->devname);
  2545. return 0;
  2546. }
  2547. }
  2548. /* If we fail to enable communications here it's OK,
  2549. * since the DTR timer will cause a disconnected, which
  2550. * will retrigger communication in timer_intr() */
  2551. if (ppp_comm_enable(card) == CMD_OK) {
  2552. wanpipe_set_state(card, WAN_CONNECTING);
  2553. init_ppp_tx_rx_buff(card);
  2554. }
  2555. return 0;
  2556. }
  2557. /*============================================================
  2558. * ppp_poll
  2559. *
  2560. * Rationale:
  2561. * We cannot manipulate the routing tables, or
  2562. * ip addresses withing the interrupt. Therefore
  2563. * we must perform such actons outside an interrupt
  2564. * at a later time.
  2565. *
  2566. * Description:
  2567. * PPP polling routine, responsible for
  2568. * shutting down interfaces upon disconnect
  2569. * and adding/removing routes.
  2570. *
  2571. * Usage:
  2572. * This function is executed for each ppp
  2573. * interface through a tq_schedule bottom half.
  2574. *
  2575. * trigger_ppp_poll() function is used to kick
  2576. * the ppp_poll routine.
  2577. */
  2578. static void ppp_poll(struct net_device *dev)
  2579. {
  2580. ppp_private_area_t *ppp_priv_area;
  2581. sdla_t *card;
  2582. u8 check_gateway=0;
  2583. ppp_flags_t *flags;
  2584. if (!dev || (ppp_priv_area = dev->priv) == NULL)
  2585. return;
  2586. card = ppp_priv_area->card;
  2587. flags = card->flags;
  2588. /* Shutdown is in progress, stop what you are
  2589. * doing and get out */
  2590. if (test_bit(PERI_CRIT,&card->wandev.critical)){
  2591. clear_bit(POLL_CRIT,&card->wandev.critical);
  2592. return;
  2593. }
  2594. /* if_open() function has triggered the polling routine
  2595. * to determine the configured IP addresses. Once the
  2596. * addresses are found, trigger the chdlc configuration */
  2597. if (test_bit(0,&ppp_priv_area->config_ppp)){
  2598. ppp_priv_area->ip_local_tmp = get_ip_address(dev,WAN_LOCAL_IP);
  2599. ppp_priv_area->ip_remote_tmp = get_ip_address(dev,WAN_POINTOPOINT_IP);
  2600. if (ppp_priv_area->ip_local_tmp == ppp_priv_area->ip_remote_tmp &&
  2601. card->u.p.ip_mode == WANOPT_PPP_HOST){
  2602. if (++ppp_priv_area->ip_error > MAX_IP_ERRORS){
  2603. printk(KERN_INFO "\n%s: --- WARNING ---\n",
  2604. card->devname);
  2605. printk(KERN_INFO "%s: The local IP address is the same as the\n",
  2606. card->devname);
  2607. printk(KERN_INFO "%s: Point-to-Point IP address.\n",
  2608. card->devname);
  2609. printk(KERN_INFO "%s: --- WARNING ---\n\n",
  2610. card->devname);
  2611. }else{
  2612. clear_bit(POLL_CRIT,&card->wandev.critical);
  2613. ppp_priv_area->poll_delay_timer.expires = jiffies+HZ;
  2614. add_timer(&ppp_priv_area->poll_delay_timer);
  2615. return;
  2616. }
  2617. }
  2618. ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_CONFIG;
  2619. flags->imask |= PPP_INTR_TIMER;
  2620. ppp_priv_area->ip_error=0;
  2621. clear_bit(0,&ppp_priv_area->config_ppp);
  2622. clear_bit(POLL_CRIT,&card->wandev.critical);
  2623. return;
  2624. }
  2625. /* Dynamic interface implementation, as well as dynamic
  2626. * routing. */
  2627. switch (card->wandev.state) {
  2628. case WAN_DISCONNECTED:
  2629. /* If the dynamic interface configuration is on, and interface
  2630. * is up, then bring down the netowrk interface */
  2631. if (test_bit(DYN_OPT_ON,&ppp_priv_area->interface_down) &&
  2632. !test_bit(DEV_DOWN,&ppp_priv_area->interface_down) &&
  2633. card->wandev.dev->flags & IFF_UP){
  2634. printk(KERN_INFO "%s: Interface %s down.\n",
  2635. card->devname,card->wandev.dev->name);
  2636. change_dev_flags(card->wandev.dev,
  2637. (card->wandev.dev->flags&~IFF_UP));
  2638. set_bit(DEV_DOWN,&ppp_priv_area->interface_down);
  2639. }else{
  2640. /* We need to check if the local IP address is
  2641. * zero. If it is, we shouldn't try to remove it.
  2642. * For some reason the kernel crashes badly if
  2643. * we try to remove the route twice */
  2644. if (card->wandev.dev->flags & IFF_UP &&
  2645. get_ip_address(card->wandev.dev,WAN_LOCAL_IP) &&
  2646. card->u.p.ip_mode == WANOPT_PPP_PEER){
  2647. remove_route(card);
  2648. }
  2649. }
  2650. break;
  2651. case WAN_CONNECTED:
  2652. /* In SMP machine this code can execute before the interface
  2653. * comes up. In this case, we must make sure that we do not
  2654. * try to bring up the interface before dev_open() is finished */
  2655. /* DEV_DOWN will be set only when we bring down the interface
  2656. * for the very first time. This way we know that it was us
  2657. * that brought the interface down */
  2658. if (test_bit(DYN_OPT_ON,&ppp_priv_area->interface_down) &&
  2659. test_bit(DEV_DOWN, &ppp_priv_area->interface_down) &&
  2660. !(card->wandev.dev->flags & IFF_UP)){
  2661. printk(KERN_INFO "%s: Interface %s up.\n",
  2662. card->devname,card->wandev.dev->name);
  2663. change_dev_flags(card->wandev.dev,(card->wandev.dev->flags|IFF_UP));
  2664. clear_bit(DEV_DOWN,&ppp_priv_area->interface_down);
  2665. check_gateway=1;
  2666. }
  2667. if ((card->u.p.ip_mode == WANOPT_PPP_PEER) &&
  2668. test_bit(1,&Read_connection_info)) {
  2669. process_route(card);
  2670. clear_bit(1,&Read_connection_info);
  2671. check_gateway=1;
  2672. }
  2673. if (ppp_priv_area->gateway && check_gateway)
  2674. add_gateway(card,dev);
  2675. break;
  2676. }
  2677. clear_bit(POLL_CRIT,&card->wandev.critical);
  2678. return;
  2679. }
  2680. /*============================================================
  2681. * trigger_ppp_poll
  2682. *
  2683. * Description:
  2684. * Add a ppp_poll() task into a tq_scheduler bh handler
  2685. * for a specific interface. This will kick
  2686. * the ppp_poll() routine at a later time.
  2687. *
  2688. * Usage:
  2689. * Interrupts use this to defer a taks to
  2690. * a polling routine.
  2691. *
  2692. */
  2693. static void trigger_ppp_poll(struct net_device *dev)
  2694. {
  2695. ppp_private_area_t *ppp_priv_area;
  2696. if ((ppp_priv_area=dev->priv) != NULL){
  2697. sdla_t *card = ppp_priv_area->card;
  2698. if (test_bit(PERI_CRIT,&card->wandev.critical)){
  2699. return;
  2700. }
  2701. if (test_and_set_bit(POLL_CRIT,&card->wandev.critical)){
  2702. return;
  2703. }
  2704. schedule_work(&ppp_priv_area->poll_work);
  2705. }
  2706. return;
  2707. }
  2708. static void ppp_poll_delay (unsigned long dev_ptr)
  2709. {
  2710. struct net_device *dev = (struct net_device *)dev_ptr;
  2711. trigger_ppp_poll(dev);
  2712. }
  2713. /*============================================================
  2714. * detect_and_fix_tx_bug
  2715. *
  2716. * Description:
  2717. * On connect, if the board tx buffer ptr is not the same
  2718. * as the driver tx buffer ptr, we found a firmware bug.
  2719. * Report the bug to the above layer. To fix the
  2720. * error restart communications again.
  2721. *
  2722. * Usage:
  2723. *
  2724. */
  2725. static int detect_and_fix_tx_bug (sdla_t *card)
  2726. {
  2727. if (((unsigned long)card->u.p.txbuf_base&0xFFF) != ((*card->u.p.txbuf_next)&0xFFF)){
  2728. NEX_PRINTK(KERN_INFO "Major Error, Fix the bug\n");
  2729. return 1;
  2730. }
  2731. return 0;
  2732. }
  2733. MODULE_LICENSE("GPL");
  2734. /****** End *****************************************************************/