00001
00033 #include "libsangoma-pvt.h"
00034 #include "libsangoma.h"
00035
00036 #ifndef LIBSANGOMA_LIGHT
00037
00038
00042 int sangoma_port_mgmnt_ioctl(sng_fd_t fd, port_management_struct_t *port_management)
00043 {
00044 int err = 0;
00045 #if defined(__WINDOWS__)
00046 DWORD ln;
00047 if(DeviceIoControl(
00048 fd,
00049 IoctlPortManagementCommand,
00050 (LPVOID)port_management,
00051 sizeof(port_management_struct_t),
00052 (LPVOID)port_management,
00053 sizeof(port_management_struct_t),
00054 (LPDWORD)(&ln),
00055 (LPOVERLAPPED)NULL
00056 ) == FALSE){
00057
00058 DBG_ERR("%s():Error: IoctlPortManagementCommand failed!!\n", __FUNCTION__);
00059 err = -1;
00060 }
00061 #else
00062 err=ioctl(fd,WANPIPE_IOCTL_PORT_MGMT,port_management);
00063 if (err) {
00064 err = -1;
00065 }
00066 #endif
00067 if(err){
00068 port_management->operation_status = SANG_STATUS_INVALID_DEVICE;
00069 }
00070
00071 return err;
00072 }
00073
00074 int sangoma_port_cfg_ioctl(sng_fd_t fd, port_cfg_t *port_cfg)
00075 {
00076 int err = 0;
00077 #if defined(__WINDOWS__)
00078 DWORD ln;
00079 if(DeviceIoControl(
00080 fd,
00081 IoctlPortConfigurationCommand,
00082 (LPVOID)port_cfg,
00083 sizeof(port_cfg_t),
00084 (LPVOID)port_cfg,
00085 sizeof(port_cfg_t),
00086 (LPDWORD)(&ln),
00087 (LPOVERLAPPED)NULL
00088 ) == FALSE){
00089
00090 DBG_ERR("%s():Error: IoctlPortConfigurationCommand failed!!\n", __FUNCTION__);
00091 err = -1;
00092 }
00093 #else
00094 err=ioctl(fd,WANPIPE_IOCTL_PORT_CONFIG,port_cfg);
00095 if (err) {
00096 err = -1;
00097 }
00098 #endif
00099 if(err){
00100 port_cfg->operation_status = SANG_STATUS_INVALID_DEVICE;
00101 }
00102
00103 return err;
00104 }
00105
00106
00107 sng_fd_t _LIBSNG_CALL sangoma_open_driver_ctrl(int port_no)
00108 {
00109 char tmp_fname[FNAME_LEN];
00110
00111 #if defined(__WINDOWS__)
00112
00113 _snprintf(tmp_fname, DEV_NAME_LEN, WP_PORT_NAME_FORM, port_no);
00114 #else
00115
00116 _snprintf(tmp_fname, DEV_NAME_LEN, WP_CONFIG_DEV_NAME);
00117 #endif
00118 return sangoma_open_dev_by_name(tmp_fname);
00119 }
00120
00121
00122 int _LIBSNG_CALL sangoma_mgmt_cmd(sng_fd_t fd, wan_udp_hdr_t* wan_udp)
00123 {
00124 int err=0;
00125 #if defined(__WINDOWS__)
00126 if(UdpManagementCommand(fd, wan_udp)){
00127 err = 1;
00128 }
00129 #else
00130 unsigned char id = 0;
00131
00132 wan_udp->wan_udphdr_request_reply = 0x01;
00133 wan_udp->wan_udphdr_id = id;
00134 wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
00135
00136 err=ioctl(fd,WANPIPE_IOCTL_PIPEMON,wan_udp);
00137 if (err < 0) {
00138 err = 1;
00139 }
00140 #endif
00141 if(err){
00142
00143 return err;
00144 }
00145
00146
00147
00148 return 0;
00149 }
00150
00151 int _LIBSNG_CALL sangoma_driver_port_start(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no)
00152 {
00153 int err;
00154 port_mgmnt->operation_status = SANG_STATUS_GENERAL_ERROR;
00155 port_mgmnt->command_code = START_PORT_VOLATILE_CONFIG;
00156 port_mgmnt->port_no = port_no;
00157
00158 err = sangoma_port_mgmnt_ioctl(fd, port_mgmnt);
00159 if (err) {
00160
00161 return err;
00162 }
00163
00164 return port_mgmnt->operation_status;
00165 }
00166
00167 int _LIBSNG_CALL sangoma_driver_port_stop(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no)
00168 {
00169 int err;
00170 port_mgmnt->operation_status = SANG_STATUS_GENERAL_ERROR;
00171 port_mgmnt->command_code = STOP_PORT;
00172 port_mgmnt->port_no = port_no;
00173
00174 err = sangoma_port_mgmnt_ioctl(fd, port_mgmnt);
00175 if (err) {
00176
00177 return err;
00178 }
00179
00180 switch(port_mgmnt->operation_status)
00181 {
00182 case SANG_STATUS_CAN_NOT_STOP_DEVICE_WHEN_ALREADY_STOPPED:
00183
00184
00185
00186 err = SANG_STATUS_SUCCESS;
00187 break;
00188 default:
00189 err = port_mgmnt->operation_status;
00190 break;
00191 }
00192
00193 return err;
00194 }
00195
00196 int _LIBSNG_CALL sangoma_driver_get_hw_info(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no)
00197 {
00198 int err;
00199 port_mgmnt->operation_status = SANG_STATUS_GENERAL_ERROR;
00200 port_mgmnt->command_code = GET_HARDWARE_INFO;
00201 port_mgmnt->port_no = port_no;
00202
00203 err = sangoma_port_mgmnt_ioctl(fd, port_mgmnt);
00204 if (err) {
00205 return err;
00206 }
00207
00208 return port_mgmnt->operation_status;
00209 }
00210
00211 int _LIBSNG_CALL sangoma_driver_get_version(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no)
00212 {
00213 int err;
00214 port_mgmnt->command_code = GET_DRIVER_VERSION;
00215 port_mgmnt->port_no = port_no;
00216
00217 err = sangoma_port_mgmnt_ioctl(fd, port_mgmnt);
00218 if (err) {
00219 return err;
00220 }
00221
00222 return port_mgmnt->operation_status;
00223 }
00224
00225 #ifdef WP_API_FEATURE_HARDWARE_RESCAN
00226 int _LIBSNG_CALL sangoma_driver_hw_rescan(sng_fd_t fd, port_management_struct_t *port_mgmnt, int *cnt)
00227 {
00228 int err;
00229 port_mgmnt->command_code = WANPIPE_HARDWARE_RESCAN;
00230 port_mgmnt->port_no = 1;
00231
00232 err = sangoma_port_mgmnt_ioctl(fd, port_mgmnt);
00233 if (err < 0) {
00234 return err;
00235 }
00236
00237 *cnt=port_mgmnt->port_no;
00238
00239 return port_mgmnt->operation_status;
00240 }
00241 #endif
00242
00243
00244 int _LIBSNG_CALL sangoma_driver_port_set_config(sng_fd_t fd, port_cfg_t *port_cfg, unsigned short port_no)
00245 {
00246 port_cfg->operation_status = SANG_STATUS_GENERAL_ERROR;
00247 port_cfg->command_code = SET_PORT_VOLATILE_CONFIG;
00248 port_cfg->port_no = port_no;
00249
00250 return sangoma_port_cfg_ioctl(fd, port_cfg);
00251 }
00252
00253 int _LIBSNG_CALL sangoma_driver_port_get_config(sng_fd_t fd, port_cfg_t *port_cfg, unsigned short port_no)
00254 {
00255 port_cfg->operation_status = SANG_STATUS_GENERAL_ERROR;
00256 port_cfg->command_code = GET_PORT_VOLATILE_CONFIG;
00257 port_cfg->port_no = port_no;
00258 return sangoma_port_cfg_ioctl(fd, port_cfg);
00259 }
00260
00261 int _LIBSNG_CALL sangoma_write_port_config_on_persistent_storage(hardware_info_t *hardware_info, port_cfg_t *port_cfg, unsigned short port_no)
00262 {
00263 int err = 0;
00264 #if defined(__WINDOWS__)
00265 HKEY hPortRegistryKey = registry_open_port_key(hardware_info);
00266
00267
00268 unsigned int ind;
00269
00270 if(hPortRegistryKey == INVALID_HANDLE_VALUE){
00271 return 1;
00272 }
00273
00274
00275 if(registry_write_front_end_cfg(hPortRegistryKey, port_cfg)){
00276 return 2;
00277 }
00278
00279
00280 if(registry_write_wan_tdmv_conf(hPortRegistryKey, port_cfg)){
00281 return 3;
00282 }
00283
00284
00285 err = registry_set_integer_value(hPortRegistryKey, "aft_number_of_logic_channels", port_cfg->num_of_ifs);
00286 if(err){
00287 return err;
00288 }
00289
00290
00291 for(ind = 0; ind < port_cfg->num_of_ifs; ind++){
00292 registry_write_channel_group_cfg(hPortRegistryKey, port_cfg, ind, port_cfg->if_cfg[ind]);
00293 }
00294
00295 #else
00296 printf("%s(): Warning: function not implemented\n", __FUNCTION__);
00297 err = 1;
00298 #endif
00299 return err;
00300 }
00301
00302
00303
00304
00305 #endif