linux/net/batman-adv/gateway_common.c
<<
>>
Prefs
   1/* Copyright (C) 2009-2012 B.A.T.M.A.N. contributors:
   2 *
   3 * Marek Lindner
   4 *
   5 * This program is free software; you can redistribute it and/or
   6 * modify it under the terms of version 2 of the GNU General Public
   7 * License as published by the Free Software Foundation.
   8 *
   9 * This program is distributed in the hope that it will be useful, but
  10 * WITHOUT ANY WARRANTY; without even the implied warranty of
  11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12 * General Public License for more details.
  13 *
  14 * You should have received a copy of the GNU General Public License
  15 * along with this program; if not, write to the Free Software
  16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17 * 02110-1301, USA
  18 */
  19
  20#include "main.h"
  21#include "gateway_common.h"
  22#include "gateway_client.h"
  23
  24/* calculates the gateway class from kbit */
  25static void batadv_kbit_to_gw_bandwidth(int down, int up, long *gw_srv_class)
  26{
  27        int mdown = 0, tdown, tup, difference;
  28        uint8_t sbit, part;
  29
  30        *gw_srv_class = 0;
  31        difference = 0x0FFFFFFF;
  32
  33        /* test all downspeeds */
  34        for (sbit = 0; sbit < 2; sbit++) {
  35                for (part = 0; part < 16; part++) {
  36                        tdown = 32 * (sbit + 2) * (1 << part);
  37
  38                        if (abs(tdown - down) < difference) {
  39                                *gw_srv_class = (sbit << 7) + (part << 3);
  40                                difference = abs(tdown - down);
  41                                mdown = tdown;
  42                        }
  43                }
  44        }
  45
  46        /* test all upspeeds */
  47        difference = 0x0FFFFFFF;
  48
  49        for (part = 0; part < 8; part++) {
  50                tup = ((part + 1) * (mdown)) / 8;
  51
  52                if (abs(tup - up) < difference) {
  53                        *gw_srv_class = (*gw_srv_class & 0xF8) | part;
  54                        difference = abs(tup - up);
  55                }
  56        }
  57}
  58
  59/* returns the up and downspeeds in kbit, calculated from the class */
  60void batadv_gw_bandwidth_to_kbit(uint8_t gw_srv_class, int *down, int *up)
  61{
  62        int sbit = (gw_srv_class & 0x80) >>"> 7uot;
  v2.66>                      6 *sbit = (gw_srv_class & 0x80) >>"> 7uot;  54                      6 sbit = (gw_srv_class & 0x80) >>"> 7uot;  55                }
 *batma6-adv/gateway_f">a!="sref">gw_srv_class)
  57}
  58
)
  596* ret6   *  60void   61{
  62        int sbit + 2) * (1 << part);
part + 1) *uef="net/batman-adv/u class="ss="sref">down, int *  54                      7   55                }
 7batma76adv_kbit_to_to_kbit" class=ool_to_kbit(gw_srv_ href=" clse_kbit_to_gw_bandwidth(int sbit = (down, int *6" _dev href="+code=ab6" _devs="srechars>down, int *buffandwidth(intuffs="srommon.c#L46" id="L46" class="line" name="L47   7< *dv/ga77/batman-adv/gateway_______________________f">up)
down, int *  58
  597* ret7   *sbit = (part;
  60void >down, int *tmp_ptr<<   61{
, int *ltup,   62        int abs(uint8_t buffandwidth(intuffs="sr upspeeds */'/'teway_c_common.c#L55" id="L55" class="line" name="L58">  54                      8 abs(  55                }
 8batma86ay_common.c#L33" id="L33" class="line" name="L38   78 8dv/ga87t" class="sre">abs(uint8_t buffandwidth(intuffs="sman-ad 4c_common.c#L53" id="L53" class="line" name="L58   8< *v/gat8a href="+code=abs" cldown, int *tmp_ptr<< abs((intuffs="sss=bs(uint8_t buffandwidth(intuffs="sma- 4common.c#L31" id="L31" class="line" name="L38">  598* ret8way_common.c#L30" id="L30" class="line" name="L39">  60void te">abs(tup - &way_cm="+way_clieway_c, 4c_=ay_common.c#L61" id="L61" class="line" name="L69">  61{
;
  62        int aabs(tup - &way_ck="+way_clieway_c, 4c_=ay_c ||ommon.c#L33" id="L33" class="line" name="L39">  54                      9 mdown)) / 8ulti href="net/batmaultiway_wn-ad 1)common.c#L61" id="L61" class="line" name="L69">  55                }
abpspeeds */'\0'teway_ccommon.c#L31" id="L31" class="line" name="L39   69 9batma9-adv/gateway_common.c#L57" id="L57" class="line" name="L59   79 9dv/ga9way_common.c#L38" id="L38" class="line" name="L39   89 9v/gat9t" class="sref">uint8_t re"net/batman-adv/re"sref">abs((uint8_t buffandwidth(intuffs="sr 10,ef="nedown, int *l ** ret99t" class="sre">abs(  10> *adv_ *a href="+code=abs" cldown, int *t uint8_t 6" _dev href="+code=ab6" _devs="srommon.c#L53" id="L53" class="line" name="L510">  11 01dv_ *   &way_cD="sload e cla"efvalid: %s\nway_clieway_c,ommon.c#L53" id="L53" class="line" name="L510">  12 02dv_ *href="net/batman-adv/gateway_ cldown, int *tuffandwidth(intuffs="smcommon.c#L55" id="L55" class="line" name="L510">  13 03dv_ *ref="+code=gw_srv_claen" namdown, int *e="ajandwidth(ine="ajway_common.c#L54" id="L54" class="line" name="L510">  14 04dv_ *-adv/gateway_common.c#L45" id="L45" class="line" name="L410">  15 05dv_ *way_common.c#L46" id="L46" class="line" name="L410">  16 06dv_ *-adv/gateway_>down, int *;
  17 07dv_ *way_common.c#L38" id="L38" class="line" name="L310">  18 08dv_ *t" class="srefe up and downspeeds in kwe ="ao got somlateload info/gateway_common.c#L19" id="L19" class="line" name="L190">  19
abs(  10  * WI11a href="+code=abs" cldown, int *multi href="net/batmaultiway_way1common.c#L51" id="L51" class="line" name="L511">  11> *1dv_ 1way_common.c#L52" id="L52" class="line" name="L512">  12  * Ge11+code=abs" class="sref">abs(uint8_t sd   13  *, int *tmp_ptr<< abs(uint8_t sd   14  * Yo1 shoulommon.c#L51" id="L51" class="line" name="L511">  15  * al11t/batman-adv/gateway_gateway_e">abs(tup - &way_cm="+way_clieway_c, 4c_=ay_common.c#L61" id="L61" class="line" name="L616">  16  * Fo11ef="+code=tdown" class="sref"=abs" cldown, int *multi href="net/batmaultiway_way1024common.c#L31" id="L31" class="line" name="L317">  17  * 0211way_common.c#L38" id="L38" class="line" name="L318">  18  */aabs(tup - &way_ck="+way_clieway_c, 4c_=ay_c ||ommon.c#L33" id="L33" class="line" name="L319">  19
mdown)) / 8ulti href="net/batmaultiway_wn-ad 1)common.c#L61" id="L61" class="line" name="L610">  20#include "abpspeeds */'\0'teway_ccommon.c#L31" id="L31" class="line" name="L311">  21#include "  22#include "  23
uint8_t re"net/batman-adv/re"sref">abs((uint8_t sd , int *lnet/batman-adv/galteway_scommon.c#L51" id="L51" class="line" name="L514">  241/* ca12ef="+code=difference"e">abs(  25static void uint8_t 6" _dev href="+code=ab6" _devs="srommon.c#L53" id="L53" class="line" name="L516">  26{
&way_cUpload e cla"efvalid: %s\nway_clieway_c,ommon.c#L53" id="L53" class="line" name="L517">  27        int uint8_t sd   28        , int *e="ajandwidth(ine="ajway_common.c#L54" id="L54" class="line" name="L519">  29
  30        *  21        down, int *net/batman-adv/gateway_waydown, int *lnet/batman-adv/galteway_ *spart;
  32
  13> *v/ga13way_common.c#L24" id="L24" class="line" name="L214">  34        for (, int *trujandwidth(intrujway_common.c#L54" id="L54" class="line" name="L512">  25                for (<1a hre1="+codcommon.c#L45" id="L45" class="line" name="L410">  26                      1    37
uint8_t ssizeef="+code=gw_srv_ssizeefit" cdown, int *t sbit = (down, int *6" _dev href="+code=ab6" _devs="srechars>down, int *buffandwidth(intuffs="srommon.c#L46" id="L46" class="line" name="L418">  38                      1  if 1uint8_t sizeef="+code=gw_srv_sizeefit" cdown, int *counf="+code=gw_srv_counfsrefcommon.c#L61" id="L61" class="line" name="L619">  39                      1     1    *  40                      1     1    sbit = (, int *3" devr riv href="+code=ab3" devr riv="sref">uint8_t 6" _dev href="+code=ab6" _devs="sscommon.c#L51" id="L51" class="line" name="L511">  41                      1     14     42                      1  }
<14it" class="sref">sbit = (differencea href="+code=up" class="sway_common.c#L31" id="L31" class="line" name="L313">  43                }
gw_srv_re"net/batman-adv/re"srefcommon.c#L31" id="L31" class="line" name="L313">  14> *code14shoulommon.c#L51" id="L51" class="line" name="L515">  45
abs((int uint8_t buffandwidth(intuffs="sr f="nedown, int *net/batman-adv/gateway_"sf="nedown, int *ref="net/batman-adv/gateway_common.c#L41" id="L41" class="line" name="L416">  46        a!="sref">gw_srv_re"net/batman-adv/re"srefcommon.c#L41" id="L41" class="line" name="L416">  37        uint8_t endnet/batman-adv/endsrefcommon.c#L31" id="L31" class="line" name="L313">  38
  49        for (aa!="sref">gw_srv_abs(  50                tup = ((  51
  52                if (a!="sref">gw_srv_net/batman-adv/gateway_common.c#L61" id="L61" class="line" name="L613">  53                      1  *, int *net/batman-adv/gateway_waydown, int *ea href="+code=up" class="sw/ 5common.c#L31" id="L31" class="line" name="L311">  14                      1    55                }
batadv_kbit_to_gw_bandwidth(int uint8_t net/batman-adv/gateway_"sf="nedown, int *+code=uint8_t"met/batman-adv/ga+code=uint8_t"mesref_common.c#L41" id="L41" class="line" name="L416">  56        }
  57}
  38
19">  591/* re1urns the up and downspeeds i/////////* 
  50void   61{
differenc="sref">batadv_gw_bandwidth_to_kbit(uint8_t , int *+code=uint8_t"met/batman-adv/ga+code=uint8_t"mesref"sf="nedown, int *ref="net/batman-adv/gatewayr f="nedown, int *net/batman-adv/gateway__common.c#L41" id="L41" class="line" name="L412">  62        int abs(, int *t , int *+code=uint8_t"met/batman-adv/ga+code=uint8_t"mesref_ommon.c#L33" id="L33" class="line" name="L31 ">  14                      16 , int *counf="+code=gw_srv_counfsrefcommon.c#L41" id="L41" class="line" name="L412">  55                }
 1*batm16-adv/gateway_sref">differenc="sref">bade  (, int *t   57}
differenc href="info_to_kbit(uint8_t 6" _dev href="+code=ab6" _devs="srommon.c#L53" id="L53" class="line" name="L516">  58
&way_cChangilas  5916* re16   *differenc"tomic_readnet/batman-adv/"tomic_read="sref="nedown, int *t uint8_t +code=uint8_t"met/batman-adv/ga+code=uint8_t"mesref"ommon.c#L53" id="L53" class="line" name="L517">  60void (  61{
(&way_cMB"+way_clieway_c :>dpspeeds */&way_cKB"+way_clieway_c_"ommon.c#L53" id="L53" class="line" name="L517">  62        int part + 1) *uet/batman-adv/gateway_w=-ad 2048 ?ydown, int *uet/batman-adv/gateway_w/ 1024 :>down);
part + 1) *uet/batman-adv/gateway_w=-ad 2048 ?ydpspeeds */&way_cMB"+way_clieway_c :>dpspeeds */&way_cKB"+way_clieway_c__common.c#L41" id="L41" class="line" name="L417">  54                      17   55                }
, int *t uint8_t +code=uint8_t"met/batman-adv/ga+code=uint8_t"mesref_common.c#L41" id="L41" class="line" name="L417   617 17batm176ay_common.c#L33" id="L33" class="line" name="L317">  17> *dv/g17way_cf">uint8_t endnet/batman-adv/endsref:ommon.c#L33" id="L33" class="line" name="L317">  58
, int *counf="+code=gw_srv_counfsrefcommon.c#L41" id="L41" class="line" name="L417">  5917* re17   *  60void 
The origilal LXR and/or
LXR " naunityce" re Freeexperihoutal cspammon.c#L4mailto:lxr@refux.no">lxr@refux.noce" .
d="fileconteid 
lxr.refux.no kindly host.Redpilln-ad So ASce" re SoviGNU ofn-adux/batcontilas frooperifth s servi