OSDN Git Service

9cecad0227f197d14181cd068f12052ddd66720f
[android-x86/external-wireless-tools.git] / wireless_tools / sample_pm_cs.c
1 /* Note : this particular snipset of code is available under
2  * the LGPL, MPL or BSD license (at your choice).
3  * Jean II
4  */
5
6 /* Backward compatibility for Wireless Extension 9 */
7 #ifndef IW_POWER_MODIFIER
8 #define IW_POWER_MODIFIER       0x000F  /* Modify a parameter */
9 #define IW_POWER_MIN            0x0001  /* Value is a minimum  */
10 #define IW_POWER_MAX            0x0002  /* Value is a maximum */
11 #define IW_POWER_RELATIVE       0x0004  /* Value is not in seconds/ms/us */
12 #endif IW_POWER_MODIFIER
13
14 struct net_local {
15   int           pm_on;          // Power Management enabled
16   int           pm_multi;       // Receive multicasts
17   int           pm_period;      // Power Management period
18   int           pm_period_auto; // Power Management auto mode
19   int           pm_max_period;  // Power Management max period
20   int           pm_min_period;  // Power Management min period
21   int           pm_timeout;     // Power Management timeout
22 };
23
24       /* Set the desired Power Management mode */
25     case SIOCSIWPOWER:
26       /* Disable it ? */
27       if(wrq->u.power.disabled)
28         {
29           local->pm_on = 0;
30           local->need_commit = 1;
31         }
32       else
33         {
34           /* Check mode */
35           switch(wrq->u.power.flags & IW_POWER_MODE)
36             {
37             case IW_POWER_UNICAST_R:
38               local->pm_multi = 0;
39               local->need_commit = 1;
40               break;
41             case IW_POWER_ALL_R:
42               local->pm_multi = 1;
43               local->need_commit = 1;
44               break;
45             case IW_POWER_ON:   /* None = ok */
46               break;
47             default:    /* Invalid */
48               rc = -EINVAL;
49             }
50           /* Set period */
51           if(wrq->u.power.flags & IW_POWER_PERIOD)
52             {
53               int       period = wrq->u.power.value/1000000;
54               /* Hum: check if within bounds... */
55
56               /* Activate PM */
57               local->pm_on = 1;
58               local->need_commit = 1;
59
60               /* Check min value */
61               if(wrq->u.power.flags & IW_POWER_MIN)
62                 {
63                   local->pm_min_period = period;
64                   local->pm_period_auto = 1;
65                 }
66               else
67                 /* Check max value */
68                 if(wrq->u.power.flags & IW_POWER_MAX)
69                   {
70                     local->pm_max_period = period;
71                     local->pm_period_auto = 1;
72                   }
73                 else
74                   {
75                     /* Fixed value */
76                     local->pm_period = period;
77                     local->pm_period_auto = 0;
78                   }
79             }
80           /* Set timeout */
81           if(wrq->u.power.flags & IW_POWER_TIMEOUT)
82             {
83               /* Activate PM */
84               local->pm_on = 1;
85               local->need_commit = 1;
86               /* Fixed value in ms */
87               local->pm_timeout = wrq->u.power.value/1000;
88             }
89         }
90       break;
91
92       /* Get the power management settings */
93     case SIOCGIWPOWER:
94       wrq->u.power.disabled = !local->pm_on;
95       /* By default, display the period */
96       if(!(wrq->u.power.flags & IW_POWER_TIMEOUT))
97         {
98           int   inc_flags = wrq->u.power.flags;
99           wrq->u.power.flags = IW_POWER_PERIOD | IW_POWER_RELATIVE;
100           /* Check if auto */
101           if(local->pm_period_auto)
102             {
103               /* By default, the min */
104               if(!(inc_flags & IW_POWER_MAX))
105                 {
106                   wrq->u.power.value = local->pm_min_period * 1000000;
107                   wrq->u.power.flags |= IW_POWER_MIN;
108                 }
109               else
110                 {
111                   wrq->u.power.value = local->pm_max_period * 1000000;
112                   wrq->u.power.flags |= IW_POWER_MAX;
113                 }
114             }
115           else
116             {
117               /* Fixed value. Check the flags */
118               if(inc_flags & (IW_POWER_MIN | IW_POWER_MAX))
119                 rc = -EINVAL;
120               else
121                 wrq->u.power.value = local->pm_period * 1000000;
122             }
123         }
124       else
125         {
126           /* Deal with the timeout - always fixed */
127           wrq->u.power.flags = IW_POWER_TIMEOUT;
128           wrq->u.power.value = local->pm_timeout * 1000;
129         }
130       if(local->pm_multi)
131         wrq->u.power.flags |= IW_POWER_ALL_R;
132       else
133         wrq->u.power.flags |= IW_POWER_UNICAST_R;
134       break;
135 #endif  /* WIRELESS_EXT > 8 */
136
137 #if WIRELESS_EXT > 9
138       range.min_pmp = 1000000;  /* 1 units */
139       range.max_pmp = 12000000; /* 12 units */
140       range.min_pmt = 1000;     /* 1 ms */
141       range.max_pmt = 1000000;  /* 1 s */
142       range.pmp_flags = IW_POWER_PERIOD | IW_POWER_RELATIVE |
143         IW_POWER_MIN | IW_POWER_MAX;
144       range.pmt_flags = IW_POWER_TIMEOUT;
145       range.pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
146 #endif /* WIRELESS_EXT > 9 */