libsangoma  1
libsangoma_config.c
Go to the documentation of this file.
1 /*******************************************************************************/
33 #include "libsangoma-pvt.h"
34 #include "libsangoma.h"
35 
36 #ifndef LIBSANGOMA_LIGHT
37 
38 /************************************************************/
42 int sangoma_port_mgmnt_ioctl(sng_fd_t fd, port_management_struct_t *port_management)
43 {
44  int err = 0;
45 #if defined(__WINDOWS__)
46  DWORD ln;
47  if(DeviceIoControl(
48  fd,
49  IoctlPortManagementCommand,
50  (LPVOID)port_management,
51  sizeof(port_management_struct_t),
52  (LPVOID)port_management,
53  sizeof(port_management_struct_t),
54  (LPDWORD)(&ln),
55  (LPOVERLAPPED)NULL
56  ) == FALSE){
57  /* Call OS specific code to find cause of the error and check messages log. */
58  DBG_ERR("%s():Error: IoctlPortManagementCommand failed!!\n", __FUNCTION__);
59  err = -1;
60  }
61 #else
62  err=ioctl(fd,WANPIPE_IOCTL_PORT_MGMT,port_management);
63  if (err) {
64  err = -1;
65  }
66 #endif
67  if(err){
68  port_management->operation_status = SANG_STATUS_INVALID_DEVICE;
69  }
70 
71  return err;
72 }
73 
74 int sangoma_port_cfg_ioctl(sng_fd_t fd, port_cfg_t *port_cfg)
75 {
76  int err = 0;
77 #if defined(__WINDOWS__)
78  DWORD ln;
79  if(DeviceIoControl(
80  fd,
81  IoctlPortConfigurationCommand,
82  (LPVOID)port_cfg,
83  sizeof(port_cfg_t),
84  (LPVOID)port_cfg,
85  sizeof(port_cfg_t),
86  (LPDWORD)(&ln),
87  (LPOVERLAPPED)NULL
88  ) == FALSE){
89  /* Call OS specific code to find cause of the error and check messages log. */
90  DBG_ERR("%s():Error: IoctlPortConfigurationCommand failed!!\n", __FUNCTION__);
91  err = -1;
92  }
93 #else
94  err=ioctl(fd,WANPIPE_IOCTL_PORT_CONFIG,port_cfg);
95  if (err) {
96  err = -1;
97  }
98 #endif
99  if(err){
100  port_cfg->operation_status = SANG_STATUS_INVALID_DEVICE;
101  }
102 
103  return err;
104 }
105 
106 /* open wanpipe configuration device */
108 {
109  char tmp_fname[FNAME_LEN];
110 
111 #if defined(__WINDOWS__)
112  /* Form the Config Device Name (i.e. wanpipe1, wanpipe2,...). */
113  _snprintf(tmp_fname, DEV_NAME_LEN, WP_PORT_NAME_FORM, port_no);
114 #else
115  /* Form the Config Device Name. ("/dev/wanpipe") */
116  _snprintf(tmp_fname, DEV_NAME_LEN, WP_CONFIG_DEV_NAME);
117 #endif
118  return sangoma_open_dev_by_name(tmp_fname);
119 }
120 
121 
123 {
124  int err=0;
125 #if defined(__WINDOWS__)
126  if(UdpManagementCommand(fd, wan_udp)){
127  err = 1;
128  }
129 #else
130  unsigned char id = 0;
131 
132  wan_udp->wan_udphdr_request_reply = 0x01;
133  wan_udp->wan_udphdr_id = id;
134  wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
135 
136  err=ioctl(fd,WANPIPE_IOCTL_PIPEMON,wan_udp);
137  if (err < 0) {
138  err = 1;
139  }
140 #endif
141  if(err){
142  /* The ioctl failed. */
143  return err;
144  }
145 
146  /* The ioctl was successfull. The caller must check
147  * value of wan_udp->wan_udphdr_return_code. */
148  return 0;
149 }
150 
151 int _LIBSNG_CALL sangoma_driver_port_start(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no)
152 {
153  int err;
154  port_mgmnt->operation_status = SANG_STATUS_GENERAL_ERROR;
155  port_mgmnt->command_code = START_PORT_VOLATILE_CONFIG;
156  port_mgmnt->port_no = port_no;
157 
158  err = sangoma_port_mgmnt_ioctl(fd, port_mgmnt);
159  if (err) {
160  /* ioctl failed */
161  return err;
162  }
163 
164  return port_mgmnt->operation_status;
165 }
166 
167 int _LIBSNG_CALL sangoma_driver_port_stop(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no)
168 {
169  int err;
170  port_mgmnt->operation_status = SANG_STATUS_GENERAL_ERROR;
171  port_mgmnt->command_code = STOP_PORT;
172  port_mgmnt->port_no = port_no;
173 
174  err = sangoma_port_mgmnt_ioctl(fd, port_mgmnt);
175  if (err) {
176  /* ioctl failed */
177  return err;
178  }
179 
180  switch(port_mgmnt->operation_status)
181  {
183  /* This is not an error, rather a state indication.
184  * Return SANG_STATUS_SUCCESS, but real return code will be available
185  * for the caller at port_mgmnt->operation_status. */
186  err = SANG_STATUS_SUCCESS;
187  break;
188  default:
189  err = port_mgmnt->operation_status;
190  break;
191  }
192 
193  return err;
194 }
195 
196 int _LIBSNG_CALL sangoma_driver_get_hw_info(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no)
197 {
198  int err;
199  port_mgmnt->operation_status = SANG_STATUS_GENERAL_ERROR;
200  port_mgmnt->command_code = GET_HARDWARE_INFO;
201  port_mgmnt->port_no = port_no;
202 
203  err = sangoma_port_mgmnt_ioctl(fd, port_mgmnt);
204  if (err) {
205  return err;
206  }
207 
208  return port_mgmnt->operation_status;
209 }
210 
211 int _LIBSNG_CALL sangoma_driver_get_version(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no)
212 {
213  int err;
214  port_mgmnt->command_code = GET_DRIVER_VERSION;
215  port_mgmnt->port_no = port_no;
216 
217  err = sangoma_port_mgmnt_ioctl(fd, port_mgmnt);
218  if (err) {
219  return err;
220  }
221 
222  return port_mgmnt->operation_status;
223 }
224 
225 #ifdef WP_API_FEATURE_HARDWARE_RESCAN
226 int _LIBSNG_CALL sangoma_driver_hw_rescan(sng_fd_t fd, port_management_struct_t *port_mgmnt, int *cnt)
227 {
228  int err;
229  port_mgmnt->command_code = WANPIPE_HARDWARE_RESCAN;
230  port_mgmnt->port_no = 1;
231 
232  err = sangoma_port_mgmnt_ioctl(fd, port_mgmnt);
233  if (err < 0) {
234  return err;
235  }
236 
237  *cnt=port_mgmnt->port_no;
238 
239  return port_mgmnt->operation_status;
240 }
241 #endif
242 
243 
244 int _LIBSNG_CALL sangoma_driver_port_set_config(sng_fd_t fd, port_cfg_t *port_cfg, unsigned short port_no)
245 {
246  port_cfg->operation_status = SANG_STATUS_GENERAL_ERROR;
247  port_cfg->command_code = SET_PORT_VOLATILE_CONFIG;
248  port_cfg->port_no = port_no;
249 
250  return sangoma_port_cfg_ioctl(fd, port_cfg);
251 }
252 
253 int _LIBSNG_CALL sangoma_driver_port_get_config(sng_fd_t fd, port_cfg_t *port_cfg, unsigned short port_no)
254 {
255  port_cfg->operation_status = SANG_STATUS_GENERAL_ERROR;
256  port_cfg->command_code = GET_PORT_VOLATILE_CONFIG;
257  port_cfg->port_no = port_no;
258  return sangoma_port_cfg_ioctl(fd, port_cfg);
259 }
260 
261 int _LIBSNG_CALL sangoma_write_port_config_on_persistent_storage(hardware_info_t *hardware_info, port_cfg_t *port_cfg, unsigned short port_no)
262 {
263  int err = 0;
264 #if defined(__WINDOWS__)
265  HKEY hPortRegistryKey = registry_open_port_key(hardware_info);
266 /* wandev_conf_t *wandev_conf = &port_cfg->wandev_conf;
267  sdla_fe_cfg_t *sdla_fe_cfg = &wandev_conf->fe_cfg;*/
268  unsigned int ind;
269 
270  if(hPortRegistryKey == INVALID_HANDLE_VALUE){
271  return 1;
272  }
273 
274  /* write T1/E1/BRI/Analog configuration */
275  if(registry_write_front_end_cfg(hPortRegistryKey, port_cfg)){
276  return 2;
277  }
278 
279  /* write TDM Voice configuration */
280  if(registry_write_wan_tdmv_conf(hPortRegistryKey, port_cfg)){
281  return 3;
282  }
283 
284  /* write number of groups */
285  err = registry_set_integer_value(hPortRegistryKey, "aft_number_of_logic_channels", port_cfg->num_of_ifs);
286  if(err){
287  return err;
288  }
289 
290  /* write configuration of each group */
291  for(ind = 0; ind < port_cfg->num_of_ifs; ind++){
292  registry_write_channel_group_cfg(hPortRegistryKey, port_cfg, ind, port_cfg->if_cfg[ind]);
293  }
294 
295 #else
296  printf("%s(): Warning: function not implemented\n", __FUNCTION__);
297  err = 1;
298 #endif
299  return err;
300 }
301 
302 
303 
304 
305 #endif /* #ifndef LIBSANGOMA_LIGHT */
int _LIBSNG_CALL sangoma_driver_port_set_config(sng_fd_t fd, port_cfg_t *port_cfg, unsigned short port_no)
Set Port&#39;s &quot;Volatile&quot; configuration. The configuration will not persist between system restarts...
#define INVALID_HANDLE_VALUE
Invalid file handle value -1, Ported from Windows.
Definition: libsangoma.h:191
Wanpipe API Library header for Sangoma AFT T1/E1/Analog/BRI/Serial Hardware -.
#define FALSE
FALSE value is 0, Ported from Windows.
Definition: libsangoma.h:244
#define _snprintf
_snprintf type mapped to snprintf, Ported from Windows
Definition: libsangoma.h:255
int _LIBSNG_CALL sangoma_mgmt_cmd(sng_fd_t fd, wan_udp_hdr_t *wan_udp)
Execute Sangoma Management Command.
sng_fd_t _LIBSNG_CALL sangoma_open_driver_ctrl(int port_no)
Open a Global Driver Control Device.
int sng_fd_t
Windows/Unix file handle abstraction.
int _LIBSNG_CALL sangoma_driver_port_get_config(sng_fd_t fd, port_cfg_t *port_cfg, unsigned short port_no)
Retrieve Port&#39;s &quot;Volatile&quot; configuration.
Wanpipe UDP Structure used for Maintenance and Debugging.
Definition: wanpipe_api.h:92
#define FNAME_LEN
string length of a file name
Definition: libsangoma.h:348
#define _LIBSNG_CALL
Not used in Linux.
Definition: libsangoma.h:185
int _LIBSNG_CALL sangoma_driver_hw_rescan(sng_fd_t fd, port_management_struct_t *port_mgmnt, int *cnt)
Rescan the pci and usb bus for newly added hardware.
int _LIBSNG_CALL sangoma_driver_get_hw_info(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no)
Retrieve information about a single instance of Sangoma hardware.
int DWORD
DWORD type is int, Ported from Windows.
Definition: libsangoma.h:259
int sangoma_port_mgmnt_ioctl(sng_fd_t fd, port_management_struct_t *port_management)
sng_fd_t _LIBSNG_CALL sangoma_open_dev_by_name(const char *dev_name)
Open API device using it&#39;s name. For example: Linux: w1g1, Windows wanpipe1_if1.
Definition: libsangoma.c:1717
int _LIBSNG_CALL sangoma_driver_get_version(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no)
Retrieve Driver Version BEFORE any communication interface is configured and sangoma_get_driver_versi...
int _LIBSNG_CALL sangoma_driver_port_stop(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no)
Start a Port, create Sangoma Communication interfaces.
#define WP_PORT_NAME_FORM
String define of a wanpipe port name.
int _LIBSNG_CALL sangoma_driver_port_start(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no)
Start a Port, create Sangoma Communication interfaces.