connector.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * connector.h
  3. *
  4. * 2004-2005 Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru>
  5. * All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef __CONNECTOR_H
  22. #define __CONNECTOR_H
  23. #include <linux/types.h>
  24. #define CN_IDX_CONNECTOR 0xffffffff
  25. #define CN_VAL_CONNECTOR 0xffffffff
  26. /*
  27. * Process Events connector unique ids -- used for message routing
  28. */
  29. #define CN_IDX_PROC 0x1
  30. #define CN_VAL_PROC 0x1
  31. #define CN_IDX_CIFS 0x2
  32. #define CN_VAL_CIFS 0x1
  33. #define CN_W1_IDX 0x3 /* w1 communication */
  34. #define CN_W1_VAL 0x1
  35. #define CN_IDX_V86D 0x4
  36. #define CN_VAL_V86D_UVESAFB 0x1
  37. #define CN_IDX_BB 0x5 /* BlackBoard, from the TSP GPL sampling framework */
  38. #define CN_DST_IDX 0x6
  39. #define CN_DST_VAL 0x1
  40. #define CN_IDX_DM 0x7 /* Device Mapper */
  41. #define CN_VAL_DM_USERSPACE_LOG 0x1
  42. #define CN_NETLINK_USERS 8
  43. /*
  44. * Maximum connector's message size.
  45. */
  46. #define CONNECTOR_MAX_MSG_SIZE 16384
  47. /*
  48. * idx and val are unique identifiers which
  49. * are used for message routing and
  50. * must be registered in connector.h for in-kernel usage.
  51. */
  52. struct cb_id {
  53. __u32 idx;
  54. __u32 val;
  55. };
  56. struct cn_msg {
  57. struct cb_id id;
  58. __u32 seq;
  59. __u32 ack;
  60. __u16 len; /* Length of the following data */
  61. __u16 flags;
  62. __u8 data[0];
  63. };
  64. /*
  65. * Notify structure - requests notification about
  66. * registering/unregistering idx/val in range [first, first+range].
  67. */
  68. struct cn_notify_req {
  69. __u32 first;
  70. __u32 range;
  71. };
  72. /*
  73. * Main notification control message
  74. * *_notify_num - number of appropriate cn_notify_req structures after
  75. * this struct.
  76. * group - notification receiver's idx.
  77. * len - total length of the attached data.
  78. */
  79. struct cn_ctl_msg {
  80. __u32 idx_notify_num;
  81. __u32 val_notify_num;
  82. __u32 group;
  83. __u32 len;
  84. __u8 data[0];
  85. };
  86. #ifdef __KERNEL__
  87. #include <asm/atomic.h>
  88. #include <linux/list.h>
  89. #include <linux/workqueue.h>
  90. #include <net/sock.h>
  91. #define CN_CBQ_NAMELEN 32
  92. struct cn_queue_dev {
  93. atomic_t refcnt;
  94. unsigned char name[CN_CBQ_NAMELEN];
  95. struct workqueue_struct *cn_queue;
  96. /* Sent to kevent to create cn_queue only when needed */
  97. struct work_struct wq_creation;
  98. /* Tell if the wq_creation job is pending/completed */
  99. atomic_t wq_requested;
  100. /* Wait for cn_queue to be created */
  101. wait_queue_head_t wq_created;
  102. struct list_head queue_list;
  103. spinlock_t queue_lock;
  104. struct sock *nls;
  105. };
  106. struct cn_callback_id {
  107. unsigned char name[CN_CBQ_NAMELEN];
  108. struct cb_id id;
  109. };
  110. struct cn_callback_data {
  111. void (*destruct_data) (void *);
  112. void *ddata;
  113. void *callback_priv;
  114. void (*callback) (struct cn_msg *);
  115. void *free;
  116. };
  117. struct cn_callback_entry {
  118. struct list_head callback_entry;
  119. struct work_struct work;
  120. struct cn_queue_dev *pdev;
  121. struct cn_callback_id id;
  122. struct cn_callback_data data;
  123. u32 seq, group;
  124. };
  125. struct cn_ctl_entry {
  126. struct list_head notify_entry;
  127. struct cn_ctl_msg *msg;
  128. };
  129. struct cn_dev {
  130. struct cb_id id;
  131. u32 seq, groups;
  132. struct sock *nls;
  133. void (*input) (struct sk_buff *skb);
  134. struct cn_queue_dev *cbdev;
  135. };
  136. int cn_add_callback(struct cb_id *, char *, void (*callback) (struct cn_msg *));
  137. void cn_del_callback(struct cb_id *);
  138. int cn_netlink_send(struct cn_msg *, u32, gfp_t);
  139. int cn_queue_add_callback(struct cn_queue_dev *dev, char *name, struct cb_id *id, void (*callback)(struct cn_msg *));
  140. void cn_queue_del_callback(struct cn_queue_dev *dev, struct cb_id *id);
  141. int queue_cn_work(struct cn_callback_entry *cbq, struct work_struct *work);
  142. struct cn_queue_dev *cn_queue_alloc_dev(char *name, struct sock *);
  143. void cn_queue_free_dev(struct cn_queue_dev *dev);
  144. int cn_cb_equal(struct cb_id *, struct cb_id *);
  145. void cn_queue_wrapper(struct work_struct *work);
  146. #endif /* __KERNEL__ */
  147. #endif /* __CONNECTOR_H */