libsangoma  1
Functions
libsangoma_config.c File Reference

Sangoma Driver and Hardware Configuration, Operation. More...

#include "libsangoma-pvt.h"
#include "libsangoma.h"
Include dependency graph for libsangoma_config.c:

Go to the source code of this file.

Functions

int sangoma_port_mgmnt_ioctl (sng_fd_t fd, port_management_struct_t *port_management)
 
int sangoma_port_cfg_ioctl (sng_fd_t fd, port_cfg_t *port_cfg)
 
sng_fd_t _LIBSNG_CALL sangoma_open_driver_ctrl (int port_no)
 Open a Global Driver Control Device. More...
 
int _LIBSNG_CALL sangoma_mgmt_cmd (sng_fd_t fd, wan_udp_hdr_t *wan_udp)
 Execute Sangoma Management Command. More...
 
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. More...
 
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. More...
 
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. More...
 
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_version() can not be called. More...
 
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. More...
 
int _LIBSNG_CALL sangoma_driver_port_set_config (sng_fd_t fd, port_cfg_t *port_cfg, unsigned short port_no)
 Set Port's "Volatile" configuration. The configuration will not persist between system restarts. Before calling this function please stop the port by calling sangoma_driver_port_stop(). After calling this function please start the port by calling sangoma_driver_port_start(). More...
 
int _LIBSNG_CALL sangoma_driver_port_get_config (sng_fd_t fd, port_cfg_t *port_cfg, unsigned short port_no)
 Retrieve Port's "Volatile" configuration. More...
 
int _LIBSNG_CALL sangoma_write_port_config_on_persistent_storage (hardware_info_t *hardware_info, port_cfg_t *port_cfg, unsigned short port_no)
 

Detailed Description

Sangoma Driver and Hardware Configuration, Operation.

Author(s): Nenad Corbic, David Rokhvarg

Copyright: (c) 2005-2011 Sangoma Technologies Corporation

THIS SOFTWARE IS PROVIDED BY Sangoma Technologies ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Sangoma Technologies BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

Definition in file libsangoma_config.c.

Function Documentation

int sangoma_port_mgmnt_ioctl ( sng_fd_t  fd,
port_management_struct_t *  port_management 
)

Device PORT Control Functions

Definition at line 42 of file libsangoma_config.c.

References FALSE, SANG_STATUS_INVALID_DEVICE, and WANPIPE_IOCTL_PORT_MGMT.

Referenced by sangoma_driver_get_hw_info(), sangoma_driver_get_version(), sangoma_driver_hw_rescan(), sangoma_driver_port_start(), and sangoma_driver_port_stop().

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 }
#define FALSE
FALSE value is 0, Ported from Windows.
Definition: libsangoma.h:244
int DWORD
DWORD type is int, Ported from Windows.
Definition: libsangoma.h:259

Here is the caller graph for this function:

sng_fd_t sangoma_open_driver_ctrl ( int  port_no)

Open a Global Driver Control Device.

Returns
File Descriptor - negative=error 0 or greater = fd

The global control device receives events for all devices configured.

Definition at line 107 of file libsangoma_config.c.

References _snprintf, FNAME_LEN, sangoma_open_dev_by_name(), and WP_PORT_NAME_FORM.

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 }
#define _snprintf
_snprintf type mapped to snprintf, Ported from Windows
Definition: libsangoma.h:255
#define FNAME_LEN
string length of a file name
Definition: libsangoma.h:348
sng_fd_t _LIBSNG_CALL sangoma_open_dev_by_name(const char *dev_name)
Open API device using it's name. For example: Linux: w1g1, Windows wanpipe1_if1.
Definition: libsangoma.c:1717
#define WP_PORT_NAME_FORM
String define of a wanpipe port name.

Here is the call graph for this function:

int sangoma_mgmt_cmd ( sng_fd_t  fd,
wan_udp_hdr_t wan_udp 
)

Execute Sangoma Management Command.

Device MANAGEMENT Functions

Parameters
fddevice file descriptor
wan_udpmanagement command structure
Returns
non-zero: error, 0: ok

Definition at line 122 of file libsangoma_config.c.

References WANPIPE_IOCTL_PIPEMON.

Referenced by sangoma_fe_reg_read(), sangoma_fe_reg_write(), sangoma_get_aft_customer_id(), and sangoma_port_led_ctrl().

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 }

Here is the caller graph for this function:

int 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.

Device PORT Control Functions

Parameters
[in]fdPort Device file descriptor
[out]port_mgmntpointer to a port_management_struct_t structure. On return, sangoma_driver_port_start() updates operation_status field of this structure.
[in]port_no1-based Port Number. Port numbers correspond to Port Names. For example, a 2-Port card will have ports named WANPIPE1 and WANPIPE2.
Returns
non-zero: system error. Call OS specific code to find cause of the error. Linux example: strerror(errno) Windows example: combination of GetLastError()/FormatMessage() zero: no system error. Check port_mgmt->operation_status.

Definition at line 151 of file libsangoma_config.c.

References SANG_STATUS_GENERAL_ERROR, and sangoma_port_mgmnt_ioctl().

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 }
int sangoma_port_mgmnt_ioctl(sng_fd_t fd, port_management_struct_t *port_management)

Here is the call graph for this function:

int 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.

Parameters
[in]fdPort Device file descriptor
[out]port_mgmntpointer to a port_management_struct_t structure. On return, sangoma_driver_port_stop() updates operation_status field of this structure.
[in]port_no1-based Port Number. Port numbers correspond to Port Names. For example, a 2-Port card will have ports named WANPIPE1 and WANPIPE2.
Returns
non-zero: system error. Call OS specific code to find cause of the error. Linux example: strerror(errno) Windows example: combination of GetLastError()/FormatMessage() zero: no system error. Check port_mgmt->operation_status.

Definition at line 167 of file libsangoma_config.c.

References SANG_STATUS_CAN_NOT_STOP_DEVICE_WHEN_ALREADY_STOPPED, SANG_STATUS_GENERAL_ERROR, SANG_STATUS_SUCCESS, and sangoma_port_mgmnt_ioctl().

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 }
int sangoma_port_mgmnt_ioctl(sng_fd_t fd, port_management_struct_t *port_management)

Here is the call graph for this function:

int 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.

Parameters
[in]fdPort Device file descriptor
[out]port_mgmntpointer to port_management_struct_t structure which will contain hardware_info_t at it's "data" field, when this function returns.
[in]port_noplease see comment of sangoma_driver_port_set_config()
Returns
non-zero: system error. Call OS specific code to find cause of the error. Linux example: strerror(errno) Windows example: combination of GetLastError()/FormatMessage() zero: no system error. Check port_mgmt->operation_status.

Definition at line 196 of file libsangoma_config.c.

References SANG_STATUS_GENERAL_ERROR, and sangoma_port_mgmnt_ioctl().

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 }
int sangoma_port_mgmnt_ioctl(sng_fd_t fd, port_management_struct_t *port_management)

Here is the call graph for this function:

int 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_version() can not be called.

Parameters
[in]fdPort Device file descriptor
[out]port_mgmntpointer to port_management_struct_t structure which will contain wan_driver_version_t at it's "data" field, when this function returns.
[in]port_noplease see comment of sangoma_driver_port_set_config()
Returns
non-zero: system error. Call OS specific code to find cause of the error. Linux example: strerror(errno) Windows example: combination of GetLastError()/FormatMessage() zero: no system error. Check port_mgmt->operation_status.

Definition at line 211 of file libsangoma_config.c.

References sangoma_port_mgmnt_ioctl().

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 }
int sangoma_port_mgmnt_ioctl(sng_fd_t fd, port_management_struct_t *port_management)

Here is the call graph for this function:

int sangoma_driver_hw_rescan ( sng_fd_t  fd,
port_management_struct_t *  port_mgmnt,
int *  detected_port_cnt 
)

Rescan the pci and usb bus for newly added hardware.

Parameters
[in]fdPort Device file descriptor
[out]port_mgmntpointer to port_management_struct_t structure which will contain wan_driver_version_t at it's "data" field, when this function returns.
[out]detected_port_cntnewly detected ports.
Returns
less than zero: system error. Call OS specific code to find cause of the error. Linux example: strerror(errno) Windows example: combination of GetLastError()/FormatMessage() zero or greater: number of new ports found.

Definition at line 226 of file libsangoma_config.c.

References sangoma_port_mgmnt_ioctl().

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 }
int sangoma_port_mgmnt_ioctl(sng_fd_t fd, port_management_struct_t *port_management)

Here is the call graph for this function:

int sangoma_driver_port_set_config ( sng_fd_t  fd,
port_cfg_t *  port_cfg,
unsigned short  port_no 
)

Set Port's "Volatile" configuration. The configuration will not persist between system restarts. Before calling this function please stop the port by calling sangoma_driver_port_stop(). After calling this function please start the port by calling sangoma_driver_port_start().

Parameters
[in]fdPort Device file descriptor
[in,out]port_cfgpointer to port_cfg_t structure that specifies complete Port configuration. On return, sangoma_driver_port_set_config() updates operation_status field of this structure.
[in]port_no1-based Port Number. Port numbers correspond to Port Names. For example, a 2-Port card will have ports named WANPIPE1 and WANPIPE2.
Returns
non-zero: system error. Call OS specific code to find cause of the error. Linux example: strerror(errno) Windows example: combination of GetLastError()/FormatMessage() zero: no system error. Check port_cfg->operation_status.

Definition at line 244 of file libsangoma_config.c.

References SANG_STATUS_GENERAL_ERROR.

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 }
int sangoma_driver_port_get_config ( sng_fd_t  fd,
port_cfg_t *  port_cfg,
unsigned short  port_no 
)

Retrieve Port's "Volatile" configuration.

Parameters
[in]fdPort Device file descriptor
[out]port_cfgpointer to port_cfg_t structure. On return, sangoma_driver_port_get_config() will copy current Port configuration into this structure.
[in]port_noplease see comment of sangoma_driver_port_set_config()
Returns
non-zero: system error. Call OS specific code to find cause of the error. Linux example: strerror(errno) Windows example: combination of GetLastError()/FormatMessage() zero: no system error. Check port_cfg->operation_status.

Definition at line 253 of file libsangoma_config.c.

References SANG_STATUS_GENERAL_ERROR.

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 }