isdn_ppp.c 78 KB

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