* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License.
+ * limitations under the License.
*/
#include <stdio.h>
#include <glib.h>
#include "net_connection.h"
+
#include <tizen_error.h>
-#define RETURN_FAIL_DESTROY(x) {connection_profile_destroy(x); return -1;}
+#define RETURN_FAIL_DESTROY(x) {connection_profile_destroy(x); return -1; }
gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
return false;
}
- buf[rv-1]='\0';
-
+ buf[rv-1] = '\0';
return true;
}
if (result == CONNECTION_ERROR_NONE)
printf("Connection open Succeeded\n");
else
- printf("Connection open Failed, err : %d\n", result);
+ printf("Connection open Failed, err : [%s]\n", test_print_error(result));
}
static void test_connection_closed_callback(connection_error_e result, void* user_data)
if (result == CONNECTION_ERROR_NONE)
printf("Connection close Succeeded\n");
else
- printf("Connection close Failed, err : %d\n", result);
+ printf("Connection close Failed, err : [%s]\n", test_print_error(result));
}
static void test_connection_reset_profile_callback(connection_error_e result, void* user_data)
if (result == CONNECTION_ERROR_NONE)
printf("Default profile setting Succeeded\n");
else
- printf("Default profile setting Failed, err : %d\n", result);
+ printf("Default profile setting Failed, err : [%s]\n", test_print_error(result));
}
void test_get_ethernet_cable_state_callback(connection_ethernet_cable_state_e state,
void* user_data)
{
- if(state == CONNECTION_ETHERNET_CABLE_ATTACHED)
+ if (state == CONNECTION_ETHERNET_CABLE_ATTACHED)
printf("Ethernet Cable Connected\n");
- else if(state == CONNECTION_ETHERNET_CABLE_DETACHED)
+ else if (state == CONNECTION_ETHERNET_CABLE_DETACHED)
printf("Ethernet Cable Disconnected\n");
}
rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
if (rv != CONNECTION_ERROR_NONE) {
- printf("Fail to get profile iterator [%d]\n", rv);
+ printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
return false;
}
connection_profile_get_wifi_essid(profile_h, &essid);
printf("%d. state:[%s], profile name:%s, essid:%s\n",
profile_count, test_print_state(profile_state),
- profile_name, (essid)? essid : "");
+ profile_name, (essid) ? essid : "");
g_free(essid);
profile_list[profile_count] = profile_h;
profile_count++;
} else {
- printf("%d. state:[%s], profile name : %s\n",
- profile_count, test_print_state(profile_state), profile_name);
+ connection_cellular_service_type_e service_type;
+ if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE)
+ printf("Fail to get cellular service type!\n");
+
+ printf("%d. state:[%s], profile name:%s[%d]\n",
+ profile_count, test_print_state(profile_state), profile_name, service_type);
profile_list[profile_count] = profile_h;
profile_count++;
return -1;
if (test_get_user_string("Input Apn - (Enter for skip) :", input_str1, 100)) {
+ g_strstrip(input_str1);
rv = connection_profile_set_cellular_apn(profile, input_str1);
if (rv != CONNECTION_ERROR_NONE)
return -1;
}
if (test_get_user_string("Input Proxy - (Enter for skip) :", input_str1, 100)) {
+ g_strstrip(input_str1);
rv = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, input_str1);
if (rv != CONNECTION_ERROR_NONE)
return -1;
}
if (test_get_user_string("Input HomeURL - (Enter for skip) :", input_str1, 100)) {
+ g_strstrip(input_str1);
rv = connection_profile_set_cellular_home_url(profile, input_str1);
if (rv != CONNECTION_ERROR_NONE)
return -1;
if (test_get_user_string("Input AuthPwd(Enter for skip) :", input_str2, 100) == false)
input_str2[0] = 0;
+ g_strstrip(input_str1);
+ g_strstrip(input_str2);
rv = connection_profile_set_cellular_auth_info(profile, type_val, input_str1, input_str2);
if (rv != CONNECTION_ERROR_NONE)
return -1;
{
int rv = 0;
int input_int = 0;
- int address_family;
+ int address_family = 0;
test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
static void test_print_cellular_info(connection_profile_h profile)
{
- connection_cellular_network_type_e network_type;
connection_cellular_service_type_e service_type;
char *apn = NULL;
connection_cellular_auth_type_e auth_type;
bool hidden = false;
bool editable = false;
- if (connection_profile_get_cellular_network_type(profile, &network_type) != CONNECTION_ERROR_NONE)
- printf("Fail to get cellular network type!\n");
- else
- printf("Cellular network type : %d\n", network_type);
-
if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
printf("Fail to get cellular service type!\n");
else
}
if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
- printf("Fail to get cellular is roaming!\n");
+ printf("Fail to get cellular roaming state!\n");
else
printf("Cellular roaming : %s\n", roaming ? "true" : "false");
connection_set_ethernet_cable_state_chaged_cb(connection,
test_get_ethernet_cable_state_callback, NULL);
} else {
- printf("Client registration failed %d\n", err);
+ printf("Client registration failed [%s]\n", test_print_error(err));
return -1;
}
rv = CONNECTION_ERROR_INVALID_OPERATION;
}
- if (rv != CONNECTION_ERROR_NONE){
- printf("Client deregistration fail [%d]\n", rv);
+ if (rv != CONNECTION_ERROR_NONE) {
+ printf("Client deregistration fail [%s]\n", test_print_error(rv));
return -1;
}
rv = connection_get_type(connection, &net_state);
if (rv != CONNECTION_ERROR_NONE) {
- printf("Fail to get network state [%d]\n", rv);
+ printf("Fail to get network state [%s]\n", test_print_error(rv));
return -1;
}
- printf("Retval = %d network connection state [%d]\n", rv, net_state);
+ printf("Retval = [%s] network connection state [%d]\n", test_print_error(rv), net_state);
return 1;
}
rv = connection_get_cellular_state(connection, &cellular_state);
if (rv != CONNECTION_ERROR_NONE) {
- printf("Fail to get Cellular state [%d]\n", rv);
+ printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
return -1;
}
- printf("Retval = %d Cellular state [%d]\n", rv, cellular_state);
+ printf("Retval = [%s] Cellular state [%d]\n", test_print_error(rv), cellular_state);
return 1;
}
rv = connection_get_wifi_state(connection, &wifi_state);
if (rv != CONNECTION_ERROR_NONE) {
- printf("Fail to get WiFi state [%d]\n", rv);
+ printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
return -1;
}
- printf("Retval = %d WiFi state [%d]\n", rv, wifi_state);
+ printf("Retval = [%s] WiFi state [%d]\n", test_print_error(rv), wifi_state);
return 1;
}
int test_get_current_ip(void)
{
char *ip_addr = NULL;
- int input;
- bool rv;
+ int input;
+ bool rv;
- rv = test_get_user_int("Input Address type to get"
- "(1:IPV4, 2:IPV6):", &input);
+ rv = test_get_user_int("Input Address type to get"
+ "(1:IPV4, 2:IPV6):", &input);
- if (rv == false) {
- printf("Invalid input!!\n");
- return -1;
- }
+ if (rv == false) {
+ printf("Invalid input!!\n");
+ return -1;
+ }
switch (input) {
case 1:
connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
printf("last recv data size [%lld]\n", rv);
connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
- printf("last sent data size [%lld]\n",rv );
+ printf("last sent data size [%lld]\n", rv);
connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
- printf("total received data size [%lld]\n",rv );
+ printf("total received data size [%lld]\n", rv);
connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
printf("total sent data size [%lld]\n", rv);
connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
printf("WiFi last recv data size [%lld]\n", rv);
connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
- printf("WiFi last sent data size [%lld]\n",rv );
+ printf("WiFi last sent data size [%lld]\n", rv);
connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
- printf("WiFi total received data size [%lld]\n",rv );
+ printf("WiFi total received data size [%lld]\n", rv);
connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
printf("WiFi total sent data size [%lld]\n", rv);
rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
if (rv != CONNECTION_ERROR_NONE) {
- printf("Fail to get profile iterator [%d]\n", rv);
+ printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
return -1;
}
printf("Fail to get profile name\n");
return -1;
}
- printf("profile name : %s\n", profile_name);
+ printf("profile name is %s\n", profile_name);
g_free(profile_name);
if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
rv = connection_get_current_profile(connection, &profile_h);
if (rv != CONNECTION_ERROR_NONE) {
- printf("Fail to get profile iterator [%d]\n", rv);
+ printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
return -1;
}
char *profile_name = NULL;
rv = test_get_user_int("Input profile type to get"
- "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering):", &input);
+ "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
if (rv == false) {
printf("Invalid input!!\n");
case 5:
service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
break;
+ case 6:
+ service_type = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
+ break;
default:
printf("Wrong number!!\n");
return -1;
if (test_get_user_string("Input Keyword - (Enter for skip) :", input_str, 100) == false)
return -1;
+ g_strstrip(input_str);
rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
if (rv != CONNECTION_ERROR_NONE)
RETURN_FAIL_DESTROY(profile);
break;
case CONNECTION_PROFILE_TYPE_ETHERNET:
+ if (test_update_network_info(profile) == -1)
+ return -1;
+ break;
+
case CONNECTION_PROFILE_TYPE_BT:
printf("Not supported!\n");
/* fall through */
rv = connection_get_bt_state(connection, &bt_state);
if (rv != CONNECTION_ERROR_NONE) {
- printf("Fail to get Bluetooth state [%d]\n", rv);
+ printf("Fail to get Bluetooth state [%s]\n", test_print_error(rv));
return -1;
}
- printf("Retval = %d, Bluetooth state [%d]\n", rv, bt_state);
+ printf("Retval = [%s], Bluetooth state [%d]\n", test_print_error(rv), bt_state);
return 1;
}
return -1;
}
- if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE) {
+ if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
return -1;
- }
return 1;
}
int main(int argc, char **argv)
{
GMainLoop *mainloop;
- mainloop = g_main_loop_new (NULL, FALSE);
+ mainloop = g_main_loop_new(NULL, FALSE);
GIOChannel *channel = g_io_channel_unix_new(0);
- g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread,NULL );
+ g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
printf("Test Thread created...\n");
- g_main_loop_run (mainloop);
+ g_main_loop_run(mainloop);
return 0;
}
{
int rv = 0;
char a[100];
-
+
memset(a, '\0', 100);
printf("Event received from stdin\n");
-
+
rv = read(0, a, 100);
-
+
if (rv < 0 || a[0] == '0') {
if (connection != NULL)
test_deregister_client();
exit(1);
}
- if (*a == '\n' || *a == '\r'){
+ if (*a == '\n' || *a == '\r') {
printf("\n\n Network Connection API Test App\n\n");
printf("Options..\n");
- printf("1 - Create Handle and set callbacks\n");
- printf("2 - Destroy Handle(unset callbacks automatically)\n");
- printf("3 - Get network state\n");
- printf("4 - Get cellular state (please insert SIM Card)\n");
- printf("5 - Get wifi state (please turn on WiFi)\n");
- printf("6 - Get current proxy address \n");
- printf("7 - Get current Ip address\n");
- printf("8 - Get cellular data call statistics\n");
- printf("9 - Get WiFi data call statistics\n");
- printf("a - Get Profile list\n");
- printf("b - Get Connected Profile list\n");
- printf("c - Get Current profile\n");
- printf("d - Open connection with profile\n");
- printf("e - Get default cellular service by type\n");
- printf("f - Set default cellular service by type\n");
- printf("g - Close connection with profile\n");
- printf("h - Add profile(Cellular only)\n");
- printf("i - Remove profile(Cellular:delete, WiFi:forgot)\n");
- printf("j - Update profile\n");
- printf("k - Get profile info\n");
- printf("l - Refresh profile info\n");
- printf("m - Set state changed callback\n");
- printf("n - Unset state changed callback\n");
- printf("o - Reset cellular data call statistics\n");
- printf("p - Reset WiFi data call statistics\n");
- printf("q - Add new route\n");
- printf("r - Remove a route\n");
- printf("s - Get Bluetooth state\n");
- printf("t - Get profile id\n");
- printf("u - Reset profile\n");
- printf("v - Get all cellular default profiles\n");
- printf("w - Get mac address\n");
- printf("x - Get ethernet cable state\n");
- printf("B - Add IPv6 new route\n");
- printf("C - Remove IPv6 route\n");
- printf("0 - Exit \n");
- printf("ENTER - Show options menu.......\n");
+ printf("1 - Create Handle and set callbacks\n");
+ printf("2 - Destroy Handle(unset callbacks automatically)\n");
+ printf("3 - Get network state\n");
+ printf("4 - Get cellular state (please insert SIM Card)\n");
+ printf("5 - Get wifi state (please turn on WiFi)\n");
+ printf("6 - Get current proxy address \n");
+ printf("7 - Get current Ip address\n");
+ printf("8 - Get cellular data call statistics\n");
+ printf("9 - Get WiFi data call statistics\n");
+ printf("a - Get Profile list\n");
+ printf("b - Get Connected Profile list\n");
+ printf("c - Get Current profile\n");
+ printf("d - Open connection with profile\n");
+ printf("e - Get default cellular service by type\n");
+ printf("f - Set default cellular service by type\n");
+ printf("g - Close connection with profile\n");
+ printf("h - Add profile(Cellular and Wifi only)\n");
+ printf("i - Remove profile(Cellular:delete, WiFi:forgot)\n");
+ printf("j - Update profile\n");
+ printf("k - Get profile info\n");
+ printf("l - Refresh profile info\n");
+ printf("m - Set state changed callback\n");
+ printf("n - Unset state changed callback\n");
+ printf("o - Reset cellular data call statistics\n");
+ printf("p - Reset WiFi data call statistics\n");
+ printf("q - Add new route\n");
+ printf("r - Remove a route\n");
+ printf("s - Get Bluetooth state\n");
+ printf("t - Get profile id\n");
+ printf("u - Reset profile\n");
+ printf("v - Get all cellular default profiles\n");
+ printf("w - Get mac address\n");
+ printf("x - Get ethernet cable state\n");
+ printf("B - Add IPv6 new route\n");
+ printf("C - Remove IPv6 route\n");
+ printf("0 - Exit \n");
+ printf("ENTER - Show options menu.......\n");
}
switch (a[0]) {