isdn_ppp.c 79 KB

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