Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.93 KB | None | 0 0
  1. diff --git a/plugins/nokia-gpio.c b/plugins/nokia-gpio.c
  2. index f3b9460..88f4d32 100644
  3. --- a/plugins/nokia-gpio.c
  4. +++ b/plugins/nokia-gpio.c
  5. @@ -33,12 +33,8 @@
  6.  #include <sys/types.h>
  7.  #include <sys/stat.h>
  8.  
  9. -#include <gisi/netlink.h>
  10.  #include <glib.h>
  11.  
  12. -#include <ofono/log.h>
  13. -
  14. -#include <drivers/isimodem/debug.h>
  15.  #include "nokia-gpio.h"
  16.  
  17.  #define GPIO_SWITCH    "/sys/devices/platform/gpio-switch"
  18. @@ -73,7 +69,6 @@ enum power_event {
  19.  };
  20.  
  21.  struct gpio_data {
  22. -   GPhonetNetlink *link;
  23.     gpio_finished_cb_t callback;
  24.     void *data;
  25.  
  26. @@ -337,9 +332,6 @@ static void gpio_power_state_machine(enum power_event event)
  27.     case POWER_EVENT_ON:
  28.         self.target = PHONET_LINK_UP;
  29.  
  30. -       if (self.current == PHONET_LINK_NONE)
  31. -           return;
  32. -
  33.         switch (self.state) {
  34.         case POWER_STATE_ON_STARTED:
  35.         case POWER_STATE_ON_RESET:
  36. @@ -596,15 +588,11 @@ static void gpio_power_set_state(enum power_state new_state)
  37.         self.timeout_source = g_timeout_add(timeout,
  38.                     gpio_power_timer_cb, NULL);
  39.     }
  40. -
  41. -   self.callback(new_state, self.data);
  42.  }
  43.  
  44. -static void phonet_status_cb(GIsiModem *idx, GPhonetLinkState state,
  45. -               char const *ifname, void *dummy)
  46. +static void phonet_status_cb(GPhonetLinkState state)
  47.  {
  48. -   DBG("Link %s (%u) is %s",
  49. -       ifname, g_isi_modem_index(idx),
  50. +   DBG("Link is %s",
  51.         state == PN_LINK_REMOVED ? "removed" :
  52.         state == PN_LINK_DOWN ? "down" : "up");
  53.  
  54. @@ -705,25 +693,10 @@ static int gpio_probe_links(void)
  55.  }
  56.  
  57.  
  58. -int gpio_probe(GIsiModem *idx, unsigned addr, gpio_finished_cb_t cb, void *data)
  59. +int gpio_probe()
  60.  {
  61.     int error;
  62.  
  63. -   if (!cb) {
  64. -       DBG("gpio: No callback given");
  65. -       return -(errno = EFAULT);
  66. -   }
  67. -
  68. -   if (self.callback) {
  69. -       DBG("gpio: %s", strerror(EBUSY));
  70. -       return -(errno = EBUSY);
  71. -   }
  72. -
  73. -   if (g_pn_netlink_by_modem(idx)) {
  74. -       DBG("Phonet link %p: %s", idx, strerror(EBUSY));
  75. -       return -(errno = EBUSY);
  76. -   }
  77. -
  78.     self.target = PHONET_LINK_NONE;
  79.     self.have_gpio_switch = file_exists(GPIO_SWITCH);
  80.  
  81. @@ -753,32 +726,11 @@ int gpio_probe(GIsiModem *idx, unsigned addr, gpio_finished_cb_t cb, void *data)
  82.     else
  83.         self.rapu = RAPU_TYPE_2;
  84.  
  85. -   self.link = g_pn_netlink_start(idx, phonet_status_cb, NULL);
  86. -   if (!self.link) {
  87. -       memset(&self, 0, sizeof self);
  88. -       return -errno;
  89. -   }
  90. -
  91. -   self.callback = cb;
  92. -   self.data = data;
  93. -
  94. -   if (addr) {
  95. -       error = g_pn_netlink_set_address(idx, addr);
  96. -       if (error && error != -EEXIST)
  97. -           DBG("g_pn_netlink_set_address: %s", strerror(-error));
  98. -   }
  99. -
  100.     return 0;
  101.  }
  102.  
  103. -int gpio_remove(void *data)
  104. +int gpio_remove()
  105.  {
  106. -   if (self.data != data)
  107. -       return -EINVAL;
  108. -
  109. -   if (self.link)
  110. -       g_pn_netlink_stop(self.link);
  111. -
  112.     if (self.timeout_source) {
  113.         g_source_remove(self.timeout_source);
  114.         self.timeout_source = 0;
  115. @@ -789,11 +741,8 @@ int gpio_remove(void *data)
  116.     return 0;
  117.  }
  118.  
  119. -int gpio_enable(void *data)
  120. +int gpio_enable()
  121.  {
  122. -   if (self.data != data)
  123. -       return -EINVAL;
  124. -
  125.     if (self.state == POWER_STATE_ON)
  126.         return 0;
  127.  
  128. @@ -802,10 +751,8 @@ int gpio_enable(void *data)
  129.     return -EINPROGRESS;
  130.  }
  131.  
  132. -int gpio_disable(void *data)
  133. +int gpio_disable()
  134.  {
  135. -   if (self.data != data)
  136. -       return -EINVAL;
  137.  
  138.     if (self.state == POWER_STATE_OFF
  139.             || self.state == POWER_STATE_ON_FAILED)
  140. @@ -815,3 +762,33 @@ int gpio_disable(void *data)
  141.  
  142.     return -EINPROGRESS;
  143.  }
  144. +
  145. +
  146. +void help(int argc, char **argv) {
  147. +   printf("Usage: %s [--enable|--disable]\n", argv[0]);
  148. +}
  149. +
  150. +int main(int argc, char **argv) {
  151. +   if(argc < 2) {
  152. +       help(argc, argv);
  153. +       return 1;
  154. +   }
  155. +
  156. +   if(getuid() != 0) {
  157. +       printf("You are not root!\n");
  158. +       return 1;
  159. +   }
  160. +
  161. +   if(strcmp(argv[1], "--enable") == 0) {
  162. +       gpio_probe();
  163. +       gpio_enable();
  164. +   } else if(strcmp(argv[1], "--disable") == 0) {
  165. +       gpio_disable();
  166. +       gpio_remove();
  167. +   } else {
  168. +       help(argc, argv);
  169. +       return 1;
  170. +   }
  171. +
  172. +   return 0;
  173. +}
  174. diff --git a/plugins/nokia-gpio.h b/plugins/nokia-gpio.h
  175. index b653bb8..7c03e15 100644
  176. --- a/plugins/nokia-gpio.h
  177. +++ b/plugins/nokia-gpio.h
  178. @@ -19,6 +19,25 @@
  179.   *
  180.   */
  181.  
  182. +/**
  183. + * DBG:
  184. + * @fmt: format string
  185. + * @arg...: list of arguments
  186. + *
  187. + * Simple macro around ofono_debug() which also include the function
  188. + * name it is called in.
  189. + */
  190. +extern void ofono_debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
  191. +
  192. +#define DBG(fmt, args...) g_debug(fmt, ##args)
  193. +
  194. +
  195. +typedef enum {
  196. +        PN_LINK_REMOVED,
  197. +        PN_LINK_DOWN,
  198. +        PN_LINK_UP
  199. +} GPhonetLinkState;
  200. +
  201.  enum power_state {
  202.     POWER_STATE_NONE,
  203.     POWER_STATE_ON_STARTED,
  204. @@ -32,9 +51,9 @@ enum power_state {
  205.  
  206.  typedef void (*gpio_finished_cb_t)(enum power_state value, void *opaque);
  207.  
  208. -int gpio_probe(GIsiModem *idx, unsigned addr, gpio_finished_cb_t cb, void *data);
  209. -int gpio_enable(void *opaque);
  210. -int gpio_disable(void *opaque);
  211. -int gpio_remove(void *opaque);
  212. +int gpio_probe();
  213. +int gpio_enable();
  214. +int gpio_disable();
  215. +int gpio_remove();
  216.  
  217.  char const *gpio_power_state_name(enum power_state value);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement