isdn_ppp.c 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042
  1. /* $Id: isdn_ppp.c,v 1.1.2.3 2004/02/10 01:07:13 keil Exp $
  2. *
  3. * Linux ISDN subsystem, functions for synchronous PPP (linklevel).
  4. *
  5. * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
  6. *
  7. * This software may be used and distributed according to the terms
  8. * of the GNU General Public License, incorporated herein by reference.
  9. *
  10. */
  11. #include <linux/isdn.h>
  12. #include <linux/poll.h>
  13. #include <linux/ppp-comp.h>
  14. #ifdef CONFIG_IPPP_FILTER
  15. #include <linux/filter.h>
  16. #endif
  17. #include "isdn_common.h"
  18. #include "isdn_ppp.h"
  19. #include "isdn_net.h"
  20. #ifndef PPP_IPX
  21. #define PPP_IPX 0x002b
  22. #endif
  23. /* Prototypes */
  24. static int isdn_ppp_fill_rq(unsigned char *buf, int len, int proto, int slot);
  25. static int isdn_ppp_closewait(int slot);
  26. static void isdn_ppp_push_higher(isdn_net_dev * net_dev, isdn_net_local * lp,
  27. struct sk_buff *skb, int proto);
  28. static int isdn_ppp_if_get_unit(char *namebuf);
  29. static int isdn_ppp_set_compressor(struct ippp_struct *is,struct isdn_ppp_comp_data *);
  30. static struct sk_buff *isdn_ppp_decompress(struct sk_buff *,
  31. struct ippp_struct *,struct ippp_struct *,int *proto);
  32. static void isdn_ppp_receive_ccp(isdn_net_dev * net_dev, isdn_net_local * lp,
  33. struct sk_buff *skb,int proto);
  34. static struct sk_buff *isdn_ppp_compress(struct sk_buff *skb_in,int *proto,
  35. struct ippp_struct *is,struct ippp_struct *master,int type);
  36. static void isdn_ppp_send_ccp(isdn_net_dev *net_dev, isdn_net_local *lp,
  37. struct sk_buff *skb);
  38. /* New CCP stuff */
  39. static void isdn_ppp_ccp_kickup(struct ippp_struct *is);
  40. static void isdn_ppp_ccp_xmit_reset(struct ippp_struct *is, int proto,
  41. unsigned char code, unsigned char id,
  42. unsigned char *data, int len);
  43. static struct ippp_ccp_reset *isdn_ppp_ccp_reset_alloc(struct ippp_struct *is);
  44. static void isdn_ppp_ccp_reset_free(struct ippp_struct *is);
  45. static void isdn_ppp_ccp_reset_free_state(struct ippp_struct *is,
  46. unsigned char id);
  47. static void isdn_ppp_ccp_timer_callback(unsigned long closure);
  48. static struct ippp_ccp_reset_state *isdn_ppp_ccp_reset_alloc_state(struct ippp_struct *is,
  49. unsigned char id);
  50. static void isdn_ppp_ccp_reset_trans(struct ippp_struct *is,
  51. struct isdn_ppp_resetparams *rp);
  52. static void isdn_ppp_ccp_reset_ack_rcvd(struct ippp_struct *is,
  53. unsigned char id);
  54. #ifdef CONFIG_ISDN_MPP
  55. static ippp_bundle * isdn_ppp_bundle_arr = NULL;
  56. static int isdn_ppp_mp_bundle_array_init(void);
  57. static int isdn_ppp_mp_init( isdn_net_local * lp, ippp_bundle * add_to );
  58. static void isdn_ppp_mp_receive(isdn_net_dev * net_dev, isdn_net_local * lp,
  59. struct sk_buff *skb);
  60. static void isdn_ppp_mp_cleanup( isdn_net_local * lp );
  61. static int isdn_ppp_bundle(struct ippp_struct *, int unit);
  62. #endif /* CONFIG_ISDN_MPP */
  63. char *isdn_ppp_revision = "$Revision: 1.1.2.3 $";
  64. static struct ippp_struct *ippp_table[ISDN_MAX_CHANNELS];
  65. static struct isdn_ppp_compressor *ipc_head = NULL;
  66. /*
  67. * frame log (debug)
  68. */
  69. static void
  70. isdn_ppp_frame_log(char *info, char *data, int len, int maxlen,int unit,int slot)
  71. {
  72. int cnt,
  73. j,
  74. i;
  75. char buf[80];
  76. if (len < maxlen)
  77. maxlen = len;
  78. for (i = 0, cnt = 0; cnt < maxlen; i++) {
  79. for (j = 0; j < 16 && cnt < maxlen; j++, cnt++)
  80. sprintf(buf + j * 3, "%02x ", (unsigned char) data[cnt]);
  81. printk(KERN_DEBUG "[%d/%d].%s[%d]: %s\n",unit,slot, info, i, buf);
  82. }
  83. }
  84. /*
  85. * unbind isdn_net_local <=> ippp-device
  86. * note: it can happen, that we hangup/free the master before the slaves
  87. * in this case we bind another lp to the master device
  88. */
  89. int
  90. isdn_ppp_free(isdn_net_local * lp)
  91. {
  92. struct ippp_struct *is;
  93. if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
  94. printk(KERN_ERR "%s: ppp_slot(%d) out of range\n",
  95. __func__, lp->ppp_slot);
  96. return 0;
  97. }
  98. #ifdef CONFIG_ISDN_MPP
  99. spin_lock(&lp->netdev->pb->lock);
  100. #endif
  101. isdn_net_rm_from_bundle(lp);
  102. #ifdef CONFIG_ISDN_MPP
  103. if (lp->netdev->pb->ref_ct == 1) /* last link in queue? */
  104. isdn_ppp_mp_cleanup(lp);
  105. lp->netdev->pb->ref_ct--;
  106. spin_unlock(&lp->netdev->pb->lock);
  107. #endif /* CONFIG_ISDN_MPP */
  108. if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
  109. printk(KERN_ERR "%s: ppp_slot(%d) now invalid\n",
  110. __func__, lp->ppp_slot);
  111. return 0;
  112. }
  113. is = ippp_table[lp->ppp_slot];
  114. if ((is->state & IPPP_CONNECT))
  115. isdn_ppp_closewait(lp->ppp_slot); /* force wakeup on ippp device */
  116. else if (is->state & IPPP_ASSIGNED)
  117. is->state = IPPP_OPEN; /* fallback to 'OPEN but not ASSIGNED' state */
  118. if (is->debug & 0x1)
  119. printk(KERN_DEBUG "isdn_ppp_free %d %lx %lx\n", lp->ppp_slot, (long) lp, (long) is->lp);
  120. is->lp = NULL; /* link is down .. set lp to NULL */
  121. lp->ppp_slot = -1; /* is this OK ?? */
  122. return 0;
  123. }
  124. /*
  125. * bind isdn_net_local <=> ippp-device
  126. *
  127. * This function is allways called with holding dev->lock so
  128. * no additional lock is needed
  129. */
  130. int
  131. isdn_ppp_bind(isdn_net_local * lp)
  132. {
  133. int i;
  134. int unit = 0;
  135. struct ippp_struct *is;
  136. int retval;
  137. if (lp->pppbind < 0) { /* device bounded to ippp device ? */
  138. isdn_net_dev *net_dev = dev->netdev;
  139. char exclusive[ISDN_MAX_CHANNELS]; /* exclusive flags */
  140. memset(exclusive, 0, ISDN_MAX_CHANNELS);
  141. while (net_dev) { /* step through net devices to find exclusive minors */
  142. isdn_net_local *lp = net_dev->local;
  143. if (lp->pppbind >= 0)
  144. exclusive[lp->pppbind] = 1;
  145. net_dev = net_dev->next;
  146. }
  147. /*
  148. * search a free device / slot
  149. */
  150. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  151. if (ippp_table[i]->state == IPPP_OPEN && !exclusive[ippp_table[i]->minor]) { /* OPEN, but not connected! */
  152. break;
  153. }
  154. }
  155. } else {
  156. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  157. if (ippp_table[i]->minor == lp->pppbind &&
  158. (ippp_table[i]->state & IPPP_OPEN) == IPPP_OPEN)
  159. break;
  160. }
  161. }
  162. if (i >= ISDN_MAX_CHANNELS) {
  163. printk(KERN_WARNING "isdn_ppp_bind: Can't find a (free) connection to the ipppd daemon.\n");
  164. retval = -1;
  165. goto out;
  166. }
  167. /* get unit number from interface name .. ugly! */
  168. unit = isdn_ppp_if_get_unit(lp->netdev->dev->name);
  169. if (unit < 0) {
  170. printk(KERN_ERR "isdn_ppp_bind: illegal interface name %s.\n",
  171. lp->netdev->dev->name);
  172. retval = -1;
  173. goto out;
  174. }
  175. lp->ppp_slot = i;
  176. is = ippp_table[i];
  177. is->lp = lp;
  178. is->unit = unit;
  179. is->state = IPPP_OPEN | IPPP_ASSIGNED; /* assigned to a netdevice but not connected */
  180. #ifdef CONFIG_ISDN_MPP
  181. retval = isdn_ppp_mp_init(lp, NULL);
  182. if (retval < 0)
  183. goto out;
  184. #endif /* CONFIG_ISDN_MPP */
  185. retval = lp->ppp_slot;
  186. out:
  187. return retval;
  188. }
  189. /*
  190. * kick the ipppd on the device
  191. * (wakes up daemon after B-channel connect)
  192. */
  193. void
  194. isdn_ppp_wakeup_daemon(isdn_net_local * lp)
  195. {
  196. if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
  197. printk(KERN_ERR "%s: ppp_slot(%d) out of range\n",
  198. __func__, lp->ppp_slot);
  199. return;
  200. }
  201. ippp_table[lp->ppp_slot]->state = IPPP_OPEN | IPPP_CONNECT | IPPP_NOBLOCK;
  202. wake_up_interruptible(&ippp_table[lp->ppp_slot]->wq);
  203. }
  204. /*
  205. * there was a hangup on the netdevice
  206. * force wakeup of the ippp device
  207. * go into 'device waits for release' state
  208. */
  209. static int
  210. isdn_ppp_closewait(int slot)
  211. {
  212. struct ippp_struct *is;
  213. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  214. printk(KERN_ERR "%s: slot(%d) out of range\n",
  215. __func__, slot);
  216. return 0;
  217. }
  218. is = ippp_table[slot];
  219. if (is->state)
  220. wake_up_interruptible(&is->wq);
  221. is->state = IPPP_CLOSEWAIT;
  222. return 1;
  223. }
  224. /*
  225. * isdn_ppp_find_slot / isdn_ppp_free_slot
  226. */
  227. static int
  228. isdn_ppp_get_slot(void)
  229. {
  230. int i;
  231. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  232. if (!ippp_table[i]->state)
  233. return i;
  234. }
  235. return -1;
  236. }
  237. /*
  238. * isdn_ppp_open
  239. */
  240. int
  241. isdn_ppp_open(int min, struct file *file)
  242. {
  243. int slot;
  244. struct ippp_struct *is;
  245. if (min < 0 || min >= ISDN_MAX_CHANNELS)
  246. return -ENODEV;
  247. slot = isdn_ppp_get_slot();
  248. if (slot < 0) {
  249. return -EBUSY;
  250. }
  251. is = file->private_data = ippp_table[slot];
  252. printk(KERN_DEBUG "ippp, open, slot: %d, minor: %d, state: %04x\n",
  253. slot, min, is->state);
  254. /* compression stuff */
  255. is->link_compressor = is->compressor = NULL;
  256. is->link_decompressor = is->decompressor = NULL;
  257. is->link_comp_stat = is->comp_stat = NULL;
  258. is->link_decomp_stat = is->decomp_stat = NULL;
  259. is->compflags = 0;
  260. is->reset = isdn_ppp_ccp_reset_alloc(is);
  261. is->lp = NULL;
  262. is->mp_seqno = 0; /* MP sequence number */
  263. is->pppcfg = 0; /* ppp configuration */
  264. is->mpppcfg = 0; /* mppp configuration */
  265. is->last_link_seqno = -1; /* MP: maybe set to Bundle-MIN, when joining a bundle ?? */
  266. is->unit = -1; /* set, when we have our interface */
  267. is->mru = 1524; /* MRU, default 1524 */
  268. is->maxcid = 16; /* VJ: maxcid */
  269. is->tk = current;
  270. init_waitqueue_head(&is->wq);
  271. is->first = is->rq + NUM_RCV_BUFFS - 1; /* receive queue */
  272. is->last = is->rq;
  273. is->minor = min;
  274. #ifdef CONFIG_ISDN_PPP_VJ
  275. /*
  276. * VJ header compression init
  277. */
  278. is->slcomp = slhc_init(16, 16); /* not necessary for 2. link in bundle */
  279. #endif
  280. #ifdef CONFIG_IPPP_FILTER
  281. is->pass_filter = NULL;
  282. is->active_filter = NULL;
  283. #endif
  284. is->state = IPPP_OPEN;
  285. return 0;
  286. }
  287. /*
  288. * release ippp device
  289. */
  290. void
  291. isdn_ppp_release(int min, struct file *file)
  292. {
  293. int i;
  294. struct ippp_struct *is;
  295. if (min < 0 || min >= ISDN_MAX_CHANNELS)
  296. return;
  297. is = file->private_data;
  298. if (!is) {
  299. printk(KERN_ERR "%s: no file->private_data\n", __func__);
  300. return;
  301. }
  302. if (is->debug & 0x1)
  303. printk(KERN_DEBUG "ippp: release, minor: %d %lx\n", min, (long) is->lp);
  304. if (is->lp) { /* a lp address says: this link is still up */
  305. isdn_net_dev *p = is->lp->netdev;
  306. if (!p) {
  307. printk(KERN_ERR "%s: no lp->netdev\n", __func__);
  308. return;
  309. }
  310. is->state &= ~IPPP_CONNECT; /* -> effect: no call of wakeup */
  311. /*
  312. * isdn_net_hangup() calls isdn_ppp_free()
  313. * isdn_ppp_free() sets is->lp to NULL and lp->ppp_slot to -1
  314. * removing the IPPP_CONNECT flag omits calling of isdn_ppp_wakeup_daemon()
  315. */
  316. isdn_net_hangup(p->dev);
  317. }
  318. for (i = 0; i < NUM_RCV_BUFFS; i++) {
  319. kfree(is->rq[i].buf);
  320. is->rq[i].buf = NULL;
  321. }
  322. is->first = is->rq + NUM_RCV_BUFFS - 1; /* receive queue */
  323. is->last = is->rq;
  324. #ifdef CONFIG_ISDN_PPP_VJ
  325. /* TODO: if this was the previous master: link the slcomp to the new master */
  326. slhc_free(is->slcomp);
  327. is->slcomp = NULL;
  328. #endif
  329. #ifdef CONFIG_IPPP_FILTER
  330. kfree(is->pass_filter);
  331. is->pass_filter = NULL;
  332. kfree(is->active_filter);
  333. is->active_filter = NULL;
  334. #endif
  335. /* TODO: if this was the previous master: link the stuff to the new master */
  336. if(is->comp_stat)
  337. is->compressor->free(is->comp_stat);
  338. if(is->link_comp_stat)
  339. is->link_compressor->free(is->link_comp_stat);
  340. if(is->link_decomp_stat)
  341. is->link_decompressor->free(is->link_decomp_stat);
  342. if(is->decomp_stat)
  343. is->decompressor->free(is->decomp_stat);
  344. is->compressor = is->link_compressor = NULL;
  345. is->decompressor = is->link_decompressor = NULL;
  346. is->comp_stat = is->link_comp_stat = NULL;
  347. is->decomp_stat = is->link_decomp_stat = NULL;
  348. /* Clean up if necessary */
  349. if(is->reset)
  350. isdn_ppp_ccp_reset_free(is);
  351. /* this slot is ready for new connections */
  352. is->state = 0;
  353. }
  354. /*
  355. * get_arg .. ioctl helper
  356. */
  357. static int
  358. get_arg(void __user *b, void *val, int len)
  359. {
  360. if (len <= 0)
  361. len = sizeof(void *);
  362. if (copy_from_user(val, b, len))
  363. return -EFAULT;
  364. return 0;
  365. }
  366. /*
  367. * set arg .. ioctl helper
  368. */
  369. static int
  370. set_arg(void __user *b, void *val,int len)
  371. {
  372. if(len <= 0)
  373. len = sizeof(void *);
  374. if (copy_to_user(b, val, len))
  375. return -EFAULT;
  376. return 0;
  377. }
  378. static int get_filter(void __user *arg, struct sock_filter **p)
  379. {
  380. struct sock_fprog uprog;
  381. struct sock_filter *code = NULL;
  382. int len, err;
  383. if (copy_from_user(&uprog, arg, sizeof(uprog)))
  384. return -EFAULT;
  385. if (!uprog.len) {
  386. *p = NULL;
  387. return 0;
  388. }
  389. /* uprog.len is unsigned short, so no overflow here */
  390. len = uprog.len * sizeof(struct sock_filter);
  391. code = kmalloc(len, GFP_KERNEL);
  392. if (code == NULL)
  393. return -ENOMEM;
  394. if (copy_from_user(code, uprog.filter, len)) {
  395. kfree(code);
  396. return -EFAULT;
  397. }
  398. err = sk_chk_filter(code, uprog.len);
  399. if (err) {
  400. kfree(code);
  401. return err;
  402. }
  403. *p = code;
  404. return uprog.len;
  405. }
  406. /*
  407. * ippp device ioctl
  408. */
  409. int
  410. isdn_ppp_ioctl(int min, struct file *file, unsigned int cmd, unsigned long arg)
  411. {
  412. unsigned long val;
  413. int r,i,j;
  414. struct ippp_struct *is;
  415. isdn_net_local *lp;
  416. struct isdn_ppp_comp_data data;
  417. void __user *argp = (void __user *)arg;
  418. is = (struct ippp_struct *) file->private_data;
  419. lp = is->lp;
  420. if (is->debug & 0x1)
  421. printk(KERN_DEBUG "isdn_ppp_ioctl: minor: %d cmd: %x state: %x\n", min, cmd, is->state);
  422. if (!(is->state & IPPP_OPEN))
  423. return -EINVAL;
  424. switch (cmd) {
  425. case PPPIOCBUNDLE:
  426. #ifdef CONFIG_ISDN_MPP
  427. if (!(is->state & IPPP_CONNECT))
  428. return -EINVAL;
  429. if ((r = get_arg(argp, &val, sizeof(val) )))
  430. return r;
  431. printk(KERN_DEBUG "iPPP-bundle: minor: %d, slave unit: %d, master unit: %d\n",
  432. (int) min, (int) is->unit, (int) val);
  433. return isdn_ppp_bundle(is, val);
  434. #else
  435. return -1;
  436. #endif
  437. break;
  438. case PPPIOCGUNIT: /* get ppp/isdn unit number */
  439. if ((r = set_arg(argp, &is->unit, sizeof(is->unit) )))
  440. return r;
  441. break;
  442. case PPPIOCGIFNAME:
  443. if(!lp)
  444. return -EINVAL;
  445. if ((r = set_arg(argp, lp->netdev->dev->name,
  446. strlen(lp->netdev->dev->name))))
  447. return r;
  448. break;
  449. case PPPIOCGMPFLAGS: /* get configuration flags */
  450. if ((r = set_arg(argp, &is->mpppcfg, sizeof(is->mpppcfg) )))
  451. return r;
  452. break;
  453. case PPPIOCSMPFLAGS: /* set configuration flags */
  454. if ((r = get_arg(argp, &val, sizeof(val) )))
  455. return r;
  456. is->mpppcfg = val;
  457. break;
  458. case PPPIOCGFLAGS: /* get configuration flags */
  459. if ((r = set_arg(argp, &is->pppcfg,sizeof(is->pppcfg) )))
  460. return r;
  461. break;
  462. case PPPIOCSFLAGS: /* set configuration flags */
  463. if ((r = get_arg(argp, &val, sizeof(val) ))) {
  464. return r;
  465. }
  466. if (val & SC_ENABLE_IP && !(is->pppcfg & SC_ENABLE_IP) && (is->state & IPPP_CONNECT)) {
  467. if (lp) {
  468. /* OK .. we are ready to send buffers */
  469. is->pppcfg = val; /* isdn_ppp_xmit test for SC_ENABLE_IP !!! */
  470. netif_wake_queue(lp->netdev->dev);
  471. break;
  472. }
  473. }
  474. is->pppcfg = val;
  475. break;
  476. case PPPIOCGIDLE: /* get idle time information */
  477. if (lp) {
  478. struct ppp_idle pidle;
  479. pidle.xmit_idle = pidle.recv_idle = lp->huptimer;
  480. if ((r = set_arg(argp, &pidle,sizeof(struct ppp_idle))))
  481. return r;
  482. }
  483. break;
  484. case PPPIOCSMRU: /* set receive unit size for PPP */
  485. if ((r = get_arg(argp, &val, sizeof(val) )))
  486. return r;
  487. is->mru = val;
  488. break;
  489. case PPPIOCSMPMRU:
  490. break;
  491. case PPPIOCSMPMTU:
  492. break;
  493. case PPPIOCSMAXCID: /* set the maximum compression slot id */
  494. if ((r = get_arg(argp, &val, sizeof(val) )))
  495. return r;
  496. val++;
  497. if (is->maxcid != val) {
  498. #ifdef CONFIG_ISDN_PPP_VJ
  499. struct slcompress *sltmp;
  500. #endif
  501. if (is->debug & 0x1)
  502. printk(KERN_DEBUG "ippp, ioctl: changed MAXCID to %ld\n", val);
  503. is->maxcid = val;
  504. #ifdef CONFIG_ISDN_PPP_VJ
  505. sltmp = slhc_init(16, val);
  506. if (!sltmp) {
  507. printk(KERN_ERR "ippp, can't realloc slhc struct\n");
  508. return -ENOMEM;
  509. }
  510. if (is->slcomp)
  511. slhc_free(is->slcomp);
  512. is->slcomp = sltmp;
  513. #endif
  514. }
  515. break;
  516. case PPPIOCGDEBUG:
  517. if ((r = set_arg(argp, &is->debug, sizeof(is->debug) )))
  518. return r;
  519. break;
  520. case PPPIOCSDEBUG:
  521. if ((r = get_arg(argp, &val, sizeof(val) )))
  522. return r;
  523. is->debug = val;
  524. break;
  525. case PPPIOCGCOMPRESSORS:
  526. {
  527. unsigned long protos[8] = {0,};
  528. struct isdn_ppp_compressor *ipc = ipc_head;
  529. while(ipc) {
  530. j = ipc->num / (sizeof(long)*8);
  531. i = ipc->num % (sizeof(long)*8);
  532. if(j < 8)
  533. protos[j] |= (0x1<<i);
  534. ipc = ipc->next;
  535. }
  536. if ((r = set_arg(argp,protos,8*sizeof(long) )))
  537. return r;
  538. }
  539. break;
  540. case PPPIOCSCOMPRESSOR:
  541. if ((r = get_arg(argp, &data, sizeof(struct isdn_ppp_comp_data))))
  542. return r;
  543. return isdn_ppp_set_compressor(is, &data);
  544. case PPPIOCGCALLINFO:
  545. {
  546. struct pppcallinfo pci;
  547. memset((char *) &pci,0,sizeof(struct pppcallinfo));
  548. if(lp)
  549. {
  550. strncpy(pci.local_num,lp->msn,63);
  551. if(lp->dial) {
  552. strncpy(pci.remote_num,lp->dial->num,63);
  553. }
  554. pci.charge_units = lp->charge;
  555. if(lp->outgoing)
  556. pci.calltype = CALLTYPE_OUTGOING;
  557. else
  558. pci.calltype = CALLTYPE_INCOMING;
  559. if(lp->flags & ISDN_NET_CALLBACK)
  560. pci.calltype |= CALLTYPE_CALLBACK;
  561. }
  562. return set_arg(argp,&pci,sizeof(struct pppcallinfo));
  563. }
  564. #ifdef CONFIG_IPPP_FILTER
  565. case PPPIOCSPASS:
  566. {
  567. struct sock_filter *code;
  568. int len = get_filter(argp, &code);
  569. if (len < 0)
  570. return len;
  571. kfree(is->pass_filter);
  572. is->pass_filter = code;
  573. is->pass_len = len;
  574. break;
  575. }
  576. case PPPIOCSACTIVE:
  577. {
  578. struct sock_filter *code;
  579. int len = get_filter(argp, &code);
  580. if (len < 0)
  581. return len;
  582. kfree(is->active_filter);
  583. is->active_filter = code;
  584. is->active_len = len;
  585. break;
  586. }
  587. #endif /* CONFIG_IPPP_FILTER */
  588. default:
  589. break;
  590. }
  591. return 0;
  592. }
  593. unsigned int
  594. isdn_ppp_poll(struct file *file, poll_table * wait)
  595. {
  596. u_int mask;
  597. struct ippp_buf_queue *bf, *bl;
  598. u_long flags;
  599. struct ippp_struct *is;
  600. is = file->private_data;
  601. if (is->debug & 0x2)
  602. printk(KERN_DEBUG "isdn_ppp_poll: minor: %d\n",
  603. iminor(file->f_path.dentry->d_inode));
  604. /* just registers wait_queue hook. This doesn't really wait. */
  605. poll_wait(file, &is->wq, wait);
  606. if (!(is->state & IPPP_OPEN)) {
  607. if(is->state == IPPP_CLOSEWAIT)
  608. return POLLHUP;
  609. printk(KERN_DEBUG "isdn_ppp: device not open\n");
  610. return POLLERR;
  611. }
  612. /* we're always ready to send .. */
  613. mask = POLLOUT | POLLWRNORM;
  614. spin_lock_irqsave(&is->buflock, flags);
  615. bl = is->last;
  616. bf = is->first;
  617. /*
  618. * if IPPP_NOBLOCK is set we return even if we have nothing to read
  619. */
  620. if (bf->next != bl || (is->state & IPPP_NOBLOCK)) {
  621. is->state &= ~IPPP_NOBLOCK;
  622. mask |= POLLIN | POLLRDNORM;
  623. }
  624. spin_unlock_irqrestore(&is->buflock, flags);
  625. return mask;
  626. }
  627. /*
  628. * fill up isdn_ppp_read() queue ..
  629. */
  630. static int
  631. isdn_ppp_fill_rq(unsigned char *buf, int len, int proto, int slot)
  632. {
  633. struct ippp_buf_queue *bf, *bl;
  634. u_long flags;
  635. u_char *nbuf;
  636. struct ippp_struct *is;
  637. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  638. printk(KERN_WARNING "ippp: illegal slot(%d).\n", slot);
  639. return 0;
  640. }
  641. is = ippp_table[slot];
  642. if (!(is->state & IPPP_CONNECT)) {
  643. printk(KERN_DEBUG "ippp: device not activated.\n");
  644. return 0;
  645. }
  646. nbuf = kmalloc(len + 4, GFP_ATOMIC);
  647. if (!nbuf) {
  648. printk(KERN_WARNING "ippp: Can't alloc buf\n");
  649. return 0;
  650. }
  651. nbuf[0] = PPP_ALLSTATIONS;
  652. nbuf[1] = PPP_UI;
  653. nbuf[2] = proto >> 8;
  654. nbuf[3] = proto & 0xff;
  655. memcpy(nbuf + 4, buf, len);
  656. spin_lock_irqsave(&is->buflock, flags);
  657. bf = is->first;
  658. bl = is->last;
  659. if (bf == bl) {
  660. printk(KERN_WARNING "ippp: Queue is full; discarding first buffer\n");
  661. bf = bf->next;
  662. kfree(bf->buf);
  663. is->first = bf;
  664. }
  665. bl->buf = (char *) nbuf;
  666. bl->len = len + 4;
  667. is->last = bl->next;
  668. spin_unlock_irqrestore(&is->buflock, flags);
  669. wake_up_interruptible(&is->wq);
  670. return len;
  671. }
  672. /*
  673. * read() .. non-blocking: ipppd calls it only after select()
  674. * reports, that there is data
  675. */
  676. int
  677. isdn_ppp_read(int min, struct file *file, char __user *buf, int count)
  678. {
  679. struct ippp_struct *is;
  680. struct ippp_buf_queue *b;
  681. u_long flags;
  682. u_char *save_buf;
  683. is = file->private_data;
  684. if (!(is->state & IPPP_OPEN))
  685. return 0;
  686. if (!access_ok(VERIFY_WRITE, buf, count))
  687. return -EFAULT;
  688. spin_lock_irqsave(&is->buflock, flags);
  689. b = is->first->next;
  690. save_buf = b->buf;
  691. if (!save_buf) {
  692. spin_unlock_irqrestore(&is->buflock, flags);
  693. return -EAGAIN;
  694. }
  695. if (b->len < count)
  696. count = b->len;
  697. b->buf = NULL;
  698. is->first = b;
  699. spin_unlock_irqrestore(&is->buflock, flags);
  700. if (copy_to_user(buf, save_buf, count))
  701. count = -EFAULT;
  702. kfree(save_buf);
  703. return count;
  704. }
  705. /*
  706. * ipppd wanna write a packet to the card .. non-blocking
  707. */
  708. int
  709. isdn_ppp_write(int min, struct file *file, const char __user *buf, int count)
  710. {
  711. isdn_net_local *lp;
  712. struct ippp_struct *is;
  713. int proto;
  714. unsigned char protobuf[4];
  715. is = file->private_data;
  716. if (!(is->state & IPPP_CONNECT))
  717. return 0;
  718. lp = is->lp;
  719. /* -> push it directly to the lowlevel interface */
  720. if (!lp)
  721. printk(KERN_DEBUG "isdn_ppp_write: lp == NULL\n");
  722. else {
  723. /*
  724. * Don't reset huptimer for
  725. * LCP packets. (Echo requests).
  726. */
  727. if (copy_from_user(protobuf, buf, 4))
  728. return -EFAULT;
  729. proto = PPP_PROTOCOL(protobuf);
  730. if (proto != PPP_LCP)
  731. lp->huptimer = 0;
  732. if (lp->isdn_device < 0 || lp->isdn_channel < 0)
  733. return 0;
  734. if ((dev->drv[lp->isdn_device]->flags & DRV_FLAG_RUNNING) &&
  735. lp->dialstate == 0 &&
  736. (lp->flags & ISDN_NET_CONNECTED)) {
  737. unsigned short hl;
  738. struct sk_buff *skb;
  739. /*
  740. * we need to reserve enought space in front of
  741. * sk_buff. old call to dev_alloc_skb only reserved
  742. * 16 bytes, now we are looking what the driver want
  743. */
  744. hl = dev->drv[lp->isdn_device]->interface->hl_hdrlen;
  745. skb = alloc_skb(hl+count, GFP_ATOMIC);
  746. if (!skb) {
  747. printk(KERN_WARNING "isdn_ppp_write: out of memory!\n");
  748. return count;
  749. }
  750. skb_reserve(skb, hl);
  751. if (copy_from_user(skb_put(skb, count), buf, count))
  752. {
  753. kfree_skb(skb);
  754. return -EFAULT;
  755. }
  756. if (is->debug & 0x40) {
  757. printk(KERN_DEBUG "ppp xmit: len %d\n", (int) skb->len);
  758. isdn_ppp_frame_log("xmit", skb->data, skb->len, 32,is->unit,lp->ppp_slot);
  759. }
  760. isdn_ppp_send_ccp(lp->netdev,lp,skb); /* keeps CCP/compression states in sync */
  761. isdn_net_write_super(lp, skb);
  762. }
  763. }
  764. return count;
  765. }
  766. /*
  767. * init memory, structures etc.
  768. */
  769. int
  770. isdn_ppp_init(void)
  771. {
  772. int i,
  773. j;
  774. #ifdef CONFIG_ISDN_MPP
  775. if( isdn_ppp_mp_bundle_array_init() < 0 )
  776. return -ENOMEM;
  777. #endif /* CONFIG_ISDN_MPP */
  778. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  779. if (!(ippp_table[i] = kzalloc(sizeof(struct ippp_struct), GFP_KERNEL))) {
  780. printk(KERN_WARNING "isdn_ppp_init: Could not alloc ippp_table\n");
  781. for (j = 0; j < i; j++)
  782. kfree(ippp_table[j]);
  783. return -1;
  784. }
  785. spin_lock_init(&ippp_table[i]->buflock);
  786. ippp_table[i]->state = 0;
  787. ippp_table[i]->first = ippp_table[i]->rq + NUM_RCV_BUFFS - 1;
  788. ippp_table[i]->last = ippp_table[i]->rq;
  789. for (j = 0; j < NUM_RCV_BUFFS; j++) {
  790. ippp_table[i]->rq[j].buf = NULL;
  791. ippp_table[i]->rq[j].last = ippp_table[i]->rq +
  792. (NUM_RCV_BUFFS + j - 1) % NUM_RCV_BUFFS;
  793. ippp_table[i]->rq[j].next = ippp_table[i]->rq + (j + 1) % NUM_RCV_BUFFS;
  794. }
  795. }
  796. return 0;
  797. }
  798. void
  799. isdn_ppp_cleanup(void)
  800. {
  801. int i;
  802. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  803. kfree(ippp_table[i]);
  804. #ifdef CONFIG_ISDN_MPP
  805. kfree(isdn_ppp_bundle_arr);
  806. #endif /* CONFIG_ISDN_MPP */
  807. }
  808. /*
  809. * check for address/control field and skip if allowed
  810. * retval != 0 -> discard packet silently
  811. */
  812. static int isdn_ppp_skip_ac(struct ippp_struct *is, struct sk_buff *skb)
  813. {
  814. if (skb->len < 1)
  815. return -1;
  816. if (skb->data[0] == 0xff) {
  817. if (skb->len < 2)
  818. return -1;
  819. if (skb->data[1] != 0x03)
  820. return -1;
  821. // skip address/control (AC) field
  822. skb_pull(skb, 2);
  823. } else {
  824. if (is->pppcfg & SC_REJ_COMP_AC)
  825. // if AC compression was not negotiated, but used, discard packet
  826. return -1;
  827. }
  828. return 0;
  829. }
  830. /*
  831. * get the PPP protocol header and pull skb
  832. * retval < 0 -> discard packet silently
  833. */
  834. static int isdn_ppp_strip_proto(struct sk_buff *skb)
  835. {
  836. int proto;
  837. if (skb->len < 1)
  838. return -1;
  839. if (skb->data[0] & 0x1) {
  840. // protocol field is compressed
  841. proto = skb->data[0];
  842. skb_pull(skb, 1);
  843. } else {
  844. if (skb->len < 2)
  845. return -1;
  846. proto = ((int) skb->data[0] << 8) + skb->data[1];
  847. skb_pull(skb, 2);
  848. }
  849. return proto;
  850. }
  851. /*
  852. * handler for incoming packets on a syncPPP interface
  853. */
  854. void isdn_ppp_receive(isdn_net_dev * net_dev, isdn_net_local * lp, struct sk_buff *skb)
  855. {
  856. struct ippp_struct *is;
  857. int slot;
  858. int proto;
  859. BUG_ON(net_dev->local->master); // we're called with the master device always
  860. slot = lp->ppp_slot;
  861. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  862. printk(KERN_ERR "isdn_ppp_receive: lp->ppp_slot(%d)\n",
  863. lp->ppp_slot);
  864. kfree_skb(skb);
  865. return;
  866. }
  867. is = ippp_table[slot];
  868. if (is->debug & 0x4) {
  869. printk(KERN_DEBUG "ippp_receive: is:%08lx lp:%08lx slot:%d unit:%d len:%d\n",
  870. (long)is,(long)lp,lp->ppp_slot,is->unit,(int) skb->len);
  871. isdn_ppp_frame_log("receive", skb->data, skb->len, 32,is->unit,lp->ppp_slot);
  872. }
  873. if (isdn_ppp_skip_ac(is, skb) < 0) {
  874. kfree_skb(skb);
  875. return;
  876. }
  877. proto = isdn_ppp_strip_proto(skb);
  878. if (proto < 0) {
  879. kfree_skb(skb);
  880. return;
  881. }
  882. #ifdef CONFIG_ISDN_MPP
  883. if (is->compflags & SC_LINK_DECOMP_ON) {
  884. skb = isdn_ppp_decompress(skb, is, NULL, &proto);
  885. if (!skb) // decompression error
  886. return;
  887. }
  888. if (!(is->mpppcfg & SC_REJ_MP_PROT)) { // we agreed to receive MPPP
  889. if (proto == PPP_MP) {
  890. isdn_ppp_mp_receive(net_dev, lp, skb);
  891. return;
  892. }
  893. }
  894. #endif
  895. isdn_ppp_push_higher(net_dev, lp, skb, proto);
  896. }
  897. /*
  898. * we receive a reassembled frame, MPPP has been taken care of before.
  899. * address/control and protocol have been stripped from the skb
  900. * note: net_dev has to be master net_dev
  901. */
  902. static void
  903. isdn_ppp_push_higher(isdn_net_dev * net_dev, isdn_net_local * lp, struct sk_buff *skb, int proto)
  904. {
  905. struct net_device *dev = net_dev->dev;
  906. struct ippp_struct *is, *mis;
  907. isdn_net_local *mlp = NULL;
  908. int slot;
  909. slot = lp->ppp_slot;
  910. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  911. printk(KERN_ERR "isdn_ppp_push_higher: lp->ppp_slot(%d)\n",
  912. lp->ppp_slot);
  913. goto drop_packet;
  914. }
  915. is = ippp_table[slot];
  916. if (lp->master) { // FIXME?
  917. mlp = (isdn_net_local *) lp->master->priv;
  918. slot = mlp->ppp_slot;
  919. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  920. printk(KERN_ERR "isdn_ppp_push_higher: master->ppp_slot(%d)\n",
  921. lp->ppp_slot);
  922. goto drop_packet;
  923. }
  924. }
  925. mis = ippp_table[slot];
  926. if (is->debug & 0x10) {
  927. printk(KERN_DEBUG "push, skb %d %04x\n", (int) skb->len, proto);
  928. isdn_ppp_frame_log("rpush", skb->data, skb->len, 32,is->unit,lp->ppp_slot);
  929. }
  930. if (mis->compflags & SC_DECOMP_ON) {
  931. skb = isdn_ppp_decompress(skb, is, mis, &proto);
  932. if (!skb) // decompression error
  933. return;
  934. }
  935. switch (proto) {
  936. case PPP_IPX: /* untested */
  937. if (is->debug & 0x20)
  938. printk(KERN_DEBUG "isdn_ppp: IPX\n");
  939. skb->protocol = htons(ETH_P_IPX);
  940. break;
  941. case PPP_IP:
  942. if (is->debug & 0x20)
  943. printk(KERN_DEBUG "isdn_ppp: IP\n");
  944. skb->protocol = htons(ETH_P_IP);
  945. break;
  946. case PPP_COMP:
  947. case PPP_COMPFRAG:
  948. printk(KERN_INFO "isdn_ppp: unexpected compressed frame dropped\n");
  949. goto drop_packet;
  950. #ifdef CONFIG_ISDN_PPP_VJ
  951. case PPP_VJC_UNCOMP:
  952. if (is->debug & 0x20)
  953. printk(KERN_DEBUG "isdn_ppp: VJC_UNCOMP\n");
  954. if (net_dev->local->ppp_slot < 0) {
  955. printk(KERN_ERR "%s: net_dev->local->ppp_slot(%d) out of range\n",
  956. __func__, net_dev->local->ppp_slot);
  957. goto drop_packet;
  958. }
  959. if (slhc_remember(ippp_table[net_dev->local->ppp_slot]->slcomp, skb->data, skb->len) <= 0) {
  960. printk(KERN_WARNING "isdn_ppp: received illegal VJC_UNCOMP frame!\n");
  961. goto drop_packet;
  962. }
  963. skb->protocol = htons(ETH_P_IP);
  964. break;
  965. case PPP_VJC_COMP:
  966. if (is->debug & 0x20)
  967. printk(KERN_DEBUG "isdn_ppp: VJC_COMP\n");
  968. {
  969. struct sk_buff *skb_old = skb;
  970. int pkt_len;
  971. skb = dev_alloc_skb(skb_old->len + 128);
  972. if (!skb) {
  973. printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);
  974. skb = skb_old;
  975. goto drop_packet;
  976. }
  977. skb_put(skb, skb_old->len + 128);
  978. skb_copy_from_linear_data(skb_old, skb->data,
  979. skb_old->len);
  980. if (net_dev->local->ppp_slot < 0) {
  981. printk(KERN_ERR "%s: net_dev->local->ppp_slot(%d) out of range\n",
  982. __func__, net_dev->local->ppp_slot);
  983. goto drop_packet;
  984. }
  985. pkt_len = slhc_uncompress(ippp_table[net_dev->local->ppp_slot]->slcomp,
  986. skb->data, skb_old->len);
  987. kfree_skb(skb_old);
  988. if (pkt_len < 0)
  989. goto drop_packet;
  990. skb_trim(skb, pkt_len);
  991. skb->protocol = htons(ETH_P_IP);
  992. }
  993. break;
  994. #endif
  995. case PPP_CCP:
  996. case PPP_CCPFRAG:
  997. isdn_ppp_receive_ccp(net_dev,lp,skb,proto);
  998. /* Dont pop up ResetReq/Ack stuff to the daemon any
  999. longer - the job is done already */
  1000. if(skb->data[0] == CCP_RESETREQ ||
  1001. skb->data[0] == CCP_RESETACK)
  1002. break;
  1003. /* fall through */
  1004. default:
  1005. isdn_ppp_fill_rq(skb->data, skb->len, proto, lp->ppp_slot); /* push data to pppd device */
  1006. kfree_skb(skb);
  1007. return;
  1008. }
  1009. #ifdef CONFIG_IPPP_FILTER
  1010. /* check if the packet passes the pass and active filters
  1011. * the filter instructions are constructed assuming
  1012. * a four-byte PPP header on each packet (which is still present) */
  1013. skb_push(skb, 4);
  1014. {
  1015. u_int16_t *p = (u_int16_t *) skb->data;
  1016. *p = 0; /* indicate inbound */
  1017. }
  1018. if (is->pass_filter
  1019. && sk_run_filter(skb, is->pass_filter, is->pass_len) == 0) {
  1020. if (is->debug & 0x2)
  1021. printk(KERN_DEBUG "IPPP: inbound frame filtered.\n");
  1022. kfree_skb(skb);
  1023. return;
  1024. }
  1025. if (!(is->active_filter
  1026. && sk_run_filter(skb, is->active_filter,
  1027. is->active_len) == 0)) {
  1028. if (is->debug & 0x2)
  1029. printk(KERN_DEBUG "IPPP: link-active filter: reseting huptimer.\n");
  1030. lp->huptimer = 0;
  1031. if (mlp)
  1032. mlp->huptimer = 0;
  1033. }
  1034. skb_pull(skb, 4);
  1035. #else /* CONFIG_IPPP_FILTER */
  1036. lp->huptimer = 0;
  1037. if (mlp)
  1038. mlp->huptimer = 0;
  1039. #endif /* CONFIG_IPPP_FILTER */
  1040. skb->dev = dev;
  1041. skb_reset_mac_header(skb);
  1042. netif_rx(skb);
  1043. /* net_dev->local->stats.rx_packets++; done in isdn_net.c */
  1044. return;
  1045. drop_packet:
  1046. net_dev->local->stats.rx_dropped++;
  1047. kfree_skb(skb);
  1048. }
  1049. /*
  1050. * isdn_ppp_skb_push ..
  1051. * checks whether we have enough space at the beginning of the skb
  1052. * and allocs a new SKB if necessary
  1053. */
  1054. static unsigned char *isdn_ppp_skb_push(struct sk_buff **skb_p,int len)
  1055. {
  1056. struct sk_buff *skb = *skb_p;
  1057. if(skb_headroom(skb) < len) {
  1058. struct sk_buff *nskb = skb_realloc_headroom(skb, len);
  1059. if (!nskb) {
  1060. printk(KERN_ERR "isdn_ppp_skb_push: can't realloc headroom!\n");
  1061. dev_kfree_skb(skb);
  1062. return NULL;
  1063. }
  1064. printk(KERN_DEBUG "isdn_ppp_skb_push:under %d %d\n",skb_headroom(skb),len);
  1065. dev_kfree_skb(skb);
  1066. *skb_p = nskb;
  1067. return skb_push(nskb, len);
  1068. }
  1069. return skb_push(skb,len);
  1070. }
  1071. /*
  1072. * send ppp frame .. we expect a PIDCOMPressable proto --
  1073. * (here: currently always PPP_IP,PPP_VJC_COMP,PPP_VJC_UNCOMP)
  1074. *
  1075. * VJ compression may change skb pointer!!! .. requeue with old
  1076. * skb isn't allowed!!
  1077. */
  1078. int
  1079. isdn_ppp_xmit(struct sk_buff *skb, struct net_device *netdev)
  1080. {
  1081. isdn_net_local *lp,*mlp;
  1082. isdn_net_dev *nd;
  1083. unsigned int proto = PPP_IP; /* 0x21 */
  1084. struct ippp_struct *ipt,*ipts;
  1085. int slot, retval = 0;
  1086. mlp = (isdn_net_local *) (netdev->priv);
  1087. nd = mlp->netdev; /* get master lp */
  1088. slot = mlp->ppp_slot;
  1089. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  1090. printk(KERN_ERR "isdn_ppp_xmit: lp->ppp_slot(%d)\n",
  1091. mlp->ppp_slot);
  1092. kfree_skb(skb);
  1093. goto out;
  1094. }
  1095. ipts = ippp_table[slot];
  1096. if (!(ipts->pppcfg & SC_ENABLE_IP)) { /* PPP connected ? */
  1097. if (ipts->debug & 0x1)
  1098. printk(KERN_INFO "%s: IP frame delayed.\n", netdev->name);
  1099. retval = 1;
  1100. goto out;
  1101. }
  1102. switch (ntohs(skb->protocol)) {
  1103. case ETH_P_IP:
  1104. proto = PPP_IP;
  1105. break;
  1106. case ETH_P_IPX:
  1107. proto = PPP_IPX; /* untested */
  1108. break;
  1109. default:
  1110. printk(KERN_ERR "isdn_ppp: skipped unsupported protocol: %#x.\n",
  1111. skb->protocol);
  1112. dev_kfree_skb(skb);
  1113. goto out;
  1114. }
  1115. lp = isdn_net_get_locked_lp(nd);
  1116. if (!lp) {
  1117. printk(KERN_WARNING "%s: all channels busy - requeuing!\n", netdev->name);
  1118. retval = 1;
  1119. goto out;
  1120. }
  1121. /* we have our lp locked from now on */
  1122. slot = lp->ppp_slot;
  1123. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  1124. printk(KERN_ERR "isdn_ppp_xmit: lp->ppp_slot(%d)\n",
  1125. lp->ppp_slot);
  1126. kfree_skb(skb);
  1127. goto unlock;
  1128. }
  1129. ipt = ippp_table[slot];
  1130. /*
  1131. * after this line .. requeueing in the device queue is no longer allowed!!!
  1132. */
  1133. /* Pull off the fake header we stuck on earlier to keep
  1134. * the fragmentation code happy.
  1135. */
  1136. skb_pull(skb,IPPP_MAX_HEADER);
  1137. #ifdef CONFIG_IPPP_FILTER
  1138. /* check if we should pass this packet
  1139. * the filter instructions are constructed assuming
  1140. * a four-byte PPP header on each packet */
  1141. *skb_push(skb, 4) = 1; /* indicate outbound */
  1142. {
  1143. u_int16_t *p = (u_int16_t *) skb->data;
  1144. p++;
  1145. *p = htons(proto);
  1146. }
  1147. if (ipt->pass_filter
  1148. && sk_run_filter(skb, ipt->pass_filter, ipt->pass_len) == 0) {
  1149. if (ipt->debug & 0x4)
  1150. printk(KERN_DEBUG "IPPP: outbound frame filtered.\n");
  1151. kfree_skb(skb);
  1152. goto unlock;
  1153. }
  1154. if (!(ipt->active_filter
  1155. && sk_run_filter(skb, ipt->active_filter,
  1156. ipt->active_len) == 0)) {
  1157. if (ipt->debug & 0x4)
  1158. printk(KERN_DEBUG "IPPP: link-active filter: reseting huptimer.\n");
  1159. lp->huptimer = 0;
  1160. }
  1161. skb_pull(skb, 4);
  1162. #else /* CONFIG_IPPP_FILTER */
  1163. lp->huptimer = 0;
  1164. #endif /* CONFIG_IPPP_FILTER */
  1165. if (ipt->debug & 0x4)
  1166. printk(KERN_DEBUG "xmit skb, len %d\n", (int) skb->len);
  1167. if (ipts->debug & 0x40)
  1168. isdn_ppp_frame_log("xmit0", skb->data, skb->len, 32,ipts->unit,lp->ppp_slot);
  1169. #ifdef CONFIG_ISDN_PPP_VJ
  1170. if (proto == PPP_IP && ipts->pppcfg & SC_COMP_TCP) { /* ipts here? probably yes, but check this again */
  1171. struct sk_buff *new_skb;
  1172. unsigned short hl;
  1173. /*
  1174. * we need to reserve enought space in front of
  1175. * sk_buff. old call to dev_alloc_skb only reserved
  1176. * 16 bytes, now we are looking what the driver want.
  1177. */
  1178. hl = dev->drv[lp->isdn_device]->interface->hl_hdrlen + IPPP_MAX_HEADER;
  1179. /*
  1180. * Note: hl might still be insufficient because the method
  1181. * above does not account for a possibible MPPP slave channel
  1182. * which had larger HL header space requirements than the
  1183. * master.
  1184. */
  1185. new_skb = alloc_skb(hl+skb->len, GFP_ATOMIC);
  1186. if (new_skb) {
  1187. u_char *buf;
  1188. int pktlen;
  1189. skb_reserve(new_skb, hl);
  1190. new_skb->dev = skb->dev;
  1191. skb_put(new_skb, skb->len);
  1192. buf = skb->data;
  1193. pktlen = slhc_compress(ipts->slcomp, skb->data, skb->len, new_skb->data,
  1194. &buf, !(ipts->pppcfg & SC_NO_TCP_CCID));
  1195. if (buf != skb->data) {
  1196. if (new_skb->data != buf)
  1197. printk(KERN_ERR "isdn_ppp: FATAL error after slhc_compress!!\n");
  1198. dev_kfree_skb(skb);
  1199. skb = new_skb;
  1200. } else {
  1201. dev_kfree_skb(new_skb);
  1202. }
  1203. skb_trim(skb, pktlen);
  1204. if (skb->data[0] & SL_TYPE_COMPRESSED_TCP) { /* cslip? style -> PPP */
  1205. proto = PPP_VJC_COMP;
  1206. skb->data[0] ^= SL_TYPE_COMPRESSED_TCP;
  1207. } else {
  1208. if (skb->data[0] >= SL_TYPE_UNCOMPRESSED_TCP)
  1209. proto = PPP_VJC_UNCOMP;
  1210. skb->data[0] = (skb->data[0] & 0x0f) | 0x40;
  1211. }
  1212. }
  1213. }
  1214. #endif
  1215. /*
  1216. * normal (single link) or bundle compression
  1217. */
  1218. if(ipts->compflags & SC_COMP_ON) {
  1219. /* We send compressed only if both down- und upstream
  1220. compression is negotiated, that means, CCP is up */
  1221. if(ipts->compflags & SC_DECOMP_ON) {
  1222. skb = isdn_ppp_compress(skb,&proto,ipt,ipts,0);
  1223. } else {
  1224. printk(KERN_DEBUG "isdn_ppp: CCP not yet up - sending as-is\n");
  1225. }
  1226. }
  1227. if (ipt->debug & 0x24)
  1228. printk(KERN_DEBUG "xmit2 skb, len %d, proto %04x\n", (int) skb->len, proto);
  1229. #ifdef CONFIG_ISDN_MPP
  1230. if (ipt->mpppcfg & SC_MP_PROT) {
  1231. /* we get mp_seqno from static isdn_net_local */
  1232. long mp_seqno = ipts->mp_seqno;
  1233. ipts->mp_seqno++;
  1234. if (ipt->mpppcfg & SC_OUT_SHORT_SEQ) {
  1235. unsigned char *data = isdn_ppp_skb_push(&skb, 3);
  1236. if(!data)
  1237. goto unlock;
  1238. mp_seqno &= 0xfff;
  1239. data[0] = MP_BEGIN_FRAG | MP_END_FRAG | ((mp_seqno >> 8) & 0xf); /* (B)egin & (E)ndbit .. */
  1240. data[1] = mp_seqno & 0xff;
  1241. data[2] = proto; /* PID compression */
  1242. } else {
  1243. unsigned char *data = isdn_ppp_skb_push(&skb, 5);
  1244. if(!data)
  1245. goto unlock;
  1246. data[0] = MP_BEGIN_FRAG | MP_END_FRAG; /* (B)egin & (E)ndbit .. */
  1247. data[1] = (mp_seqno >> 16) & 0xff; /* sequence number: 24bit */
  1248. data[2] = (mp_seqno >> 8) & 0xff;
  1249. data[3] = (mp_seqno >> 0) & 0xff;
  1250. data[4] = proto; /* PID compression */
  1251. }
  1252. proto = PPP_MP; /* MP Protocol, 0x003d */
  1253. }
  1254. #endif
  1255. /*
  1256. * 'link in bundle' compression ...
  1257. */
  1258. if(ipt->compflags & SC_LINK_COMP_ON)
  1259. skb = isdn_ppp_compress(skb,&proto,ipt,ipts,1);
  1260. if( (ipt->pppcfg & SC_COMP_PROT) && (proto <= 0xff) ) {
  1261. unsigned char *data = isdn_ppp_skb_push(&skb,1);
  1262. if(!data)
  1263. goto unlock;
  1264. data[0] = proto & 0xff;
  1265. }
  1266. else {
  1267. unsigned char *data = isdn_ppp_skb_push(&skb,2);
  1268. if(!data)
  1269. goto unlock;
  1270. data[0] = (proto >> 8) & 0xff;
  1271. data[1] = proto & 0xff;
  1272. }
  1273. if(!(ipt->pppcfg & SC_COMP_AC)) {
  1274. unsigned char *data = isdn_ppp_skb_push(&skb,2);
  1275. if(!data)
  1276. goto unlock;
  1277. data[0] = 0xff; /* All Stations */
  1278. data[1] = 0x03; /* Unnumbered information */
  1279. }
  1280. /* tx-stats are now updated via BSENT-callback */
  1281. if (ipts->debug & 0x40) {
  1282. printk(KERN_DEBUG "skb xmit: len: %d\n", (int) skb->len);
  1283. isdn_ppp_frame_log("xmit", skb->data, skb->len, 32,ipt->unit,lp->ppp_slot);
  1284. }
  1285. isdn_net_writebuf_skb(lp, skb);
  1286. unlock:
  1287. spin_unlock_bh(&lp->xmit_lock);
  1288. out:
  1289. return retval;
  1290. }
  1291. #ifdef CONFIG_IPPP_FILTER
  1292. /*
  1293. * check if this packet may trigger auto-dial.
  1294. */
  1295. int isdn_ppp_autodial_filter(struct sk_buff *skb, isdn_net_local *lp)
  1296. {
  1297. struct ippp_struct *is = ippp_table[lp->ppp_slot];
  1298. u_int16_t proto;
  1299. int drop = 0;
  1300. switch (ntohs(skb->protocol)) {
  1301. case ETH_P_IP:
  1302. proto = PPP_IP;
  1303. break;
  1304. case ETH_P_IPX:
  1305. proto = PPP_IPX;
  1306. break;
  1307. default:
  1308. printk(KERN_ERR "isdn_ppp_autodial_filter: unsupported protocol 0x%x.\n",
  1309. skb->protocol);
  1310. return 1;
  1311. }
  1312. /* the filter instructions are constructed assuming
  1313. * a four-byte PPP header on each packet. we have to
  1314. * temporarily remove part of the fake header stuck on
  1315. * earlier.
  1316. */
  1317. *skb_pull(skb, IPPP_MAX_HEADER - 4) = 1; /* indicate outbound */
  1318. {
  1319. u_int16_t *p = (u_int16_t *) skb->data;
  1320. p++;
  1321. *p = htons(proto);
  1322. }
  1323. drop |= is->pass_filter
  1324. && sk_run_filter(skb, is->pass_filter, is->pass_len) == 0;
  1325. drop |= is->active_filter
  1326. && sk_run_filter(skb, is->active_filter, is->active_len) == 0;
  1327. skb_push(skb, IPPP_MAX_HEADER - 4);
  1328. return drop;
  1329. }
  1330. #endif
  1331. #ifdef CONFIG_ISDN_MPP
  1332. /* this is _not_ rfc1990 header, but something we convert both short and long
  1333. * headers to for convinience's sake:
  1334. * byte 0 is flags as in rfc1990
  1335. * bytes 1...4 is 24-bit seqence number converted to host byte order
  1336. */
  1337. #define MP_HEADER_LEN 5
  1338. #define MP_LONGSEQ_MASK 0x00ffffff
  1339. #define MP_SHORTSEQ_MASK 0x00000fff
  1340. #define MP_LONGSEQ_MAX MP_LONGSEQ_MASK
  1341. #define MP_SHORTSEQ_MAX MP_SHORTSEQ_MASK
  1342. #define MP_LONGSEQ_MAXBIT ((MP_LONGSEQ_MASK+1)>>1)
  1343. #define MP_SHORTSEQ_MAXBIT ((MP_SHORTSEQ_MASK+1)>>1)
  1344. /* sequence-wrap safe comparisions (for long sequence)*/
  1345. #define MP_LT(a,b) ((a-b)&MP_LONGSEQ_MAXBIT)
  1346. #define MP_LE(a,b) !((b-a)&MP_LONGSEQ_MAXBIT)
  1347. #define MP_GT(a,b) ((b-a)&MP_LONGSEQ_MAXBIT)
  1348. #define MP_GE(a,b) !((a-b)&MP_LONGSEQ_MAXBIT)
  1349. #define MP_SEQ(f) ((*(u32*)(f->data+1)))
  1350. #define MP_FLAGS(f) (f->data[0])
  1351. static int isdn_ppp_mp_bundle_array_init(void)
  1352. {
  1353. int i;
  1354. int sz = ISDN_MAX_CHANNELS*sizeof(ippp_bundle);
  1355. if( (isdn_ppp_bundle_arr = kzalloc(sz, GFP_KERNEL)) == NULL )
  1356. return -ENOMEM;
  1357. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1358. spin_lock_init(&isdn_ppp_bundle_arr[i].lock);
  1359. skb_queue_head_init(&isdn_ppp_bundle_arr[i].frags);
  1360. }
  1361. return 0;
  1362. }
  1363. static ippp_bundle * isdn_ppp_mp_bundle_alloc(void)
  1364. {
  1365. int i;
  1366. for( i = 0; i < ISDN_MAX_CHANNELS; i++ )
  1367. if (isdn_ppp_bundle_arr[i].ref_ct <= 0)
  1368. return (isdn_ppp_bundle_arr + i);
  1369. return NULL;
  1370. }
  1371. static int isdn_ppp_mp_init( isdn_net_local * lp, ippp_bundle * add_to )
  1372. {
  1373. struct ippp_struct * is;
  1374. if (lp->ppp_slot < 0) {
  1375. printk(KERN_ERR "%s: lp->ppp_slot(%d) out of range\n",
  1376. __func__, lp->ppp_slot);
  1377. return(-EINVAL);
  1378. }
  1379. is = ippp_table[lp->ppp_slot];
  1380. if (add_to) {
  1381. if( lp->netdev->pb )
  1382. lp->netdev->pb->ref_ct--;
  1383. lp->netdev->pb = add_to;
  1384. } else { /* first link in a bundle */
  1385. is->mp_seqno = 0;
  1386. if ((lp->netdev->pb = isdn_ppp_mp_bundle_alloc()) == NULL)
  1387. return -ENOMEM;
  1388. lp->next = lp->last = lp; /* nobody else in a queue */
  1389. skb_queue_head_init(&lp->netdev->pb->frags);
  1390. lp->netdev->pb->frames = 0;
  1391. lp->netdev->pb->seq = UINT_MAX;
  1392. }
  1393. lp->netdev->pb->ref_ct++;
  1394. is->last_link_seqno = 0;
  1395. return 0;
  1396. }
  1397. static u32 isdn_ppp_mp_get_seq( int short_seq,
  1398. struct sk_buff * skb, u32 last_seq );
  1399. static void isdn_ppp_mp_discard(ippp_bundle *mp, struct sk_buff *from,
  1400. struct sk_buff *to);
  1401. static void isdn_ppp_mp_reassembly(isdn_net_dev *net_dev, isdn_net_local *lp,
  1402. struct sk_buff *from, struct sk_buff *to,
  1403. u32 lastseq);
  1404. static void isdn_ppp_mp_free_skb(ippp_bundle *mp, struct sk_buff *skb);
  1405. static void isdn_ppp_mp_print_recv_pkt( int slot, struct sk_buff * skb );
  1406. static void isdn_ppp_mp_receive(isdn_net_dev * net_dev, isdn_net_local * lp,
  1407. struct sk_buff *skb)
  1408. {
  1409. struct sk_buff *newfrag, *frag, *start, *nextf;
  1410. u32 newseq, minseq, thisseq;
  1411. isdn_mppp_stats *stats;
  1412. struct ippp_struct *is;
  1413. unsigned long flags;
  1414. isdn_net_local *lpq;
  1415. ippp_bundle *mp;
  1416. int slot;
  1417. spin_lock_irqsave(&net_dev->pb->lock, flags);
  1418. mp = net_dev->pb;
  1419. stats = &mp->stats;
  1420. slot = lp->ppp_slot;
  1421. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  1422. printk(KERN_ERR "%s: lp->ppp_slot(%d)\n",
  1423. __func__, lp->ppp_slot);
  1424. stats->frame_drops++;
  1425. dev_kfree_skb(skb);
  1426. spin_unlock_irqrestore(&mp->lock, flags);
  1427. return;
  1428. }
  1429. is = ippp_table[slot];
  1430. if (++mp->frames > stats->max_queue_len)
  1431. stats->max_queue_len = mp->frames;
  1432. if (is->debug & 0x8)
  1433. isdn_ppp_mp_print_recv_pkt(lp->ppp_slot, skb);
  1434. newseq = isdn_ppp_mp_get_seq(is->mpppcfg & SC_IN_SHORT_SEQ,
  1435. skb, is->last_link_seqno);
  1436. /* if this packet seq # is less than last already processed one,
  1437. * toss it right away, but check for sequence start case first
  1438. */
  1439. if (mp->seq > MP_LONGSEQ_MAX && (newseq & MP_LONGSEQ_MAXBIT)) {
  1440. mp->seq = newseq; /* the first packet: required for
  1441. * rfc1990 non-compliant clients --
  1442. * prevents constant packet toss */
  1443. } else if( MP_LT(newseq, mp->seq) ) {
  1444. stats->frame_drops++;
  1445. isdn_ppp_mp_free_skb(mp, skb);
  1446. spin_unlock_irqrestore(&mp->lock, flags);
  1447. return;
  1448. }
  1449. /* find the minimum received sequence number over all links */
  1450. is->last_link_seqno = minseq = newseq;
  1451. for (lpq = net_dev->queue;;) {
  1452. slot = lpq->ppp_slot;
  1453. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  1454. printk(KERN_ERR "%s: lpq->ppp_slot(%d)\n",
  1455. __func__, lpq->ppp_slot);
  1456. } else {
  1457. u32 lls = ippp_table[slot]->last_link_seqno;
  1458. if (MP_LT(lls, minseq))
  1459. minseq = lls;
  1460. }
  1461. if ((lpq = lpq->next) == net_dev->queue)
  1462. break;
  1463. }
  1464. if (MP_LT(minseq, mp->seq))
  1465. minseq = mp->seq; /* can't go beyond already processed
  1466. * packets */
  1467. newfrag = skb;
  1468. /* Insert new fragment into the proper sequence slot. */
  1469. skb_queue_walk(&mp->frags, frag) {
  1470. if (MP_SEQ(frag) == newseq) {
  1471. isdn_ppp_mp_free_skb(mp, newfrag);
  1472. newfrag = NULL;
  1473. break;
  1474. }
  1475. if (MP_LT(newseq, MP_SEQ(frag))) {
  1476. __skb_queue_before(&mp->frags, frag, newfrag);
  1477. newfrag = NULL;
  1478. break;
  1479. }
  1480. }
  1481. if (newfrag)
  1482. __skb_queue_tail(&mp->frags, newfrag);
  1483. frag = skb_peek(&mp->frags);
  1484. start = ((MP_FLAGS(frag) & MP_BEGIN_FRAG) &&
  1485. (MP_SEQ(frag) == mp->seq)) ? frag : NULL;
  1486. if (!start)
  1487. goto check_overflow;
  1488. /* main fragment traversing loop
  1489. *
  1490. * try to accomplish several tasks:
  1491. * - reassemble any complete fragment sequence (non-null 'start'
  1492. * indicates there is a continguous sequence present)
  1493. * - discard any incomplete sequences that are below minseq -- due
  1494. * to the fact that sender always increment sequence number, if there
  1495. * is an incomplete sequence below minseq, no new fragments would
  1496. * come to complete such sequence and it should be discarded
  1497. *
  1498. * loop completes when we accomplished the following tasks:
  1499. * - we hit a gap in the sequence, so no reassembly/processing is
  1500. * possible ('start' would be set to NULL)
  1501. *
  1502. * algorithm for this code is derived from code in the book
  1503. * 'PPP Design And Debugging' by James Carlson (Addison-Wesley)
  1504. */
  1505. skb_queue_walk_safe(&mp->frags, frag, nextf) {
  1506. thisseq = MP_SEQ(frag);
  1507. /* check for misplaced start */
  1508. if (start != frag && (MP_FLAGS(frag) & MP_BEGIN_FRAG)) {
  1509. printk(KERN_WARNING"isdn_mppp(seq %d): new "
  1510. "BEGIN flag with no prior END", thisseq);
  1511. stats->seqerrs++;
  1512. stats->frame_drops++;
  1513. isdn_ppp_mp_discard(mp, start, frag);
  1514. start = frag;
  1515. } else if (MP_LE(thisseq, minseq)) {
  1516. if (MP_FLAGS(frag) & MP_BEGIN_FRAG)
  1517. start = frag;
  1518. else {
  1519. if (MP_FLAGS(frag) & MP_END_FRAG)
  1520. stats->frame_drops++;
  1521. __skb_unlink(skb, &mp->frags);
  1522. isdn_ppp_mp_free_skb(mp, frag);
  1523. continue;
  1524. }
  1525. }
  1526. /* if we have end fragment, then we have full reassembly
  1527. * sequence -- reassemble and process packet now
  1528. */
  1529. if (MP_FLAGS(frag) & MP_END_FRAG) {
  1530. minseq = mp->seq = (thisseq+1) & MP_LONGSEQ_MASK;
  1531. /* Reassemble the packet then dispatch it */
  1532. isdn_ppp_mp_reassembly(net_dev, lp, start, frag, thisseq);
  1533. start = NULL;
  1534. frag = NULL;
  1535. }
  1536. /* check if need to update start pointer: if we just
  1537. * reassembled the packet and sequence is contiguous
  1538. * then next fragment should be the start of new reassembly
  1539. * if sequence is contiguous, but we haven't reassembled yet,
  1540. * keep going.
  1541. * if sequence is not contiguous, either clear everyting
  1542. * below low watermark and set start to the next frag or
  1543. * clear start ptr.
  1544. */
  1545. if (nextf != (struct sk_buff *)&mp->frags &&
  1546. ((thisseq+1) & MP_LONGSEQ_MASK) == MP_SEQ(nextf)) {
  1547. /* if we just reassembled and the next one is here,
  1548. * then start another reassembly.
  1549. */
  1550. if (frag == NULL) {
  1551. if (MP_FLAGS(nextf) & MP_BEGIN_FRAG)
  1552. start = nextf;
  1553. else {
  1554. printk(KERN_WARNING"isdn_mppp(seq %d):"
  1555. " END flag with no following "
  1556. "BEGIN", thisseq);
  1557. stats->seqerrs++;
  1558. }
  1559. }
  1560. } else {
  1561. if (nextf != (struct sk_buff *)&mp->frags &&
  1562. frag != NULL &&
  1563. MP_LT(thisseq, minseq)) {
  1564. /* we've got a break in the sequence
  1565. * and we not at the end yet
  1566. * and we did not just reassembled
  1567. *(if we did, there wouldn't be anything before)
  1568. * and we below the low watermark
  1569. * discard all the frames below low watermark
  1570. * and start over */
  1571. stats->frame_drops++;
  1572. isdn_ppp_mp_discard(mp, start, nextf);
  1573. }
  1574. /* break in the sequence, no reassembly */
  1575. start = NULL;
  1576. }
  1577. if (!start)
  1578. break;
  1579. }
  1580. check_overflow:
  1581. /* rather straighforward way to deal with (not very) possible
  1582. * queue overflow
  1583. */
  1584. if (mp->frames > MP_MAX_QUEUE_LEN) {
  1585. stats->overflows++;
  1586. skb_queue_walk_safe(&mp->frags, frag, nextf) {
  1587. if (mp->frames <= MP_MAX_QUEUE_LEN)
  1588. break;
  1589. __skb_unlink(frag, &mp->frags);
  1590. isdn_ppp_mp_free_skb(mp, frag);
  1591. }
  1592. }
  1593. spin_unlock_irqrestore(&mp->lock, flags);
  1594. }
  1595. static void isdn_ppp_mp_cleanup(isdn_net_local *lp)
  1596. {
  1597. struct sk_buff *skb, *tmp;
  1598. skb_queue_walk_safe(&lp->netdev->pb->frags, skb, tmp) {
  1599. __skb_unlink(skb, &lp->netdev->pb->frags);
  1600. isdn_ppp_mp_free_skb(lp->netdev->pb, skb);
  1601. }
  1602. }
  1603. static u32 isdn_ppp_mp_get_seq( int short_seq,
  1604. struct sk_buff * skb, u32 last_seq )
  1605. {
  1606. u32 seq;
  1607. int flags = skb->data[0] & (MP_BEGIN_FRAG | MP_END_FRAG);
  1608. if( !short_seq )
  1609. {
  1610. seq = ntohl(*(u32*)skb->data) & MP_LONGSEQ_MASK;
  1611. skb_push(skb,1);
  1612. }
  1613. else
  1614. {
  1615. /* convert 12-bit short seq number to 24-bit long one
  1616. */
  1617. seq = ntohs(*(u16*)skb->data) & MP_SHORTSEQ_MASK;
  1618. /* check for seqence wrap */
  1619. if( !(seq & MP_SHORTSEQ_MAXBIT) &&
  1620. (last_seq & MP_SHORTSEQ_MAXBIT) &&
  1621. (unsigned long)last_seq <= MP_LONGSEQ_MAX )
  1622. seq |= (last_seq + MP_SHORTSEQ_MAX+1) &
  1623. (~MP_SHORTSEQ_MASK & MP_LONGSEQ_MASK);
  1624. else
  1625. seq |= last_seq & (~MP_SHORTSEQ_MASK & MP_LONGSEQ_MASK);
  1626. skb_push(skb, 3); /* put converted seqence back in skb */
  1627. }
  1628. *(u32*)(skb->data+1) = seq; /* put seqence back in _host_ byte
  1629. * order */
  1630. skb->data[0] = flags; /* restore flags */
  1631. return seq;
  1632. }
  1633. static void isdn_ppp_mp_discard(ippp_bundle *mp, struct sk_buff *from,
  1634. struct sk_buff *to)
  1635. {
  1636. if (from) {
  1637. struct sk_buff *skb, *tmp;
  1638. int freeing = 0;
  1639. skb_queue_walk_safe(&mp->frags, skb, tmp) {
  1640. if (skb == to)
  1641. break;
  1642. if (skb == from)
  1643. freeing = 1;
  1644. if (!freeing)
  1645. continue;
  1646. __skb_unlink(skb, &mp->frags);
  1647. isdn_ppp_mp_free_skb(mp, skb);
  1648. }
  1649. }
  1650. }
  1651. static unsigned int calc_tot_len(struct sk_buff_head *queue,
  1652. struct sk_buff *from, struct sk_buff *to)
  1653. {
  1654. unsigned int tot_len = 0;
  1655. struct sk_buff *skb;
  1656. int found_start = 0;
  1657. skb_queue_walk(queue, skb) {
  1658. if (skb == from)
  1659. found_start = 1;
  1660. if (!found_start)
  1661. continue;
  1662. tot_len += skb->len - MP_HEADER_LEN;
  1663. if (skb == to)
  1664. break;
  1665. }
  1666. return tot_len;
  1667. }
  1668. /* Reassemble packet using fragments in the reassembly queue from
  1669. * 'from' until 'to', inclusive.
  1670. */
  1671. static void isdn_ppp_mp_reassembly(isdn_net_dev *net_dev, isdn_net_local *lp,
  1672. struct sk_buff *from, struct sk_buff *to,
  1673. u32 lastseq)
  1674. {
  1675. ippp_bundle *mp = net_dev->pb;
  1676. unsigned int tot_len;
  1677. struct sk_buff *skb;
  1678. int proto;
  1679. if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
  1680. printk(KERN_ERR "%s: lp->ppp_slot(%d) out of range\n",
  1681. __func__, lp->ppp_slot);
  1682. return;
  1683. }
  1684. tot_len = calc_tot_len(&mp->frags, from, to);
  1685. if (MP_FLAGS(from) == (MP_BEGIN_FRAG | MP_END_FRAG)) {
  1686. if (ippp_table[lp->ppp_slot]->debug & 0x40)
  1687. printk(KERN_DEBUG "isdn_mppp: reassembly: frame %d, "
  1688. "len %d\n", MP_SEQ(from), from->len);
  1689. skb = from;
  1690. skb_pull(skb, MP_HEADER_LEN);
  1691. __skb_unlink(skb, &mp->frags);
  1692. mp->frames--;
  1693. } else {
  1694. struct sk_buff *walk, *tmp;
  1695. int found_start = 0;
  1696. if (ippp_table[lp->ppp_slot]->debug & 0x40)
  1697. printk(KERN_DEBUG"isdn_mppp: reassembling frames %d "
  1698. "to %d, len %d\n", MP_SEQ(from), lastseq,
  1699. tot_len);
  1700. skb = dev_alloc_skb(tot_len);
  1701. if (!skb)
  1702. printk(KERN_ERR "isdn_mppp: cannot allocate sk buff "
  1703. "of size %d\n", tot_len);
  1704. found_start = 0;
  1705. skb_queue_walk_safe(&mp->frags, walk, tmp) {
  1706. if (walk == from)
  1707. found_start = 1;
  1708. if (!found_start)
  1709. continue;
  1710. if (skb) {
  1711. unsigned int len = walk->len - MP_HEADER_LEN;
  1712. skb_copy_from_linear_data_offset(walk, MP_HEADER_LEN,
  1713. skb_put(skb, len),
  1714. len);
  1715. }
  1716. __skb_unlink(walk, &mp->frags);
  1717. isdn_ppp_mp_free_skb(mp, walk);
  1718. if (walk == to)
  1719. break;
  1720. }
  1721. }
  1722. if (!skb)
  1723. return;
  1724. proto = isdn_ppp_strip_proto(skb);
  1725. isdn_ppp_push_higher(net_dev, lp, skb, proto);
  1726. }
  1727. static void isdn_ppp_mp_free_skb(ippp_bundle *mp, struct sk_buff *skb)
  1728. {
  1729. dev_kfree_skb(skb);
  1730. mp->frames--;
  1731. }
  1732. static void isdn_ppp_mp_print_recv_pkt( int slot, struct sk_buff * skb )
  1733. {
  1734. printk(KERN_DEBUG "mp_recv: %d/%d -> %02x %02x %02x %02x %02x %02x\n",
  1735. slot, (int) skb->len,
  1736. (int) skb->data[0], (int) skb->data[1], (int) skb->data[2],
  1737. (int) skb->data[3], (int) skb->data[4], (int) skb->data[5]);
  1738. }
  1739. static int
  1740. isdn_ppp_bundle(struct ippp_struct *is, int unit)
  1741. {
  1742. char ifn[IFNAMSIZ + 1];
  1743. isdn_net_dev *p;
  1744. isdn_net_local *lp, *nlp;
  1745. int rc;
  1746. unsigned long flags;
  1747. sprintf(ifn, "ippp%d", unit);
  1748. p = isdn_net_findif(ifn);
  1749. if (!p) {
  1750. printk(KERN_ERR "ippp_bundle: cannot find %s\n", ifn);
  1751. return -EINVAL;
  1752. }
  1753. spin_lock_irqsave(&p->pb->lock, flags);
  1754. nlp = is->lp;
  1755. lp = p->queue;
  1756. if( nlp->ppp_slot < 0 || nlp->ppp_slot >= ISDN_MAX_CHANNELS ||
  1757. lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS ) {
  1758. printk(KERN_ERR "ippp_bundle: binding to invalid slot %d\n",
  1759. nlp->ppp_slot < 0 || nlp->ppp_slot >= ISDN_MAX_CHANNELS ?
  1760. nlp->ppp_slot : lp->ppp_slot );
  1761. rc = -EINVAL;
  1762. goto out;
  1763. }
  1764. isdn_net_add_to_bundle(p, nlp);
  1765. ippp_table[nlp->ppp_slot]->unit = ippp_table[lp->ppp_slot]->unit;
  1766. /* maybe also SC_CCP stuff */
  1767. ippp_table[nlp->ppp_slot]->pppcfg |= ippp_table[lp->ppp_slot]->pppcfg &
  1768. (SC_ENABLE_IP | SC_NO_TCP_CCID | SC_REJ_COMP_TCP);
  1769. ippp_table[nlp->ppp_slot]->mpppcfg |= ippp_table[lp->ppp_slot]->mpppcfg &
  1770. (SC_MP_PROT | SC_REJ_MP_PROT | SC_OUT_SHORT_SEQ | SC_IN_SHORT_SEQ);
  1771. rc = isdn_ppp_mp_init(nlp, p->pb);
  1772. out:
  1773. spin_unlock_irqrestore(&p->pb->lock, flags);
  1774. return rc;
  1775. }
  1776. #endif /* CONFIG_ISDN_MPP */
  1777. /*
  1778. * network device ioctl handlers
  1779. */
  1780. static int
  1781. isdn_ppp_dev_ioctl_stats(int slot, struct ifreq *ifr, struct net_device *dev)
  1782. {
  1783. struct ppp_stats __user *res = ifr->ifr_data;
  1784. struct ppp_stats t;
  1785. isdn_net_local *lp = (isdn_net_local *) dev->priv;
  1786. if (!access_ok(VERIFY_WRITE, res, sizeof(struct ppp_stats)))
  1787. return -EFAULT;
  1788. /* build a temporary stat struct and copy it to user space */
  1789. memset(&t, 0, sizeof(struct ppp_stats));
  1790. if (dev->flags & IFF_UP) {
  1791. t.p.ppp_ipackets = lp->stats.rx_packets;
  1792. t.p.ppp_ibytes = lp->stats.rx_bytes;
  1793. t.p.ppp_ierrors = lp->stats.rx_errors;
  1794. t.p.ppp_opackets = lp->stats.tx_packets;
  1795. t.p.ppp_obytes = lp->stats.tx_bytes;
  1796. t.p.ppp_oerrors = lp->stats.tx_errors;
  1797. #ifdef CONFIG_ISDN_PPP_VJ
  1798. if (slot >= 0 && ippp_table[slot]->slcomp) {
  1799. struct slcompress *slcomp = ippp_table[slot]->slcomp;
  1800. t.vj.vjs_packets = slcomp->sls_o_compressed + slcomp->sls_o_uncompressed;
  1801. t.vj.vjs_compressed = slcomp->sls_o_compressed;
  1802. t.vj.vjs_searches = slcomp->sls_o_searches;
  1803. t.vj.vjs_misses = slcomp->sls_o_misses;
  1804. t.vj.vjs_errorin = slcomp->sls_i_error;
  1805. t.vj.vjs_tossed = slcomp->sls_i_tossed;
  1806. t.vj.vjs_uncompressedin = slcomp->sls_i_uncompressed;
  1807. t.vj.vjs_compressedin = slcomp->sls_i_compressed;
  1808. }
  1809. #endif
  1810. }
  1811. if (copy_to_user(res, &t, sizeof(struct ppp_stats)))
  1812. return -EFAULT;
  1813. return 0;
  1814. }
  1815. int
  1816. isdn_ppp_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  1817. {
  1818. int error=0;
  1819. int len;
  1820. isdn_net_local *lp = (isdn_net_local *) dev->priv;
  1821. if (lp->p_encap != ISDN_NET_ENCAP_SYNCPPP)
  1822. return -EINVAL;
  1823. switch (cmd) {
  1824. #define PPP_VERSION "2.3.7"
  1825. case SIOCGPPPVER:
  1826. len = strlen(PPP_VERSION) + 1;
  1827. if (copy_to_user(ifr->ifr_data, PPP_VERSION, len))
  1828. error = -EFAULT;
  1829. break;
  1830. case SIOCGPPPSTATS:
  1831. error = isdn_ppp_dev_ioctl_stats(lp->ppp_slot, ifr, dev);
  1832. break;
  1833. default:
  1834. error = -EINVAL;
  1835. break;
  1836. }
  1837. return error;
  1838. }
  1839. static int
  1840. isdn_ppp_if_get_unit(char *name)
  1841. {
  1842. int len,
  1843. i,
  1844. unit = 0,
  1845. deci;
  1846. len = strlen(name);
  1847. if (strncmp("ippp", name, 4) || len > 8)
  1848. return -1;
  1849. for (i = 0, deci = 1; i < len; i++, deci *= 10) {
  1850. char a = name[len - i - 1];
  1851. if (a >= '0' && a <= '9')
  1852. unit += (a - '0') * deci;
  1853. else
  1854. break;
  1855. }
  1856. if (!i || len - i != 4)
  1857. unit = -1;
  1858. return unit;
  1859. }
  1860. int
  1861. isdn_ppp_dial_slave(char *name)
  1862. {
  1863. #ifdef CONFIG_ISDN_MPP
  1864. isdn_net_dev *ndev;
  1865. isdn_net_local *lp;
  1866. struct net_device *sdev;
  1867. if (!(ndev = isdn_net_findif(name)))
  1868. return 1;
  1869. lp = ndev->local;
  1870. if (!(lp->flags & ISDN_NET_CONNECTED))
  1871. return 5;
  1872. sdev = lp->slave;
  1873. while (sdev) {
  1874. isdn_net_local *mlp = (isdn_net_local *) sdev->priv;
  1875. if (!(mlp->flags & ISDN_NET_CONNECTED))
  1876. break;
  1877. sdev = mlp->slave;
  1878. }
  1879. if (!sdev)
  1880. return 2;
  1881. isdn_net_dial_req((isdn_net_local *) sdev->priv);
  1882. return 0;
  1883. #else
  1884. return -1;
  1885. #endif
  1886. }
  1887. int
  1888. isdn_ppp_hangup_slave(char *name)
  1889. {
  1890. #ifdef CONFIG_ISDN_MPP
  1891. isdn_net_dev *ndev;
  1892. isdn_net_local *lp;
  1893. struct net_device *sdev;
  1894. if (!(ndev = isdn_net_findif(name)))
  1895. return 1;
  1896. lp = ndev->local;
  1897. if (!(lp->flags & ISDN_NET_CONNECTED))
  1898. return 5;
  1899. sdev = lp->slave;
  1900. while (sdev) {
  1901. isdn_net_local *mlp = (isdn_net_local *) sdev->priv;
  1902. if (mlp->slave) { /* find last connected link in chain */
  1903. isdn_net_local *nlp = (isdn_net_local *) mlp->slave->priv;
  1904. if (!(nlp->flags & ISDN_NET_CONNECTED))
  1905. break;
  1906. } else if (mlp->flags & ISDN_NET_CONNECTED)
  1907. break;
  1908. sdev = mlp->slave;
  1909. }
  1910. if (!sdev)
  1911. return 2;
  1912. isdn_net_hangup(sdev);
  1913. return 0;
  1914. #else
  1915. return -1;
  1916. #endif
  1917. }
  1918. /*
  1919. * PPP compression stuff
  1920. */
  1921. /* Push an empty CCP Data Frame up to the daemon to wake it up and let it
  1922. generate a CCP Reset-Request or tear down CCP altogether */
  1923. static void isdn_ppp_ccp_kickup(struct ippp_struct *is)
  1924. {
  1925. isdn_ppp_fill_rq(NULL, 0, PPP_COMP, is->lp->ppp_slot);
  1926. }
  1927. /* In-kernel handling of CCP Reset-Request and Reset-Ack is necessary,
  1928. but absolutely nontrivial. The most abstruse problem we are facing is
  1929. that the generation, reception and all the handling of timeouts and
  1930. resends including proper request id management should be entirely left
  1931. to the (de)compressor, but indeed is not covered by the current API to
  1932. the (de)compressor. The API is a prototype version from PPP where only
  1933. some (de)compressors have yet been implemented and all of them are
  1934. rather simple in their reset handling. Especially, their is only one
  1935. outstanding ResetAck at a time with all of them and ResetReq/-Acks do
  1936. not have parameters. For this very special case it was sufficient to
  1937. just return an error code from the decompressor and have a single
  1938. reset() entry to communicate all the necessary information between
  1939. the framework and the (de)compressor. Bad enough, LZS is different
  1940. (and any other compressor may be different, too). It has multiple
  1941. histories (eventually) and needs to Reset each of them independently
  1942. and thus uses multiple outstanding Acks and history numbers as an
  1943. additional parameter to Reqs/Acks.
  1944. All that makes it harder to port the reset state engine into the
  1945. kernel because it is not just the same simple one as in (i)pppd but
  1946. it must be able to pass additional parameters and have multiple out-
  1947. standing Acks. We are trying to achieve the impossible by handling
  1948. reset transactions independent by their id. The id MUST change when
  1949. the data portion changes, thus any (de)compressor who uses more than
  1950. one resettable state must provide and recognize individual ids for
  1951. each individual reset transaction. The framework itself does _only_
  1952. differentiate them by id, because it has no other semantics like the
  1953. (de)compressor might.
  1954. This looks like a major redesign of the interface would be nice,
  1955. but I don't have an idea how to do it better. */
  1956. /* Send a CCP Reset-Request or Reset-Ack directly from the kernel. This is
  1957. getting that lengthy because there is no simple "send-this-frame-out"
  1958. function above but every wrapper does a bit different. Hope I guess
  1959. correct in this hack... */
  1960. static void isdn_ppp_ccp_xmit_reset(struct ippp_struct *is, int proto,
  1961. unsigned char code, unsigned char id,
  1962. unsigned char *data, int len)
  1963. {
  1964. struct sk_buff *skb;
  1965. unsigned char *p;
  1966. int hl;
  1967. int cnt = 0;
  1968. isdn_net_local *lp = is->lp;
  1969. /* Alloc large enough skb */
  1970. hl = dev->drv[lp->isdn_device]->interface->hl_hdrlen;
  1971. skb = alloc_skb(len + hl + 16,GFP_ATOMIC);
  1972. if(!skb) {
  1973. printk(KERN_WARNING
  1974. "ippp: CCP cannot send reset - out of memory\n");
  1975. return;
  1976. }
  1977. skb_reserve(skb, hl);
  1978. /* We may need to stuff an address and control field first */
  1979. if(!(is->pppcfg & SC_COMP_AC)) {
  1980. p = skb_put(skb, 2);
  1981. *p++ = 0xff;
  1982. *p++ = 0x03;
  1983. }
  1984. /* Stuff proto, code, id and length */
  1985. p = skb_put(skb, 6);
  1986. *p++ = (proto >> 8);
  1987. *p++ = (proto & 0xff);
  1988. *p++ = code;
  1989. *p++ = id;
  1990. cnt = 4 + len;
  1991. *p++ = (cnt >> 8);
  1992. *p++ = (cnt & 0xff);
  1993. /* Now stuff remaining bytes */
  1994. if(len) {
  1995. p = skb_put(skb, len);
  1996. memcpy(p, data, len);
  1997. }
  1998. /* skb is now ready for xmit */
  1999. printk(KERN_DEBUG "Sending CCP Frame:\n");
  2000. isdn_ppp_frame_log("ccp-xmit", skb->data, skb->len, 32, is->unit,lp->ppp_slot);
  2001. isdn_net_write_super(lp, skb);
  2002. }
  2003. /* Allocate the reset state vector */
  2004. static struct ippp_ccp_reset *isdn_ppp_ccp_reset_alloc(struct ippp_struct *is)
  2005. {
  2006. struct ippp_ccp_reset *r;
  2007. r = kzalloc(sizeof(struct ippp_ccp_reset), GFP_KERNEL);
  2008. if(!r) {
  2009. printk(KERN_ERR "ippp_ccp: failed to allocate reset data"
  2010. " structure - no mem\n");
  2011. return NULL;
  2012. }
  2013. printk(KERN_DEBUG "ippp_ccp: allocated reset data structure %p\n", r);
  2014. is->reset = r;
  2015. return r;
  2016. }
  2017. /* Destroy the reset state vector. Kill all pending timers first. */
  2018. static void isdn_ppp_ccp_reset_free(struct ippp_struct *is)
  2019. {
  2020. unsigned int id;
  2021. printk(KERN_DEBUG "ippp_ccp: freeing reset data structure %p\n",
  2022. is->reset);
  2023. for(id = 0; id < 256; id++) {
  2024. if(is->reset->rs[id]) {
  2025. isdn_ppp_ccp_reset_free_state(is, (unsigned char)id);
  2026. }
  2027. }
  2028. kfree(is->reset);
  2029. is->reset = NULL;
  2030. }
  2031. /* Free a given state and clear everything up for later reallocation */
  2032. static void isdn_ppp_ccp_reset_free_state(struct ippp_struct *is,
  2033. unsigned char id)
  2034. {
  2035. struct ippp_ccp_reset_state *rs;
  2036. if(is->reset->rs[id]) {
  2037. printk(KERN_DEBUG "ippp_ccp: freeing state for id %d\n", id);
  2038. rs = is->reset->rs[id];
  2039. /* Make sure the kernel will not call back later */
  2040. if(rs->ta)
  2041. del_timer(&rs->timer);
  2042. is->reset->rs[id] = NULL;
  2043. kfree(rs);
  2044. } else {
  2045. printk(KERN_WARNING "ippp_ccp: id %d is not allocated\n", id);
  2046. }
  2047. }
  2048. /* The timer callback function which is called when a ResetReq has timed out,
  2049. aka has never been answered by a ResetAck */
  2050. static void isdn_ppp_ccp_timer_callback(unsigned long closure)
  2051. {
  2052. struct ippp_ccp_reset_state *rs =
  2053. (struct ippp_ccp_reset_state *)closure;
  2054. if(!rs) {
  2055. printk(KERN_ERR "ippp_ccp: timer cb with zero closure.\n");
  2056. return;
  2057. }
  2058. if(rs->ta && rs->state == CCPResetSentReq) {
  2059. /* We are correct here */
  2060. if(!rs->expra) {
  2061. /* Hmm, there is no Ack really expected. We can clean
  2062. up the state now, it will be reallocated if the
  2063. decompressor insists on another reset */
  2064. rs->ta = 0;
  2065. isdn_ppp_ccp_reset_free_state(rs->is, rs->id);
  2066. return;
  2067. }
  2068. printk(KERN_DEBUG "ippp_ccp: CCP Reset timed out for id %d\n",
  2069. rs->id);
  2070. /* Push it again */
  2071. isdn_ppp_ccp_xmit_reset(rs->is, PPP_CCP, CCP_RESETREQ, rs->id,
  2072. rs->data, rs->dlen);
  2073. /* Restart timer */
  2074. rs->timer.expires = jiffies + HZ*5;
  2075. add_timer(&rs->timer);
  2076. } else {
  2077. printk(KERN_WARNING "ippp_ccp: timer cb in wrong state %d\n",
  2078. rs->state);
  2079. }
  2080. }
  2081. /* Allocate a new reset transaction state */
  2082. static struct ippp_ccp_reset_state *isdn_ppp_ccp_reset_alloc_state(struct ippp_struct *is,
  2083. unsigned char id)
  2084. {
  2085. struct ippp_ccp_reset_state *rs;
  2086. if(is->reset->rs[id]) {
  2087. printk(KERN_WARNING "ippp_ccp: old state exists for id %d\n",
  2088. id);
  2089. return NULL;
  2090. } else {
  2091. rs = kzalloc(sizeof(struct ippp_ccp_reset_state), GFP_KERNEL);
  2092. if(!rs)
  2093. return NULL;
  2094. rs->state = CCPResetIdle;
  2095. rs->is = is;
  2096. rs->id = id;
  2097. init_timer(&rs->timer);
  2098. rs->timer.data = (unsigned long)rs;
  2099. rs->timer.function = isdn_ppp_ccp_timer_callback;
  2100. is->reset->rs[id] = rs;
  2101. }
  2102. return rs;
  2103. }
  2104. /* A decompressor wants a reset with a set of parameters - do what is
  2105. necessary to fulfill it */
  2106. static void isdn_ppp_ccp_reset_trans(struct ippp_struct *is,
  2107. struct isdn_ppp_resetparams *rp)
  2108. {
  2109. struct ippp_ccp_reset_state *rs;
  2110. if(rp->valid) {
  2111. /* The decompressor defines parameters by itself */
  2112. if(rp->rsend) {
  2113. /* And he wants us to send a request */
  2114. if(!(rp->idval)) {
  2115. printk(KERN_ERR "ippp_ccp: decompressor must"
  2116. " specify reset id\n");
  2117. return;
  2118. }
  2119. if(is->reset->rs[rp->id]) {
  2120. /* There is already a transaction in existence
  2121. for this id. May be still waiting for a
  2122. Ack or may be wrong. */
  2123. rs = is->reset->rs[rp->id];
  2124. if(rs->state == CCPResetSentReq && rs->ta) {
  2125. printk(KERN_DEBUG "ippp_ccp: reset"
  2126. " trans still in progress"
  2127. " for id %d\n", rp->id);
  2128. } else {
  2129. printk(KERN_WARNING "ippp_ccp: reset"
  2130. " trans in wrong state %d for"
  2131. " id %d\n", rs->state, rp->id);
  2132. }
  2133. } else {
  2134. /* Ok, this is a new transaction */
  2135. printk(KERN_DEBUG "ippp_ccp: new trans for id"
  2136. " %d to be started\n", rp->id);
  2137. rs = isdn_ppp_ccp_reset_alloc_state(is, rp->id);
  2138. if(!rs) {
  2139. printk(KERN_ERR "ippp_ccp: out of mem"
  2140. " allocing ccp trans\n");
  2141. return;
  2142. }
  2143. rs->state = CCPResetSentReq;
  2144. rs->expra = rp->expra;
  2145. if(rp->dtval) {
  2146. rs->dlen = rp->dlen;
  2147. memcpy(rs->data, rp->data, rp->dlen);
  2148. }
  2149. /* HACK TODO - add link comp here */
  2150. isdn_ppp_ccp_xmit_reset(is, PPP_CCP,
  2151. CCP_RESETREQ, rs->id,
  2152. rs->data, rs->dlen);
  2153. /* Start the timer */
  2154. rs->timer.expires = jiffies + 5*HZ;
  2155. add_timer(&rs->timer);
  2156. rs->ta = 1;
  2157. }
  2158. } else {
  2159. printk(KERN_DEBUG "ippp_ccp: no reset sent\n");
  2160. }
  2161. } else {
  2162. /* The reset params are invalid. The decompressor does not
  2163. care about them, so we just send the minimal requests
  2164. and increase ids only when an Ack is received for a
  2165. given id */
  2166. if(is->reset->rs[is->reset->lastid]) {
  2167. /* There is already a transaction in existence
  2168. for this id. May be still waiting for a
  2169. Ack or may be wrong. */
  2170. rs = is->reset->rs[is->reset->lastid];
  2171. if(rs->state == CCPResetSentReq && rs->ta) {
  2172. printk(KERN_DEBUG "ippp_ccp: reset"
  2173. " trans still in progress"
  2174. " for id %d\n", rp->id);
  2175. } else {
  2176. printk(KERN_WARNING "ippp_ccp: reset"
  2177. " trans in wrong state %d for"
  2178. " id %d\n", rs->state, rp->id);
  2179. }
  2180. } else {
  2181. printk(KERN_DEBUG "ippp_ccp: new trans for id"
  2182. " %d to be started\n", is->reset->lastid);
  2183. rs = isdn_ppp_ccp_reset_alloc_state(is,
  2184. is->reset->lastid);
  2185. if(!rs) {
  2186. printk(KERN_ERR "ippp_ccp: out of mem"
  2187. " allocing ccp trans\n");
  2188. return;
  2189. }
  2190. rs->state = CCPResetSentReq;
  2191. /* We always expect an Ack if the decompressor doesn't
  2192. know better */
  2193. rs->expra = 1;
  2194. rs->dlen = 0;
  2195. /* HACK TODO - add link comp here */
  2196. isdn_ppp_ccp_xmit_reset(is, PPP_CCP, CCP_RESETREQ,
  2197. rs->id, NULL, 0);
  2198. /* Start the timer */
  2199. rs->timer.expires = jiffies + 5*HZ;
  2200. add_timer(&rs->timer);
  2201. rs->ta = 1;
  2202. }
  2203. }
  2204. }
  2205. /* An Ack was received for this id. This means we stop the timer and clean
  2206. up the state prior to calling the decompressors reset routine. */
  2207. static void isdn_ppp_ccp_reset_ack_rcvd(struct ippp_struct *is,
  2208. unsigned char id)
  2209. {
  2210. struct ippp_ccp_reset_state *rs = is->reset->rs[id];
  2211. if(rs) {
  2212. if(rs->ta && rs->state == CCPResetSentReq) {
  2213. /* Great, we are correct */
  2214. if(!rs->expra)
  2215. printk(KERN_DEBUG "ippp_ccp: ResetAck received"
  2216. " for id %d but not expected\n", id);
  2217. } else {
  2218. printk(KERN_INFO "ippp_ccp: ResetAck received out of"
  2219. "sync for id %d\n", id);
  2220. }
  2221. if(rs->ta) {
  2222. rs->ta = 0;
  2223. del_timer(&rs->timer);
  2224. }
  2225. isdn_ppp_ccp_reset_free_state(is, id);
  2226. } else {
  2227. printk(KERN_INFO "ippp_ccp: ResetAck received for unknown id"
  2228. " %d\n", id);
  2229. }
  2230. /* Make sure the simple reset stuff uses a new id next time */
  2231. is->reset->lastid++;
  2232. }
  2233. /*
  2234. * decompress packet
  2235. *
  2236. * if master = 0, we're trying to uncompress an per-link compressed packet,
  2237. * as opposed to an compressed reconstructed-from-MPPP packet.
  2238. * proto is updated to protocol field of uncompressed packet.
  2239. *
  2240. * retval: decompressed packet,
  2241. * same packet if uncompressed,
  2242. * NULL if decompression error
  2243. */
  2244. static struct sk_buff *isdn_ppp_decompress(struct sk_buff *skb,struct ippp_struct *is,struct ippp_struct *master,
  2245. int *proto)
  2246. {
  2247. void *stat = NULL;
  2248. struct isdn_ppp_compressor *ipc = NULL;
  2249. struct sk_buff *skb_out;
  2250. int len;
  2251. struct ippp_struct *ri;
  2252. struct isdn_ppp_resetparams rsparm;
  2253. unsigned char rsdata[IPPP_RESET_MAXDATABYTES];
  2254. if(!master) {
  2255. // per-link decompression
  2256. stat = is->link_decomp_stat;
  2257. ipc = is->link_decompressor;
  2258. ri = is;
  2259. } else {
  2260. stat = master->decomp_stat;
  2261. ipc = master->decompressor;
  2262. ri = master;
  2263. }
  2264. if (!ipc) {
  2265. // no decompressor -> we can't decompress.
  2266. printk(KERN_DEBUG "ippp: no decompressor defined!\n");
  2267. return skb;
  2268. }
  2269. BUG_ON(!stat); // if we have a compressor, stat has been set as well
  2270. if((master && *proto == PPP_COMP) || (!master && *proto == PPP_COMPFRAG) ) {
  2271. // compressed packets are compressed by their protocol type
  2272. // Set up reset params for the decompressor
  2273. memset(&rsparm, 0, sizeof(rsparm));
  2274. rsparm.data = rsdata;
  2275. rsparm.maxdlen = IPPP_RESET_MAXDATABYTES;
  2276. skb_out = dev_alloc_skb(is->mru + PPP_HDRLEN);
  2277. if (!skb_out) {
  2278. kfree_skb(skb);
  2279. printk(KERN_ERR "ippp: decomp memory allocation failure\n");
  2280. return NULL;
  2281. }
  2282. len = ipc->decompress(stat, skb, skb_out, &rsparm);
  2283. kfree_skb(skb);
  2284. if (len <= 0) {
  2285. switch(len) {
  2286. case DECOMP_ERROR:
  2287. printk(KERN_INFO "ippp: decomp wants reset %s params\n",
  2288. rsparm.valid ? "with" : "without");
  2289. isdn_ppp_ccp_reset_trans(ri, &rsparm);
  2290. break;
  2291. case DECOMP_FATALERROR:
  2292. ri->pppcfg |= SC_DC_FERROR;
  2293. /* Kick ipppd to recognize the error */
  2294. isdn_ppp_ccp_kickup(ri);
  2295. break;
  2296. }
  2297. kfree_skb(skb_out);
  2298. return NULL;
  2299. }
  2300. *proto = isdn_ppp_strip_proto(skb_out);
  2301. if (*proto < 0) {
  2302. kfree_skb(skb_out);
  2303. return NULL;
  2304. }
  2305. return skb_out;
  2306. } else {
  2307. // uncompressed packets are fed through the decompressor to
  2308. // update the decompressor state
  2309. ipc->incomp(stat, skb, *proto);
  2310. return skb;
  2311. }
  2312. }
  2313. /*
  2314. * compress a frame
  2315. * type=0: normal/bundle compression
  2316. * =1: link compression
  2317. * returns original skb if we haven't compressed the frame
  2318. * and a new skb pointer if we've done it
  2319. */
  2320. static struct sk_buff *isdn_ppp_compress(struct sk_buff *skb_in,int *proto,
  2321. struct ippp_struct *is,struct ippp_struct *master,int type)
  2322. {
  2323. int ret;
  2324. int new_proto;
  2325. struct isdn_ppp_compressor *compressor;
  2326. void *stat;
  2327. struct sk_buff *skb_out;
  2328. /* we do not compress control protocols */
  2329. if(*proto < 0 || *proto > 0x3fff) {
  2330. return skb_in;
  2331. }
  2332. if(type) { /* type=1 => Link compression */
  2333. return skb_in;
  2334. }
  2335. else {
  2336. if(!master) {
  2337. compressor = is->compressor;
  2338. stat = is->comp_stat;
  2339. }
  2340. else {
  2341. compressor = master->compressor;
  2342. stat = master->comp_stat;
  2343. }
  2344. new_proto = PPP_COMP;
  2345. }
  2346. if(!compressor) {
  2347. printk(KERN_ERR "isdn_ppp: No compressor set!\n");
  2348. return skb_in;
  2349. }
  2350. if(!stat) {
  2351. printk(KERN_ERR "isdn_ppp: Compressor not initialized?\n");
  2352. return skb_in;
  2353. }
  2354. /* Allow for at least 150 % expansion (for now) */
  2355. skb_out = alloc_skb(skb_in->len + skb_in->len/2 + 32 +
  2356. skb_headroom(skb_in), GFP_ATOMIC);
  2357. if(!skb_out)
  2358. return skb_in;
  2359. skb_reserve(skb_out, skb_headroom(skb_in));
  2360. ret = (compressor->compress)(stat,skb_in,skb_out,*proto);
  2361. if(!ret) {
  2362. dev_kfree_skb(skb_out);
  2363. return skb_in;
  2364. }
  2365. dev_kfree_skb(skb_in);
  2366. *proto = new_proto;
  2367. return skb_out;
  2368. }
  2369. /*
  2370. * we received a CCP frame ..
  2371. * not a clean solution, but we MUST handle a few cases in the kernel
  2372. */
  2373. static void isdn_ppp_receive_ccp(isdn_net_dev *net_dev, isdn_net_local *lp,
  2374. struct sk_buff *skb,int proto)
  2375. {
  2376. struct ippp_struct *is;
  2377. struct ippp_struct *mis;
  2378. int len;
  2379. struct isdn_ppp_resetparams rsparm;
  2380. unsigned char rsdata[IPPP_RESET_MAXDATABYTES];
  2381. printk(KERN_DEBUG "Received CCP frame from peer slot(%d)\n",
  2382. lp->ppp_slot);
  2383. if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
  2384. printk(KERN_ERR "%s: lp->ppp_slot(%d) out of range\n",
  2385. __func__, lp->ppp_slot);
  2386. return;
  2387. }
  2388. is = ippp_table[lp->ppp_slot];
  2389. isdn_ppp_frame_log("ccp-rcv", skb->data, skb->len, 32, is->unit,lp->ppp_slot);
  2390. if(lp->master) {
  2391. int slot = ((isdn_net_local *) (lp->master->priv))->ppp_slot;
  2392. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  2393. printk(KERN_ERR "%s: slot(%d) out of range\n",
  2394. __func__, slot);
  2395. return;
  2396. }
  2397. mis = ippp_table[slot];
  2398. } else
  2399. mis = is;
  2400. switch(skb->data[0]) {
  2401. case CCP_CONFREQ:
  2402. if(is->debug & 0x10)
  2403. printk(KERN_DEBUG "Disable compression here!\n");
  2404. if(proto == PPP_CCP)
  2405. mis->compflags &= ~SC_COMP_ON;
  2406. else
  2407. is->compflags &= ~SC_LINK_COMP_ON;
  2408. break;
  2409. case CCP_TERMREQ:
  2410. case CCP_TERMACK:
  2411. if(is->debug & 0x10)
  2412. printk(KERN_DEBUG "Disable (de)compression here!\n");
  2413. if(proto == PPP_CCP)
  2414. mis->compflags &= ~(SC_DECOMP_ON|SC_COMP_ON);
  2415. else
  2416. is->compflags &= ~(SC_LINK_DECOMP_ON|SC_LINK_COMP_ON);
  2417. break;
  2418. case CCP_CONFACK:
  2419. /* if we RECEIVE an ackowledge we enable the decompressor */
  2420. if(is->debug & 0x10)
  2421. printk(KERN_DEBUG "Enable decompression here!\n");
  2422. if(proto == PPP_CCP) {
  2423. if (!mis->decompressor)
  2424. break;
  2425. mis->compflags |= SC_DECOMP_ON;
  2426. } else {
  2427. if (!is->decompressor)
  2428. break;
  2429. is->compflags |= SC_LINK_DECOMP_ON;
  2430. }
  2431. break;
  2432. case CCP_RESETACK:
  2433. printk(KERN_DEBUG "Received ResetAck from peer\n");
  2434. len = (skb->data[2] << 8) | skb->data[3];
  2435. len -= 4;
  2436. if(proto == PPP_CCP) {
  2437. /* If a reset Ack was outstanding for this id, then
  2438. clean up the state engine */
  2439. isdn_ppp_ccp_reset_ack_rcvd(mis, skb->data[1]);
  2440. if(mis->decompressor && mis->decomp_stat)
  2441. mis->decompressor->
  2442. reset(mis->decomp_stat,
  2443. skb->data[0],
  2444. skb->data[1],
  2445. len ? &skb->data[4] : NULL,
  2446. len, NULL);
  2447. /* TODO: This is not easy to decide here */
  2448. mis->compflags &= ~SC_DECOMP_DISCARD;
  2449. }
  2450. else {
  2451. isdn_ppp_ccp_reset_ack_rcvd(is, skb->data[1]);
  2452. if(is->link_decompressor && is->link_decomp_stat)
  2453. is->link_decompressor->
  2454. reset(is->link_decomp_stat,
  2455. skb->data[0],
  2456. skb->data[1],
  2457. len ? &skb->data[4] : NULL,
  2458. len, NULL);
  2459. /* TODO: neither here */
  2460. is->compflags &= ~SC_LINK_DECOMP_DISCARD;
  2461. }
  2462. break;
  2463. case CCP_RESETREQ:
  2464. printk(KERN_DEBUG "Received ResetReq from peer\n");
  2465. /* Receiving a ResetReq means we must reset our compressor */
  2466. /* Set up reset params for the reset entry */
  2467. memset(&rsparm, 0, sizeof(rsparm));
  2468. rsparm.data = rsdata;
  2469. rsparm.maxdlen = IPPP_RESET_MAXDATABYTES;
  2470. /* Isolate data length */
  2471. len = (skb->data[2] << 8) | skb->data[3];
  2472. len -= 4;
  2473. if(proto == PPP_CCP) {
  2474. if(mis->compressor && mis->comp_stat)
  2475. mis->compressor->
  2476. reset(mis->comp_stat,
  2477. skb->data[0],
  2478. skb->data[1],
  2479. len ? &skb->data[4] : NULL,
  2480. len, &rsparm);
  2481. }
  2482. else {
  2483. if(is->link_compressor && is->link_comp_stat)
  2484. is->link_compressor->
  2485. reset(is->link_comp_stat,
  2486. skb->data[0],
  2487. skb->data[1],
  2488. len ? &skb->data[4] : NULL,
  2489. len, &rsparm);
  2490. }
  2491. /* Ack the Req as specified by rsparm */
  2492. if(rsparm.valid) {
  2493. /* Compressor reset handler decided how to answer */
  2494. if(rsparm.rsend) {
  2495. /* We should send a Frame */
  2496. isdn_ppp_ccp_xmit_reset(is, proto, CCP_RESETACK,
  2497. rsparm.idval ? rsparm.id
  2498. : skb->data[1],
  2499. rsparm.dtval ?
  2500. rsparm.data : NULL,
  2501. rsparm.dtval ?
  2502. rsparm.dlen : 0);
  2503. } else {
  2504. printk(KERN_DEBUG "ResetAck suppressed\n");
  2505. }
  2506. } else {
  2507. /* We answer with a straight reflected Ack */
  2508. isdn_ppp_ccp_xmit_reset(is, proto, CCP_RESETACK,
  2509. skb->data[1],
  2510. len ? &skb->data[4] : NULL,
  2511. len);
  2512. }
  2513. break;
  2514. }
  2515. }
  2516. /*
  2517. * Daemon sends a CCP frame ...
  2518. */
  2519. /* TODO: Clean this up with new Reset semantics */
  2520. /* I believe the CCP handling as-is is done wrong. Compressed frames
  2521. * should only be sent/received after CCP reaches UP state, which means
  2522. * both sides have sent CONF_ACK. Currently, we handle both directions
  2523. * independently, which means we may accept compressed frames too early
  2524. * (supposedly not a problem), but may also mean we send compressed frames
  2525. * too early, which may turn out to be a problem.
  2526. * This part of state machine should actually be handled by (i)pppd, but
  2527. * that's too big of a change now. --kai
  2528. */
  2529. /* Actually, we might turn this into an advantage: deal with the RFC in
  2530. * the old tradition of beeing generous on what we accept, but beeing
  2531. * strict on what we send. Thus we should just
  2532. * - accept compressed frames as soon as decompression is negotiated
  2533. * - send compressed frames only when decomp *and* comp are negotiated
  2534. * - drop rx compressed frames if we cannot decomp (instead of pushing them
  2535. * up to ipppd)
  2536. * and I tried to modify this file according to that. --abp
  2537. */
  2538. static void isdn_ppp_send_ccp(isdn_net_dev *net_dev, isdn_net_local *lp, struct sk_buff *skb)
  2539. {
  2540. struct ippp_struct *mis,*is;
  2541. int proto, slot = lp->ppp_slot;
  2542. unsigned char *data;
  2543. if(!skb || skb->len < 3)
  2544. return;
  2545. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  2546. printk(KERN_ERR "%s: lp->ppp_slot(%d) out of range\n",
  2547. __func__, slot);
  2548. return;
  2549. }
  2550. is = ippp_table[slot];
  2551. /* Daemon may send with or without address and control field comp */
  2552. data = skb->data;
  2553. if(!(is->pppcfg & SC_COMP_AC) && data[0] == 0xff && data[1] == 0x03) {
  2554. data += 2;
  2555. if(skb->len < 5)
  2556. return;
  2557. }
  2558. proto = ((int)data[0]<<8)+data[1];
  2559. if(proto != PPP_CCP && proto != PPP_CCPFRAG)
  2560. return;
  2561. printk(KERN_DEBUG "Received CCP frame from daemon:\n");
  2562. isdn_ppp_frame_log("ccp-xmit", skb->data, skb->len, 32, is->unit,lp->ppp_slot);
  2563. if (lp->master) {
  2564. slot = ((isdn_net_local *) (lp->master->priv))->ppp_slot;
  2565. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  2566. printk(KERN_ERR "%s: slot(%d) out of range\n",
  2567. __func__, slot);
  2568. return;
  2569. }
  2570. mis = ippp_table[slot];
  2571. } else
  2572. mis = is;
  2573. if (mis != is)
  2574. printk(KERN_DEBUG "isdn_ppp: Ouch! Master CCP sends on slave slot!\n");
  2575. switch(data[2]) {
  2576. case CCP_CONFREQ:
  2577. if(is->debug & 0x10)
  2578. printk(KERN_DEBUG "Disable decompression here!\n");
  2579. if(proto == PPP_CCP)
  2580. is->compflags &= ~SC_DECOMP_ON;
  2581. else
  2582. is->compflags &= ~SC_LINK_DECOMP_ON;
  2583. break;
  2584. case CCP_TERMREQ:
  2585. case CCP_TERMACK:
  2586. if(is->debug & 0x10)
  2587. printk(KERN_DEBUG "Disable (de)compression here!\n");
  2588. if(proto == PPP_CCP)
  2589. is->compflags &= ~(SC_DECOMP_ON|SC_COMP_ON);
  2590. else
  2591. is->compflags &= ~(SC_LINK_DECOMP_ON|SC_LINK_COMP_ON);
  2592. break;
  2593. case CCP_CONFACK:
  2594. /* if we SEND an ackowledge we can/must enable the compressor */
  2595. if(is->debug & 0x10)
  2596. printk(KERN_DEBUG "Enable compression here!\n");
  2597. if(proto == PPP_CCP) {
  2598. if (!is->compressor)
  2599. break;
  2600. is->compflags |= SC_COMP_ON;
  2601. } else {
  2602. if (!is->compressor)
  2603. break;
  2604. is->compflags |= SC_LINK_COMP_ON;
  2605. }
  2606. break;
  2607. case CCP_RESETACK:
  2608. /* If we send a ACK we should reset our compressor */
  2609. if(is->debug & 0x10)
  2610. printk(KERN_DEBUG "Reset decompression state here!\n");
  2611. printk(KERN_DEBUG "ResetAck from daemon passed by\n");
  2612. if(proto == PPP_CCP) {
  2613. /* link to master? */
  2614. if(is->compressor && is->comp_stat)
  2615. is->compressor->reset(is->comp_stat, 0, 0,
  2616. NULL, 0, NULL);
  2617. is->compflags &= ~SC_COMP_DISCARD;
  2618. }
  2619. else {
  2620. if(is->link_compressor && is->link_comp_stat)
  2621. is->link_compressor->reset(is->link_comp_stat,
  2622. 0, 0, NULL, 0, NULL);
  2623. is->compflags &= ~SC_LINK_COMP_DISCARD;
  2624. }
  2625. break;
  2626. case CCP_RESETREQ:
  2627. /* Just let it pass by */
  2628. printk(KERN_DEBUG "ResetReq from daemon passed by\n");
  2629. break;
  2630. }
  2631. }
  2632. int isdn_ppp_register_compressor(struct isdn_ppp_compressor *ipc)
  2633. {
  2634. ipc->next = ipc_head;
  2635. ipc->prev = NULL;
  2636. if(ipc_head) {
  2637. ipc_head->prev = ipc;
  2638. }
  2639. ipc_head = ipc;
  2640. return 0;
  2641. }
  2642. int isdn_ppp_unregister_compressor(struct isdn_ppp_compressor *ipc)
  2643. {
  2644. if(ipc->prev)
  2645. ipc->prev->next = ipc->next;
  2646. else
  2647. ipc_head = ipc->next;
  2648. if(ipc->next)
  2649. ipc->next->prev = ipc->prev;
  2650. ipc->prev = ipc->next = NULL;
  2651. return 0;
  2652. }
  2653. static int isdn_ppp_set_compressor(struct ippp_struct *is, struct isdn_ppp_comp_data *data)
  2654. {
  2655. struct isdn_ppp_compressor *ipc = ipc_head;
  2656. int ret;
  2657. void *stat;
  2658. int num = data->num;
  2659. if(is->debug & 0x10)
  2660. printk(KERN_DEBUG "[%d] Set %s type %d\n",is->unit,
  2661. (data->flags&IPPP_COMP_FLAG_XMIT)?"compressor":"decompressor",num);
  2662. /* If is has no valid reset state vector, we cannot allocate a
  2663. decompressor. The decompressor would cause reset transactions
  2664. sooner or later, and they need that vector. */
  2665. if(!(data->flags & IPPP_COMP_FLAG_XMIT) && !is->reset) {
  2666. printk(KERN_ERR "ippp_ccp: no reset data structure - can't"
  2667. " allow decompression.\n");
  2668. return -ENOMEM;
  2669. }
  2670. while(ipc) {
  2671. if(ipc->num == num) {
  2672. stat = ipc->alloc(data);
  2673. if(stat) {
  2674. ret = ipc->init(stat,data,is->unit,0);
  2675. if(!ret) {
  2676. printk(KERN_ERR "Can't init (de)compression!\n");
  2677. ipc->free(stat);
  2678. stat = NULL;
  2679. break;
  2680. }
  2681. }
  2682. else {
  2683. printk(KERN_ERR "Can't alloc (de)compression!\n");
  2684. break;
  2685. }
  2686. if(data->flags & IPPP_COMP_FLAG_XMIT) {
  2687. if(data->flags & IPPP_COMP_FLAG_LINK) {
  2688. if(is->link_comp_stat)
  2689. is->link_compressor->free(is->link_comp_stat);
  2690. is->link_comp_stat = stat;
  2691. is->link_compressor = ipc;
  2692. }
  2693. else {
  2694. if(is->comp_stat)
  2695. is->compressor->free(is->comp_stat);
  2696. is->comp_stat = stat;
  2697. is->compressor = ipc;
  2698. }
  2699. }
  2700. else {
  2701. if(data->flags & IPPP_COMP_FLAG_LINK) {
  2702. if(is->link_decomp_stat)
  2703. is->link_decompressor->free(is->link_decomp_stat);
  2704. is->link_decomp_stat = stat;
  2705. is->link_decompressor = ipc;
  2706. }
  2707. else {
  2708. if(is->decomp_stat)
  2709. is->decompressor->free(is->decomp_stat);
  2710. is->decomp_stat = stat;
  2711. is->decompressor = ipc;
  2712. }
  2713. }
  2714. return 0;
  2715. }
  2716. ipc = ipc->next;
  2717. }
  2718. return -EINVAL;
  2719. }