sdla_ppp.c 97 KB

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