From: user Date: Tue, 12 Mar 2013 15:35:11 +0000 (+0530) Subject: The patch contains following changes - 1. Clone function removal from each Module... X-Git-Tag: submit/tizen_2.1/20130424.233346~26 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a04d2f35e63cec9aa815c386cadc2083231ecaf1;p=platform%2Fcore%2Ftelephony%2Flibtcore.git The patch contains following changes - 1. Clone function removal from each Module (tcore_xxx_clone) 2. Updation of MUX to remove Kernel MUX support from libtcore 3. Updations related to Mapping Table 4. Server Node mechanism addition --- diff --git a/debian/rules b/debian/rules old mode 100755 new mode 100644 diff --git a/include/co_call.h b/include/co_call.h old mode 100755 new mode 100644 index e2e3637..e8e13a4 --- a/include/co_call.h +++ b/include/co_call.h @@ -150,102 +150,102 @@ struct tcore_call_control_operations { TReturn (*deflect)(CoreObject *o, UserRequest *ur, const char *number, ConfirmCallback cb, void *user_data); }; -/* Call Core API */ -CoreObject *tcore_call_new(TcorePlugin *p, const char *name, struct tcore_call_operations *ops, TcoreHal *hal); -void tcore_call_free(CoreObject *o); +// Call Core API +CoreObject *tcore_call_new(TcorePlugin *p, + struct tcore_call_operations *ops, TcoreHal *hal); +void tcore_call_free( CoreObject *o); -CoreObject *tcore_call_clone(TcorePlugin *p, const char *name, TcoreHal *hal); void tcore_call_override_ops(CoreObject *o, - struct tcore_call_operations *call_ops, - struct tcore_call_control_operations *control_ops); - -/* Call Object API */ -CallObject *tcore_call_object_new(CoreObject *o, int id); -gboolean tcore_call_object_free(CoreObject *o, CallObject *co); - -CallObject *tcore_call_object_current_on_mt_processing(CoreObject *o); -CallObject *tcore_call_object_current_on_mo_processing(CoreObject *o); -CallObject *tcore_call_object_find_by_id(CoreObject *o, int id); -CallObject *tcore_call_object_find_by_number(CoreObject *o, char *num); -GSList *tcore_call_object_find_by_status(CoreObject *o, enum tcore_call_status cs); - -int tcore_call_object_get_id(CallObject *co); - -gboolean tcore_call_object_set_type(CallObject *co, enum tcore_call_type ct); -enum tcore_call_type tcore_call_object_get_type(CallObject *co); - -gboolean tcore_call_object_set_direction(CallObject *co, enum tcore_call_direction cd); -enum tcore_call_direction tcore_call_object_get_direction(CallObject *co); - -gboolean tcore_call_object_set_status(CallObject *co, enum tcore_call_status cs); -enum tcore_call_status tcore_call_object_get_status(CallObject *co); - -gboolean tcore_call_object_set_cli_info(CallObject *co, enum tcore_call_cli_mode mode, char *num); -enum tcore_call_cli_mode tcore_call_object_get_cli_mode(CallObject *co); -int tcore_call_object_get_number(CallObject *co, char *num); - -gboolean tcore_call_object_set_cna_info(CallObject *co, enum tcore_call_cna_mode mode, char *name, int dcs); -enum tcore_call_cna_mode tcore_call_object_get_cna_mode(CallObject *co); -int tcore_call_object_get_name(CallObject *co, char *name); - -gboolean tcore_call_object_set_multiparty_state (CallObject *co, gboolean is); -gboolean tcore_call_object_get_multiparty_state (CallObject *co); - -gboolean tcore_call_object_set_active_line(CallObject *co, unsigned int line); -int tcore_call_object_get_active_line(CallObject *co); - - -/* Call Control API */ -gboolean tcore_call_control_new(CoreObject *o, struct tcore_call_control_operations *ops); -void tcore_call_control_free(CoreObject *o); - -TReturn tcore_call_control_answer_hold_and_accept(CoreObject *o, UserRequest *ur, ConfirmCallback cb, void *user_data); -TReturn tcore_call_control_answer_replace(CoreObject *o, UserRequest *ur, ConfirmCallback cb, void *user_data); -TReturn tcore_call_control_answer_reject(CoreObject *o, UserRequest *ur, ConfirmCallback cb, void *user_data); - -TReturn tcore_call_control_end_specific(CoreObject *o, UserRequest *ur, const int id, ConfirmCallback cb, void *user_data); -TReturn tcore_call_control_end_all_active(CoreObject *o, UserRequest *ur, ConfirmCallback cb, void *user_data); -TReturn tcore_call_control_end_all_held(CoreObject *o, UserRequest *ur, ConfirmCallback cb, void *user_data); - -TReturn tcore_call_control_active(CoreObject *o, UserRequest *ur, ConfirmCallback cb, void *user_data); -TReturn tcore_call_control_hold(CoreObject *o, UserRequest *ur, ConfirmCallback cb, void *user_data); -TReturn tcore_call_control_swap(CoreObject *o, UserRequest *ur, ConfirmCallback cb, void *user_data); -TReturn tcore_call_control_join(CoreObject *o, UserRequest *ur, ConfirmCallback cb, void *user_data); -TReturn tcore_call_control_split(CoreObject *o, UserRequest *ur, const int id, ConfirmCallback cb, void *user_data); -TReturn tcore_call_control_transfer(CoreObject *o, UserRequest *ur, ConfirmCallback cb, void *user_data); -TReturn tcore_call_control_deflect(CoreObject *o, UserRequest *ur, const char *number, ConfirmCallback cb, void *user_data); - -void tcore_call_control_set_operations(CoreObject *o, struct tcore_call_control_operations *ops); - - -void tcore_call_information_mo_col(CoreObject *o, char *number); -void tcore_call_information_mo_waiting(CoreObject *o); -void tcore_call_information_mo_cug(CoreObject *o, int cug_index); -void tcore_call_information_mo_forwarded(CoreObject *o); -void tcore_call_information_mo_barred_incoming(CoreObject *o); -void tcore_call_information_mo_barred_outgoing(CoreObject *o); -void tcore_call_information_mo_deflected(CoreObject *o); -void tcore_call_information_mo_clir_suppression_reject(CoreObject *o); -void tcore_call_information_mo_cfu(CoreObject *o); -void tcore_call_information_mo_cfc(CoreObject *o); - -void tcore_call_information_mt_cli(CoreObject *o, enum tcore_call_cli_mode mode, char *number); -void tcore_call_information_mt_cna(CoreObject *o, enum tcore_call_cna_mode mode, char *name, int dcs); -void tcore_call_information_mt_forwarded_call(CoreObject *o, char *number); -void tcore_call_information_mt_cug_call(CoreObject *o, int cug_index, char *number); -void tcore_call_information_mt_deflected_call(CoreObject *o, char *number); -void tcore_call_information_mt_transfered(CoreObject *o, char *number); - -void tcore_call_information_held(CoreObject *o, char *number); -void tcore_call_information_active(CoreObject *o, char *number); -void tcore_call_information_joined(CoreObject *o, char *number); -void tcore_call_information_released_on_hold(CoreObject *o, char *number); -void tcore_call_information_transfer_alert(CoreObject *o, char *number); -void tcore_call_information_transfered(CoreObject *o, char *number); -void tcore_call_information_cf_check_ss_message(CoreObject *o, char *number); + struct tcore_call_operations *call_ops, + struct tcore_call_control_operations *control_ops); + +// Call Object API +CallObject *tcore_call_object_new( CoreObject *o, int id ); +gboolean tcore_call_object_free( CoreObject *o, CallObject *co ); + +CallObject *tcore_call_object_current_on_mt_processing( CoreObject *o ); +CallObject *tcore_call_object_current_on_mo_processing( CoreObject *o ); +CallObject *tcore_call_object_find_by_id( CoreObject *o, int id ); +CallObject *tcore_call_object_find_by_number( CoreObject *o, char *num ); +GSList *tcore_call_object_find_by_status( CoreObject *o, enum tcore_call_status cs ); + +int tcore_call_object_get_id( CallObject *co ); + +gboolean tcore_call_object_set_type( CallObject *co, enum tcore_call_type ct ); +enum tcore_call_type tcore_call_object_get_type( CallObject *co ); + +gboolean tcore_call_object_set_direction( CallObject *co, enum tcore_call_direction cd ); +enum tcore_call_direction tcore_call_object_get_direction( CallObject *co ); + +gboolean tcore_call_object_set_status( CallObject *co, enum tcore_call_status cs ); +enum tcore_call_status tcore_call_object_get_status( CallObject *co ); + +gboolean tcore_call_object_set_cli_info( CallObject *co, enum tcore_call_cli_mode mode, char *num ); +enum tcore_call_cli_mode tcore_call_object_get_cli_mode( CallObject *co ); +int tcore_call_object_get_number( CallObject *co, char *num ); + +gboolean tcore_call_object_set_cna_info( CallObject *co, enum tcore_call_cna_mode mode, char *name, int dcs ); +enum tcore_call_cna_mode tcore_call_object_get_cna_mode( CallObject *co ); +int tcore_call_object_get_name( CallObject *co, char *name ); + +gboolean tcore_call_object_set_multiparty_state ( CallObject *co, gboolean is ); +gboolean tcore_call_object_get_multiparty_state ( CallObject *co ); + +gboolean tcore_call_object_set_active_line( CallObject *co, unsigned int line ); +int tcore_call_object_get_active_line( CallObject *co ); + + +// Call Control API +gboolean tcore_call_control_new( CoreObject *o, struct tcore_call_control_operations *ops ); +void tcore_call_control_free( CoreObject *o ); + +TReturn tcore_call_control_answer_hold_and_accept( CoreObject* o, UserRequest* ur, ConfirmCallback cb, void* user_data ); +TReturn tcore_call_control_answer_replace( CoreObject* o, UserRequest* ur, ConfirmCallback cb, void* user_data ); +TReturn tcore_call_control_answer_reject( CoreObject* o, UserRequest* ur, ConfirmCallback cb, void* user_data ); + +TReturn tcore_call_control_end_specific( CoreObject* o, UserRequest* ur, const int id, ConfirmCallback cb, void* user_data ); +TReturn tcore_call_control_end_all_active( CoreObject* o, UserRequest* ur, ConfirmCallback cb, void* user_data ); +TReturn tcore_call_control_end_all_held( CoreObject* o, UserRequest* ur, ConfirmCallback cb, void* user_data ); + +TReturn tcore_call_control_active( CoreObject* o, UserRequest* ur, ConfirmCallback cb, void* user_data ); +TReturn tcore_call_control_hold( CoreObject* o, UserRequest* ur, ConfirmCallback cb, void* user_data ); +TReturn tcore_call_control_swap( CoreObject* o, UserRequest* ur, ConfirmCallback cb, void* user_data ); +TReturn tcore_call_control_join( CoreObject* o, UserRequest* ur, ConfirmCallback cb, void* user_data ); +TReturn tcore_call_control_split( CoreObject* o, UserRequest* ur, const int id, ConfirmCallback cb, void* user_data ); +TReturn tcore_call_control_transfer( CoreObject* o, UserRequest* ur, ConfirmCallback cb, void* user_data ); +TReturn tcore_call_control_deflect( CoreObject* o, UserRequest* ur, const char* number, ConfirmCallback cb, void* user_data ); + +void tcore_call_control_set_operations( CoreObject* o, struct tcore_call_control_operations *ops ); + + +void tcore_call_information_mo_col( CoreObject *o, char* number ); +void tcore_call_information_mo_waiting( CoreObject *o ); +void tcore_call_information_mo_cug( CoreObject *o, int cug_index ); +void tcore_call_information_mo_forwarded( CoreObject *o ); +void tcore_call_information_mo_barred_incoming( CoreObject *o ); +void tcore_call_information_mo_barred_outgoing( CoreObject *o ); +void tcore_call_information_mo_deflected( CoreObject *o ); +void tcore_call_information_mo_clir_suppression_reject( CoreObject *o ); +void tcore_call_information_mo_cfu( CoreObject *o ); +void tcore_call_information_mo_cfc( CoreObject *o ); + +void tcore_call_information_mt_cli( CoreObject *o, enum tcore_call_cli_mode mode, char* number ); +void tcore_call_information_mt_cna( CoreObject *o, enum tcore_call_cna_mode mode, char* name, int dcs ); +void tcore_call_information_mt_forwarded_call( CoreObject *o, char* number ); +void tcore_call_information_mt_cug_call( CoreObject *o, int cug_index, char* number ); +void tcore_call_information_mt_deflected_call( CoreObject *o, char* number ); +void tcore_call_information_mt_transfered( CoreObject *o, char* number ); + +void tcore_call_information_held( CoreObject *o, char* number ); +void tcore_call_information_active( CoreObject *o, char* number ); +void tcore_call_information_joined( CoreObject *o, char* number ); +void tcore_call_information_released_on_hold( CoreObject *o, char* number ); +void tcore_call_information_transfer_alert( CoreObject *o, char* number ); +void tcore_call_information_transfered( CoreObject *o, char* number ); +void tcore_call_information_cf_check_ss_message( CoreObject *o, char* number ); /* To be removed later */ -void tcore_call_information_set_operations(CoreObject *o, struct tcore_call_information_operations *ops); +void tcore_call_information_set_operations( CoreObject *o, struct tcore_call_information_operations *ops ); __END_DECLS diff --git a/include/co_context.h b/include/co_context.h index bf249ac..489e3ce 100644 --- a/include/co_context.h +++ b/include/co_context.h @@ -72,52 +72,60 @@ enum co_context_auth { CONTEXT_AUTH_CHAP }; -CoreObject* tcore_context_new(TcorePlugin *p, const char *name, TcoreHal *hal); -void tcore_context_free(CoreObject *o); +CoreObject *tcore_context_new(TcorePlugin *p, TcoreHal *hal); +void tcore_context_free(CoreObject *o); CoreObject *tcore_context_clone(TcorePlugin *p, const char *name, TcoreHal *hal); -TReturn tcore_context_set_state(CoreObject *o, enum co_context_state state); -enum co_context_state tcore_context_get_state(CoreObject *o); -TReturn tcore_context_set_id(CoreObject *o, unsigned int id); -unsigned int tcore_context_get_id(CoreObject *o); -TReturn tcore_context_set_role(CoreObject *o, enum co_context_role type); -enum co_context_role tcore_context_get_role(CoreObject *o); - -TReturn tcore_context_set_apn(CoreObject *o, const char *apn); -char* tcore_context_get_apn(CoreObject *o); -TReturn tcore_context_set_type(CoreObject *o, enum co_context_type type); -enum co_context_type tcore_context_get_type(CoreObject *o); -TReturn tcore_context_set_data_compression(CoreObject *o, enum co_context_d_comp comp); -enum co_context_d_comp tcore_context_get_data_compression(CoreObject *o); -TReturn tcore_context_set_header_compression(CoreObject *o, enum co_context_h_comp comp); -enum co_context_h_comp tcore_context_get_header_compression(CoreObject *o); - -TReturn tcore_context_set_username(CoreObject *o, const char *username); -char* tcore_context_get_username(CoreObject *o); -TReturn tcore_context_set_password(CoreObject *o, const char *password); -char* tcore_context_get_password(CoreObject *o); -TReturn tcore_context_set_auth(CoreObject *o, enum co_context_auth auth); -enum co_context_auth tcore_context_get_auth(CoreObject *o); -TReturn tcore_context_set_proxy(CoreObject *o, const char *proxy); -char* tcore_context_get_proxy(CoreObject *o); -TReturn tcore_context_set_mmsurl(CoreObject *o, const char *mmsurl); -char* tcore_context_get_mmsurl(CoreObject *o); -TReturn tcore_context_set_profile_name(CoreObject *o, const char *profile_name); -char* tcore_context_get_profile_name(CoreObject *o); - -TReturn tcore_context_set_devinfo(CoreObject *o, struct tnoti_ps_pdp_ipconfiguration *devinfo); -TReturn tcore_context_reset_devinfo(CoreObject *o); -void tcore_context_cp_service_info(CoreObject *dest, CoreObject *src); - -TReturn tcore_context_set_ipv4_addr(CoreObject *o, const char *addr); -char* tcore_context_get_ipv4_addr(CoreObject *o); -TReturn tcore_context_set_ipv4_dns(CoreObject *o, const char *dns1, const char *dns2); -char* tcore_context_get_ipv4_dns1(CoreObject *o); -char* tcore_context_get_ipv4_dns2(CoreObject *o); -char* tcore_context_get_ipv4_gw(CoreObject *o); -TReturn tcore_context_set_ipv4_devname(CoreObject *o, const char *name); -char* tcore_context_get_ipv4_devname(CoreObject *o); +TReturn tcore_context_set_state(CoreObject *o, enum co_context_state state); +enum co_context_state tcore_context_get_state(CoreObject *o); +TReturn tcore_context_set_id(CoreObject *o, unsigned int id); +unsigned int tcore_context_get_id(CoreObject *o); +TReturn tcore_context_set_role(CoreObject *o, enum co_context_role type); +enum co_context_role tcore_context_get_role(CoreObject *o); + +TReturn tcore_context_set_apn(CoreObject *o, const char *apn); +char *tcore_context_get_apn(CoreObject *o); + +TReturn tcore_context_set_address(CoreObject *o, const char *addr); +char *tcore_context_get_address(CoreObject *o); +TReturn tcore_context_set_dns1(CoreObject *o, const char *dns); +char *tcore_context_get_dns1(CoreObject *o); +TReturn tcore_context_set_dns2(CoreObject *o, const char *dns); +char *tcore_context_get_dns2(CoreObject *o); + +TReturn tcore_context_set_type(CoreObject *o, enum co_context_type type); +enum co_context_type tcore_context_get_type(CoreObject *o); +TReturn tcore_context_set_data_compression(CoreObject *o, enum co_context_d_comp comp); +enum co_context_d_comp tcore_context_get_data_compression(CoreObject *o); +TReturn tcore_context_set_header_compression(CoreObject *o, enum co_context_h_comp comp); +enum co_context_h_comp tcore_context_get_header_compression(CoreObject *o); + +TReturn tcore_context_set_username(CoreObject *o, const char *username); +char *tcore_context_get_username(CoreObject *o); +TReturn tcore_context_set_password(CoreObject *o, const char *password); +char *tcore_context_get_password(CoreObject *o); +TReturn tcore_context_set_auth(CoreObject *o, enum co_context_auth auth); +enum co_context_auth tcore_context_get_auth(CoreObject *o); +TReturn tcore_context_set_proxy(CoreObject *o, const char *proxy); +char *tcore_context_get_proxy(CoreObject *o); +TReturn tcore_context_set_mmsurl(CoreObject *o, const char *mmsurl); +char *tcore_context_get_mmsurl(CoreObject *o); +TReturn tcore_context_set_profile_name(CoreObject *o, const char *profile_name); +char *tcore_context_get_profile_name(CoreObject *o); + +TReturn tcore_context_set_devinfo(CoreObject *o, struct tnoti_ps_pdp_ipconfiguration *devinfo); +TReturn tcore_context_reset_devinfo(CoreObject *o); +void tcore_context_cp_service_info(CoreObject *dest, CoreObject *src); + +TReturn tcore_context_set_ipv4_addr(CoreObject *o, const char *addr); +char *tcore_context_get_ipv4_addr(CoreObject *o); +TReturn tcore_context_set_ipv4_dns(CoreObject *o, const char *dns1, const char *dns2); +char *tcore_context_get_ipv4_dns1(CoreObject *o); +char *tcore_context_get_ipv4_dns2(CoreObject *o); +char *tcore_context_get_ipv4_gw(CoreObject *o); +TReturn tcore_context_set_ipv4_devname(CoreObject *o, const char *name); +char *tcore_context_get_ipv4_devname(CoreObject *o); __END_DECLS diff --git a/include/co_gps.h b/include/co_gps.h index ddb3107..767fa4a 100644 --- a/include/co_gps.h +++ b/include/co_gps.h @@ -31,10 +31,10 @@ struct tcore_gps_operations { TReturn (*set_frequency_aiding)(CoreObject *o, UserRequest *ur); }; -CoreObject* tcore_gps_new(TcorePlugin *p, const char *name, struct tcore_gps_operations *ops, TcoreHal *hal); -void tcore_gps_free(CoreObject *o); +CoreObject *tcore_gps_new(TcorePlugin *p, + struct tcore_gps_operations *ops, TcoreHal *hal); +void tcore_gps_free(CoreObject *o); -CoreObject *tcore_gps_clone(TcorePlugin *p, const char *name, TcoreHal *hal); void tcore_gps_override_ops(CoreObject *o, struct tcore_gps_operations *gps_ops); __END_DECLS diff --git a/include/co_modem.h b/include/co_modem.h index d42d3f8..a2f334f 100644 --- a/include/co_modem.h +++ b/include/co_modem.h @@ -38,16 +38,16 @@ struct tcore_modem_operations { TReturn (*get_flight_mode)(CoreObject *o, UserRequest *ur); }; -CoreObject* tcore_modem_new(TcorePlugin *p, const char *name, struct tcore_modem_operations *ops, TcoreHal *hal); -void tcore_modem_free(CoreObject *o); +CoreObject *tcore_modem_new(TcorePlugin *p, + struct tcore_modem_operations *ops, TcoreHal *hal); +void tcore_modem_free(CoreObject *o); -CoreObject *tcore_modem_clone(TcorePlugin *p, const char *name, TcoreHal *hal); void tcore_modem_override_ops(CoreObject *o, struct tcore_modem_operations *modem_ops); -TReturn tcore_modem_set_flight_mode_state(CoreObject *o, gboolean flag); -gboolean tcore_modem_get_flight_mode_state(CoreObject *o); -TReturn tcore_modem_set_powered(CoreObject *o, gboolean pwr); -gboolean tcore_modem_get_powered(CoreObject *o); +TReturn tcore_modem_set_flight_mode_state(CoreObject *o, gboolean flag); +gboolean tcore_modem_get_flight_mode_state(CoreObject *o); +TReturn tcore_modem_set_powered(CoreObject *o, gboolean pwr); +gboolean tcore_modem_get_powered(CoreObject *o); __END_DECLS diff --git a/include/co_network.h b/include/co_network.h index eadbead..108fc7d 100644 --- a/include/co_network.h +++ b/include/co_network.h @@ -73,61 +73,59 @@ struct tcore_network_operations { TReturn (*get_neighboring_cell_info)(CoreObject *o, UserRequest *ur); }; -CoreObject* tcore_network_new(TcorePlugin *plugin, const char *name, - struct tcore_network_operations *ops, TcoreHal *hal); -void tcore_network_free(CoreObject *co); +CoreObject *tcore_network_new(TcorePlugin *plugin, + struct tcore_network_operations *ops, TcoreHal *hal); +void tcore_network_free(CoreObject *co); -CoreObject *tcore_network_clone(TcorePlugin *p, const char *name, TcoreHal *hal); void tcore_network_override_ops(CoreObject *o, struct tcore_network_operations *network_ops); -TReturn tcore_network_set_plmn(CoreObject *co, const char *plmn); -char* tcore_network_get_plmn(CoreObject *co); +TReturn tcore_network_set_plmn(CoreObject *co, const char *plmn); +char *tcore_network_get_plmn(CoreObject *co); -TReturn tcore_network_set_network_name(CoreObject *co, - enum tcore_network_name_type type, const char *network_name); -char* tcore_network_get_network_name(CoreObject *co, - enum tcore_network_name_type type); +TReturn tcore_network_set_network_name(CoreObject *co, + enum tcore_network_name_type type, const char *network_name); +char *tcore_network_get_network_name(CoreObject *co, + enum tcore_network_name_type type); -TReturn tcore_network_set_network_name_priority(CoreObject *co, - enum tcore_network_name_priority priority); -TReturn tcore_network_get_network_name_priority(CoreObject *co, - enum tcore_network_name_priority *priority); +TReturn tcore_network_set_network_name_priority(CoreObject *co, + enum tcore_network_name_priority priority); +TReturn tcore_network_get_network_name_priority(CoreObject *co, + enum tcore_network_name_priority *priority); -TReturn tcore_network_set_roaming_state(CoreObject *co, gboolean state); -gboolean tcore_network_get_roaming_state(CoreObject *co); +TReturn tcore_network_set_roaming_state(CoreObject *co, gboolean state); +gboolean tcore_network_get_roaming_state(CoreObject *co); -TReturn tcore_network_set_service_status(CoreObject *co, - enum tcore_network_service_domain_type type, - enum telephony_network_service_domain_status status); -TReturn tcore_network_get_service_status(CoreObject *co, - enum tcore_network_service_domain_type type, - enum telephony_network_service_domain_status *result); +TReturn tcore_network_set_service_status(CoreObject *co, + enum tcore_network_service_domain_type type, + enum telephony_network_service_domain_status status); +TReturn tcore_network_get_service_status(CoreObject *co, + enum tcore_network_service_domain_type type, + enum telephony_network_service_domain_status *result); -TReturn tcore_network_set_access_technology(CoreObject *co, - enum telephony_network_access_technology act); -TReturn tcore_network_get_access_technology(CoreObject *co, - enum telephony_network_access_technology *result); +TReturn tcore_network_set_access_technology(CoreObject *co, + enum telephony_network_access_technology act); +TReturn tcore_network_get_access_technology(CoreObject *co, + enum telephony_network_access_technology *result); -TReturn tcore_network_set_lac(CoreObject *co, unsigned int lac); -TReturn tcore_network_get_lac(CoreObject *co, unsigned int *result); +TReturn tcore_network_set_lac(CoreObject *co, unsigned int lac); +TReturn tcore_network_get_lac(CoreObject *co, unsigned int *result); -TReturn tcore_network_set_rac(CoreObject *co, unsigned int rac); -TReturn tcore_network_get_rac(CoreObject *co, unsigned int *result); +TReturn tcore_network_set_rac(CoreObject *co, unsigned int rac); +TReturn tcore_network_get_rac(CoreObject *co, unsigned int *result); -TReturn tcore_network_set_cell_id(CoreObject *co, unsigned int cell_id); -TReturn tcore_network_get_cell_id(CoreObject *co, unsigned int *result); +TReturn tcore_network_set_cell_id(CoreObject *co, unsigned int cell_id); +TReturn tcore_network_get_cell_id(CoreObject *co, unsigned int *result); -TReturn tcore_network_set_service_type(CoreObject *co, - enum telephony_network_service_type service_type); -TReturn tcore_network_get_service_type(CoreObject *co, - enum telephony_network_service_type *result); +TReturn tcore_network_set_service_type(CoreObject *co, + enum telephony_network_service_type service_type); +TReturn tcore_network_get_service_type(CoreObject *co, + enum telephony_network_service_type *result); -TReturn tcore_network_operator_info_add(CoreObject *co, - struct tcore_network_operator_info *noi); +TReturn tcore_network_operator_info_add(CoreObject *co, + struct tcore_network_operator_info *noi); -struct tcore_network_operator_info* - tcore_network_operator_info_find(CoreObject *co, - const char *mcc, const char *mnc); +struct tcore_network_operator_info *tcore_network_operator_info_find(CoreObject *co, + const char *mcc, const char *mnc); __END_DECLS diff --git a/include/co_phonebook.h b/include/co_phonebook.h index b7e2662..792ad2c 100644 --- a/include/co_phonebook.h +++ b/include/co_phonebook.h @@ -34,17 +34,17 @@ struct tcore_phonebook_operations { TReturn (*delete_record)(CoreObject *o, UserRequest *ur); }; -CoreObject* tcore_phonebook_new(TcorePlugin *p, const char *name, struct tcore_phonebook_operations *ops, TcoreHal *hal); -void tcore_phonebook_free(CoreObject *n); +CoreObject *tcore_phonebook_new(TcorePlugin *p, + struct tcore_phonebook_operations *ops, TcoreHal *hal); +void tcore_phonebook_free(CoreObject *n); -CoreObject *tcore_phonebook_clone(TcorePlugin *p, const char *name, TcoreHal *hal); void tcore_phonebook_override_ops(CoreObject *o, struct tcore_phonebook_operations *phonebook_ops); -gboolean tcore_phonebook_get_status(CoreObject *o); -gboolean tcore_phonebook_set_status(CoreObject *o, gboolean b_init); +gboolean tcore_phonebook_get_status(CoreObject *o); +gboolean tcore_phonebook_set_status(CoreObject *o, gboolean b_init); struct tel_phonebook_support_list* tcore_phonebook_get_support_list(CoreObject *o); -gboolean tcore_phonebook_set_support_list(CoreObject *o, struct tel_phonebook_support_list *list); +gboolean tcore_phonebook_set_support_list(CoreObject *o, struct tel_phonebook_support_list *list); enum tel_phonebook_type tcore_phonebook_get_selected_type(CoreObject *o); gboolean tcore_phonebook_set_selected_type(CoreObject *o, enum tel_phonebook_type t); diff --git a/include/co_ps.h b/include/co_ps.h index 4495441..33138d3 100644 --- a/include/co_ps.h +++ b/include/co_ps.h @@ -35,26 +35,27 @@ struct tcore_ps_operations { TReturn (*deactivate_context)(CoreObject *co_ps, CoreObject *context, void *user_data); }; -CoreObject* tcore_ps_new(TcorePlugin *p, const char *name, struct tcore_ps_operations *ops, TcoreHal *hal); -void tcore_ps_free(CoreObject *o); +CoreObject *tcore_ps_new(TcorePlugin *p, + struct tcore_ps_operations *ops, TcoreHal *hal); +void tcore_ps_free(CoreObject *o); -CoreObject *tcore_ps_clone(TcorePlugin *p, const char *name, TcoreHal *hal); void tcore_ps_override_ops(CoreObject *o, struct tcore_ps_operations *ps_ops); -TReturn tcore_ps_add_context(CoreObject *o, CoreObject *ctx_o); -TReturn tcore_ps_remove_context(CoreObject *o, CoreObject *ctx_o); -CoreObject* tcore_ps_ref_context_by_role(CoreObject *o, enum co_context_role role); -GSList* tcore_ps_ref_context_by_id(CoreObject *o, unsigned int id); +TReturn tcore_ps_add_context(CoreObject *o, CoreObject *ctx_o); +TReturn tcore_ps_remove_context(CoreObject *o, CoreObject *ctx_o); +CoreObject *tcore_ps_ref_context_by_role(CoreObject *o, enum co_context_role role); +GSList *tcore_ps_ref_context_by_id(CoreObject *o, unsigned int id); -TReturn tcore_ps_set_online(CoreObject *o, gboolean state); +TReturn tcore_ps_set_online(CoreObject *o, gboolean state); -TReturn tcore_ps_assign_context_id(CoreObject *o, CoreObject *context, unsigned int cid); -TReturn tcore_ps_clear_context_id(CoreObject *o, CoreObject *context); +TReturn tcore_ps_assign_context_id(CoreObject *o, CoreObject *context, unsigned int cid); +TReturn tcore_ps_clear_context_id(CoreObject *o, CoreObject *context); -TReturn tcore_ps_define_context(CoreObject *o, CoreObject *context, void *user_data); -TReturn tcore_ps_activate_context(CoreObject *o, CoreObject *context, void *user_data); -TReturn tcore_ps_deactivate_context(CoreObject *o, CoreObject *context, void *user_data); -TReturn tcore_ps_deactivate_contexts(CoreObject *o); +TReturn tcore_ps_define_context(CoreObject *o, CoreObject *ps_context, void *user_data); + +TReturn tcore_ps_activate_context(CoreObject *o, CoreObject *context, void *user_data); +TReturn tcore_ps_deactivate_context(CoreObject *o, CoreObject *context, void *user_data); +TReturn tcore_ps_deactivate_contexts(CoreObject *o); __END_DECLS diff --git a/include/co_sap.h b/include/co_sap.h index 5647374..cc12358 100644 --- a/include/co_sap.h +++ b/include/co_sap.h @@ -36,10 +36,10 @@ struct tcore_sap_operations { TReturn (*get_cardreader_status)(CoreObject *o, UserRequest *ur); }; -CoreObject* tcore_sap_new(TcorePlugin *p, const char *name, struct tcore_sap_operations *ops, TcoreHal *hal); -void tcore_sap_free(CoreObject *o); +CoreObject *tcore_sap_new(TcorePlugin *p, + struct tcore_sap_operations *ops, TcoreHal *hal); +void tcore_sap_free(CoreObject *o); -CoreObject *tcore_sap_clone(TcorePlugin *p, const char *name, TcoreHal *hal); void tcore_sap_override_ops(CoreObject *o, struct tcore_sap_operations *sap_ops); __END_DECLS diff --git a/include/co_sat.h b/include/co_sat.h index 856a1f3..4ff5cf5 100644 --- a/include/co_sat.h +++ b/include/co_sat.h @@ -72,7 +72,8 @@ struct tcore_sat_proactive_command { TelSatCloseChannelIndInfo_t closeChannel; TelSatReceiveDataIndInfo_t receiveData; TelSatSendDataIndInfo_t sendData; - TelSatGetChannelStatusIndInfo_t getChannelStatus;*/ + TelSatGetChannelStatusIndInfo_t getChannelStatus; +*/ } data; }; @@ -85,10 +86,10 @@ int tcore_sat_decode_proactive_command(unsigned char* tlv_origin, unsigned int t int tcore_sat_encode_envelop_cmd(const struct treq_sat_envelop_cmd_data *src_envelop, char *dst_envelop); int tcore_sat_encode_terminal_response(const struct treq_sat_terminal_rsp_data *src_tr, char *dst_tr); -CoreObject* tcore_sat_new(TcorePlugin *p, const char *name, struct tcore_sat_operations *ops, TcoreHal *hal); -void tcore_sat_free(CoreObject *n); +CoreObject *tcore_sat_new(TcorePlugin *p, + struct tcore_sat_operations *ops, TcoreHal *hal); +void tcore_sat_free(CoreObject *n); -CoreObject *tcore_sat_clone(TcorePlugin *p, const char *name, TcoreHal *hal); void tcore_sat_override_ops(CoreObject *o, struct tcore_sat_operations *sat_ops); #endif diff --git a/include/co_sim.h b/include/co_sim.h index eebb1cd..f761916 100644 --- a/include/co_sim.h +++ b/include/co_sim.h @@ -40,73 +40,74 @@ struct tcore_sim_operations { TReturn (*req_authentication)(CoreObject *o, UserRequest *ur); }; -CoreObject* tcore_sim_new(TcorePlugin *p, const char *name, struct tcore_sim_operations *ops, TcoreHal *hal); -void tcore_sim_free(CoreObject *n); +CoreObject *tcore_sim_new(TcorePlugin *p, + struct tcore_sim_operations *ops, TcoreHal *hal); +void tcore_sim_free(CoreObject *n); -CoreObject *tcore_sim_clone(TcorePlugin *p, const char *name, TcoreHal *hal); -void tcore_sim_override_ops(CoreObject *o, struct tcore_sim_operations *sim_ops); +void tcore_sim_override_ops(CoreObject *o, + struct tcore_sim_operations *sim_ops); -enum tel_sim_type tcore_sim_get_type(CoreObject *o); -gboolean tcore_sim_set_type(CoreObject *o, enum tel_sim_type type); +enum tel_sim_type tcore_sim_get_type(CoreObject *o); +gboolean tcore_sim_set_type(CoreObject *o, enum tel_sim_type type); -struct tel_sim_imsi* tcore_sim_get_imsi(CoreObject *o); -gboolean tcore_sim_set_imsi(CoreObject *o, struct tel_sim_imsi *imsi); +struct tel_sim_imsi *tcore_sim_get_imsi(CoreObject *o); +gboolean tcore_sim_set_imsi(CoreObject *o, struct tel_sim_imsi *imsi); -enum tel_sim_status tcore_sim_get_status(CoreObject *o); -gboolean tcore_sim_set_status(CoreObject *o, enum tel_sim_status status); +enum tel_sim_status tcore_sim_get_status(CoreObject *o); +gboolean tcore_sim_set_status(CoreObject *o, enum tel_sim_status status); -gboolean tcore_sim_get_identification(CoreObject *o); -gboolean tcore_sim_set_identification(CoreObject *o, gboolean b_changed); +gboolean tcore_sim_get_identification(CoreObject *o); +gboolean tcore_sim_set_identification(CoreObject *o, gboolean b_changed); -struct tel_sim_service_table* tcore_sim_get_service_table(CoreObject *o); +struct tel_sim_service_table *tcore_sim_get_service_table(CoreObject *o); gboolean tcore_sim_set_service_table(CoreObject *o, struct tel_sim_service_table *svct); -gboolean tcore_sim_get_cphs_status(CoreObject *o); -gboolean tcore_sim_set_cphs_status(CoreObject *o, gboolean b_support); - -gboolean tcore_sim_link_userdata(CoreObject *o, void *userdata); -void* tcore_sim_ref_userdata(CoreObject *o); - -gboolean tcore_sim_decode_iccid(struct tel_sim_iccid *p_out, unsigned char *p_in, int in_length); -gboolean tcore_sim_decode_lp(struct tel_sim_language *p_out, unsigned char *p_in, int in_length); -char* tcore_sim_encode_lp(int *out_length, struct tel_sim_language *p_in); -gboolean tcore_sim_decode_li(enum tel_sim_file_id file_id, struct tel_sim_language *p_out, unsigned char *p_in, int in_length); -char* tcore_sim_encode_li(int *out_length, struct tel_sim_language *p_in); -gboolean tcore_sim_decode_imsi(struct tel_sim_imsi *p_out, unsigned char *p_in, int in_length); -gboolean tcore_sim_decode_sst(struct tel_sim_sst *p_sst, unsigned char *p_in, int in_length); -gboolean tcore_sim_decode_spn(struct tel_sim_spn *p_spn, unsigned char *p_in, int in_length); -gboolean tcore_sim_decode_spdi(struct tel_sim_spdi *p_spdi, unsigned char *p_in, int in_length); -gboolean tcore_sim_decode_msisdn(struct tel_sim_msisdn *p_msisdn, unsigned char *p_in, int in_length); -gboolean tcore_sim_decode_xdn(struct tel_sim_dialing_number *p_xdn, unsigned char *p_in, int in_length); -char* tcore_sim_encode_xdn(int out_length, struct tel_sim_dialing_number *p_xdn); -gboolean tcore_sim_decode_ecc(struct tel_sim_ecc_list *p_ecc, unsigned char *p_in, int in_length); -gboolean tcore_sim_decode_ust(struct tel_sim_ust *p_ust, unsigned char *p_in, int in_length); -gboolean tcore_sim_decode_est(struct tel_sim_est *p_est, unsigned char *p_in, int in_length); -gboolean tcore_sim_decode_uecc(struct tel_sim_ecc *p_ecc, unsigned char* p_in, int in_length); -gboolean tcore_sim_decode_gid( struct tel_sim_gid *p_gid, unsigned char* p_in, int in_length); -gboolean tcore_sim_decode_mbi(struct tel_sim_mbi *p_mbi, unsigned char *p_in, int in_length); -gboolean tcore_sim_encode_mbi(char *p_out, int out_length, struct tel_sim_mbi *p_mbi); -gboolean tcore_sim_decode_mwis(struct tel_sim_mw *pMwis, unsigned char *p_in, int in_length); -char* tcore_sim_encode_mwis(int *out_length, const struct tel_sim_mw *pMwis); -gboolean tcore_sim_decode_vmwf(struct tel_sim_cphs_mw *p_vmwf, unsigned char* p_in, unsigned long in_length); -char* tcore_sim_encode_vmwf(int *out_length, const struct tel_sim_cphs_mw *p_vmwf); -gboolean tcore_sim_decode_cfis(struct tel_sim_cfis *cfis, unsigned char *p_in, int in_length); -char* tcore_sim_encode_cfis(int *out_length, const struct tel_sim_cfis *p_cfis); -gboolean tcore_sim_decode_cff(struct tel_sim_cphs_cf *cfis, unsigned char *p_in, int in_length); -char* tcore_sim_encode_cff(const struct tel_sim_cphs_cf *cff); -gboolean tcore_sim_decode_csp(struct tel_sim_cphs_csp *p_csp, unsigned char *p_in, int in_length); -gboolean tcore_sim_encode_csp(unsigned char *p_out, int out_length, struct tel_sim_cphs_csp *p_csp); -gboolean tcore_sim_decode_dynamic_flag(struct tel_sim_cphs_dflag *p_df, unsigned char *p_in, int in_length); -gboolean tcore_sim_encode_dynamic_flag(char *p_out, int out_length, struct tel_sim_cphs_dflag *p_df); -gboolean tcore_sim_decode_dynamic2_flag(struct tel_sim_cphs_dflag2 *p_d2f, unsigned char *p_in, int in_length); -gboolean tcore_sim_encode_dynamic2_flag(char *p_out, int out_length, struct tel_sim_cphs_dflag2 *p_d2f); -gboolean tcore_sim_decode_cphs_info(struct tel_sim_cphs_info *pCphsInfo, unsigned char *p_in, int in_length); -gboolean tcore_sim_decode_short_ons(unsigned char *p_out, unsigned char *p_in, int in_length); -gboolean tcore_sim_decode_ons(unsigned char *p_out, unsigned char *p_in, int in_length); -gboolean tcore_sim_decode_information_number(struct tel_sim_cphs_info_number *p_info, unsigned char* p_in, int in_length); -gboolean tcore_sim_decode_opl(struct tel_sim_opl *p_opl, unsigned char *p_in, int in_length); -gboolean tcore_sim_decode_pnn(struct tel_sim_pnn *p_pnn, unsigned char* p_in, int in_length); -gboolean tcore_sim_decode_oplmnwact(struct tel_sim_oplmnwact_list *p_list, unsigned char *p_in, int in_length); +gboolean tcore_sim_get_cphs_status(CoreObject *o); +gboolean tcore_sim_set_cphs_status(CoreObject *o, gboolean b_support); + +gboolean tcore_sim_link_userdata(CoreObject *o, void *userdata); +void *tcore_sim_ref_userdata(CoreObject *o); + +gboolean tcore_sim_decode_iccid(struct tel_sim_iccid *p_out, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_lp(struct tel_sim_language *p_out, unsigned char *p_in, int in_length); +char *tcore_sim_encode_lp(int *out_length, struct tel_sim_language *p_in); +gboolean tcore_sim_decode_li(enum tel_sim_file_id file_id, struct tel_sim_language *p_out, unsigned char *p_in, int in_length); +char *tcore_sim_encode_li(int *out_length, struct tel_sim_language *p_in); +gboolean tcore_sim_decode_imsi(struct tel_sim_imsi *p_out, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_sst(struct tel_sim_sst *p_sst, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_spn(struct tel_sim_spn *p_spn, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_spdi(struct tel_sim_spdi *p_spdi, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_msisdn(struct tel_sim_msisdn *p_msisdn, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_xdn(struct tel_sim_dialing_number *p_xdn, unsigned char *p_in, int in_length); +char *tcore_sim_encode_xdn(int out_length, struct tel_sim_dialing_number *p_xdn); +gboolean tcore_sim_decode_ecc(struct tel_sim_ecc_list *p_ecc, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_ust(struct tel_sim_ust *p_ust, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_est(struct tel_sim_est *p_est, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_uecc(struct tel_sim_ecc *p_ecc, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_gid( struct tel_sim_gid *p_gid, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_mbi(struct tel_sim_mbi *p_mbi, unsigned char *p_in, int in_length); +gboolean tcore_sim_encode_mbi(char *p_out, int out_length, struct tel_sim_mbi *p_mbi); +gboolean tcore_sim_decode_mwis(struct tel_sim_mw *pMwis, unsigned char *p_in, int in_length); +char *tcore_sim_encode_mwis(int *out_length, const struct tel_sim_mw *pMwis); +gboolean tcore_sim_decode_vmwf(struct tel_sim_cphs_mw *p_vmwf, unsigned char *p_in, unsigned long in_length); +char *tcore_sim_encode_vmwf(int *out_length, const struct tel_sim_cphs_mw *p_vmwf); +gboolean tcore_sim_decode_cfis(struct tel_sim_cfis *cfis, unsigned char *p_in, int in_length); +char *tcore_sim_encode_cfis(int *out_length, const struct tel_sim_cfis *p_cfis); +gboolean tcore_sim_decode_cff(struct tel_sim_cphs_cf *cfis, unsigned char *p_in, int in_length); +char *tcore_sim_encode_cff(const struct tel_sim_cphs_cf *cff); +gboolean tcore_sim_decode_csp(struct tel_sim_cphs_csp *p_csp, unsigned char *p_in, int in_length); +gboolean tcore_sim_encode_csp(unsigned char *p_out, int out_length, struct tel_sim_cphs_csp *p_csp); +gboolean tcore_sim_decode_dynamic_flag(struct tel_sim_cphs_dflag *p_df, unsigned char *p_in, int in_length); +gboolean tcore_sim_encode_dynamic_flag(char *p_out, int out_length, struct tel_sim_cphs_dflag *p_df); +gboolean tcore_sim_decode_dynamic2_flag(struct tel_sim_cphs_dflag2 *p_d2f, unsigned char *p_in, int in_length); +gboolean tcore_sim_encode_dynamic2_flag(char *p_out, int out_length, struct tel_sim_cphs_dflag2 *p_d2f); +gboolean tcore_sim_decode_cphs_info(struct tel_sim_cphs_info *pCphsInfo, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_short_ons(unsigned char *p_out, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_ons(unsigned char *p_out, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_information_number(struct tel_sim_cphs_info_number *p_info, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_opl(struct tel_sim_opl *p_opl, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_pnn(struct tel_sim_pnn *p_pnn, unsigned char *p_in, int in_length); +gboolean tcore_sim_decode_oplmnwact(struct tel_sim_oplmnwact_list *p_list, unsigned char *p_in, int in_length); __END_DECLS diff --git a/include/co_sms.h b/include/co_sms.h index 25da8e1..09770c3 100644 --- a/include/co_sms.h +++ b/include/co_sms.h @@ -67,13 +67,14 @@ struct tcore_sms_operations { }; -int _tcore_util_sms_encode_smsParameters(const struct telephony_sms_Params *incoming, unsigned char *data, int SMSPRecordLen); -gboolean tcore_sms_get_ready_status(CoreObject *o); -gboolean tcore_sms_set_ready_status(CoreObject *o, int status); -CoreObject* tcore_sms_new(TcorePlugin *p, const char *name, struct tcore_sms_operations *ops, TcoreHal *hal); -void tcore_sms_free(CoreObject * n); +int _tcore_util_sms_encode_smsParameters(const struct telephony_sms_Params *incoming, unsigned char *data, int SMSPRecordLen); +gboolean tcore_sms_get_ready_status(CoreObject *o); +gboolean tcore_sms_set_ready_status(CoreObject *o, int status); + +CoreObject* tcore_sms_new(TcorePlugin *p, + struct tcore_sms_operations *ops, TcoreHal *hal); +void tcore_sms_free(CoreObject * n); -CoreObject *tcore_sms_clone(TcorePlugin *p, const char *name, TcoreHal *hal); void tcore_sms_override_ops(CoreObject *o, struct tcore_sms_operations *sms_ops); __END_DECLS diff --git a/include/co_ss.h b/include/co_ss.h index 165b971..fa4367d 100644 --- a/include/co_ss.h +++ b/include/co_ss.h @@ -95,7 +95,7 @@ enum tcore_ss_class { enum tcore_ss_status { TCORE_SS_STATUS_REG = 0x01, /* 0x01 : Registration */ - TCORE_SS_STATUS_DEREG, /* 0x02 : De-registration( erase ) */ + TCORE_SS_STATUS_DEREG, /* 0x02 : De-registration(erase) */ TCORE_SS_STATUS_ACTIVATE, /* 0x03 : Activation */ TCORE_SS_STATUS_DEACTIVATE, /* 0x04 : De-activation */ TCORE_SS_STATUS_MAX @@ -176,19 +176,22 @@ struct tcore_ss_operations { }; -CoreObject* tcore_ss_new(TcorePlugin *p, const char *name, struct tcore_ss_operations *ops, TcoreHal *hal); -void tcore_ss_free(CoreObject *o); +CoreObject *tcore_ss_new(TcorePlugin *p, + struct tcore_ss_operations *ops, TcoreHal *hal); +void tcore_ss_free(CoreObject *o); -CoreObject *tcore_ss_clone(TcorePlugin *p, const char *name, TcoreHal *hal); void tcore_ss_override_ops(CoreObject *o, struct tcore_ss_operations *ss_ops); -struct ussd_session* tcore_ss_ussd_create_session( CoreObject *o, enum tcore_ss_ussd_type type, void *data, int data_len ); -void tcore_ss_ussd_destroy_session( struct ussd_session *ussd_s ); -struct ussd_session* tcore_ss_ussd_get_session( CoreObject *o ); -enum tcore_ss_ussd_type tcore_ss_ussd_get_session_type( struct ussd_session* ussd_s ); -void tcore_ss_ussd_set_session_type( struct ussd_session* ussd_s, enum tcore_ss_ussd_type type ); -int tcore_ss_ussd_get_session_data( struct ussd_session* ussd_s, void** data ); -void tcore_ss_ussd_set_session_data( struct ussd_session* ussd_s, void* data, int data_len ); +struct ussd_session *tcore_ss_ussd_create_session(CoreObject *o, + enum tcore_ss_ussd_type type, void *data, int data_len); +void tcore_ss_ussd_destroy_session(struct ussd_session *ussd_s); +struct ussd_session *tcore_ss_ussd_get_session(CoreObject *o); +enum tcore_ss_ussd_type tcore_ss_ussd_get_session_type(struct ussd_session* ussd_s); +void tcore_ss_ussd_set_session_type(struct ussd_session* ussd_s, + enum tcore_ss_ussd_type type); +int tcore_ss_ussd_get_session_data(struct ussd_session* ussd_s, void** data); +void tcore_ss_ussd_set_session_data(struct ussd_session* ussd_s, + void* data, int data_len); __END_DECLS diff --git a/include/core_object.h b/include/core_object.h index 991da72..8f287b3 100644 --- a/include/core_object.h +++ b/include/core_object.h @@ -23,45 +23,89 @@ __BEGIN_DECLS -#define CORE_OBJECT_TYPE_DEFAULT 0xB0000000 -#define CORE_OBJECT_TYPE_MODEM (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_MODEM) -#define CORE_OBJECT_TYPE_CALL (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_CALL) -#define CORE_OBJECT_TYPE_SS (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SS) -#define CORE_OBJECT_TYPE_NETWORK (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_NETWORK) -#define CORE_OBJECT_TYPE_PS (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_PS) -#define CORE_OBJECT_TYPE_PS_CONTEXT (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_PDP) -#define CORE_OBJECT_TYPE_SIM (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SIM) -#define CORE_OBJECT_TYPE_SAT (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SAT) -#define CORE_OBJECT_TYPE_SAP (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SAP) -#define CORE_OBJECT_TYPE_SMS (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SMS) -#define CORE_OBJECT_TYPE_PHONEBOOK (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_PHONEBOOK) -#define CORE_OBJECT_TYPE_SOUND (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SOUND) -#define CORE_OBJECT_TYPE_CUSTOM (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_CUSTOM) -#define CORE_OBJECT_TYPE_GPS (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_GPS) - -#define CORE_OBJECT_CHECK(o,t) \ - if (!o) { warn("core_object is NULL"); return; } \ - if (tcore_object_get_type(o) != t) { warn("type(0x%x != 0x%x) mismatch", tcore_object_get_type(o), t); return; } -#define CORE_OBJECT_CHECK_RETURN(o,t,r) \ - if (!o) { warn("core_object is NULL"); return r; } \ - if (tcore_object_get_type(o) != t) { warn("type(0x%x != 0x%x) mismatch", tcore_object_get_type(o), t); return r; } - -typedef void (*CoreObjectFreeHook)(CoreObject *co); -typedef void (*CoreObjectCloneHook)(CoreObject *src, CoreObject *dest); -typedef gboolean (*CoreObjectCallback)(CoreObject *co, const void *event_info, void *user_data); -typedef TReturn (*CoreObjectDispatcher)(CoreObject *co, UserRequest *ur); - -CoreObject *tcore_object_new(TcorePlugin *plugin, const char *name, TcoreHal *hal); +#define CORE_OBJECT_TYPE_DEFAULT 0xB0000000 +#define CORE_OBJECT_TYPE_MODEM (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_MODEM) +#define CORE_OBJECT_TYPE_CALL (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_CALL) +#define CORE_OBJECT_TYPE_SS (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SS) +#define CORE_OBJECT_TYPE_NETWORK (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_NETWORK) +#define CORE_OBJECT_TYPE_PS (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_PS) +#define CORE_OBJECT_TYPE_PS_CONTEXT (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_PDP) +#define CORE_OBJECT_TYPE_SIM (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SIM) +#define CORE_OBJECT_TYPE_SAT (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SAT) +#define CORE_OBJECT_TYPE_SAP (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SAP) +#define CORE_OBJECT_TYPE_SMS (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SMS) +#define CORE_OBJECT_TYPE_PHONEBOOK (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_PHONEBOOK) +#define CORE_OBJECT_TYPE_SOUND (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SOUND) +#define CORE_OBJECT_TYPE_CUSTOM (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_CUSTOM) +#define CORE_OBJECT_TYPE_GPS (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_GPS) + +#define CORE_OBJECT_CHECK(co,t) \ + if (co == NULL) { warn("core_object is NULL"); return; } \ + if (tcore_object_get_type(co) != t) { \ + warn("type(0x%x != 0x%x) mismatch", tcore_object_get_type(co), t); \ + return; \ + } + +#define CORE_OBJECT_CHECK_RETURN(co,t,r) \ + if (co == NULL) { warn("core_object is NULL"); return r; } \ + if (tcore_object_get_type(co) != t) { \ + warn("type(0x%x != 0x%x) mismatch", tcore_object_get_type(co), t); \ + return r; \ + } + +typedef struct tcore_object_mapping_tbl object_mapping_table_t; + +typedef void (*tcore_object_free_hook)(CoreObject *co); +typedef void (*tcore_object_clone_hook)(CoreObject *src, CoreObject *dest); +typedef gboolean (*tcore_object_callback)(CoreObject *co, + const void *event_info, void *user_data); +typedef TReturn (*tcore_object_dispatcher)(CoreObject *co, UserRequest *ur); + + +typedef gboolean (*tcore_object_init)(TcorePlugin *plugin, CoreObject *co); +typedef void (*tcore_object_deinit)(TcorePlugin *plugin, CoreObject *co); + +/* Core Object Initializers */ +struct object_initializer { + tcore_object_init modem_init; + tcore_object_init sim_init; + tcore_object_init sat_init; + tcore_object_init sap_init; + tcore_object_init network_init; + tcore_object_init ps_init; + tcore_object_init call_init; + tcore_object_init ss_init; + tcore_object_init sms_init; + tcore_object_init phonebook_init; + tcore_object_init gps_init; + /* To be updated based on New modules */ +}; + +/* Core Object De-initializers */ +struct object_deinitializer { + tcore_object_deinit modem_deinit; + tcore_object_deinit sim_deinit; + tcore_object_deinit sat_deinit; + tcore_object_deinit sap_deinit; + tcore_object_deinit network_deinit; + tcore_object_deinit ps_deinit; + tcore_object_deinit call_deinit; + tcore_object_deinit ss_deinit; + tcore_object_deinit sms_deinit; + tcore_object_deinit phonebook_deinit; + tcore_object_deinit gps_deinit; + /* To be updated based on New modules */ +}; + +CoreObject *tcore_object_new(TcorePlugin *plugin, TcoreHal *hal); void tcore_object_free(CoreObject *co); -TReturn tcore_object_set_free_hook(CoreObject *co, CoreObjectFreeHook free_hook); -TReturn tcore_object_set_clone_hook(CoreObject *co, CoreObjectCloneHook clone_hook); +TReturn tcore_object_set_free_hook(CoreObject *co, tcore_object_free_hook free_hook); +TReturn tcore_object_set_clone_hook(CoreObject *co, tcore_object_clone_hook clone_hook); -CoreObject *tcore_object_clone(CoreObject *src, TcorePlugin *new_parent, const char *new_name); -CoreObject *tcore_object_clone_template_object(TcorePlugin *p, const char *co_name, unsigned int co_type); - -TReturn tcore_object_set_name(CoreObject *co, const char *name); -const char *tcore_object_ref_name(CoreObject *co); +CoreObject *tcore_object_clone(CoreObject *src, TcorePlugin *new_parent); +CoreObject *tcore_object_clone_template_object(TcorePlugin *p, + unsigned int co_type); TReturn tcore_object_set_plugin(CoreObject *co, TcorePlugin *plugin); TcorePlugin *tcore_object_ref_plugin(CoreObject *co); @@ -78,14 +122,26 @@ TcoreHal *tcore_object_get_hal(CoreObject *co); TReturn tcore_object_link_user_data(CoreObject *co, void *user_data); void *tcore_object_ref_user_data(CoreObject *co); -TReturn tcore_object_set_dispatcher(CoreObject *co, CoreObjectDispatcher func); +TReturn tcore_object_set_dispatcher(CoreObject *co, tcore_object_dispatcher func); TReturn tcore_object_dispatch_request(CoreObject *co, UserRequest *ur); -TReturn tcore_object_add_callback(CoreObject *co, const char *event, CoreObjectCallback callback, void *user_data); -TReturn tcore_object_del_callback(CoreObject *co, const char *event, CoreObjectCallback callback); -TReturn tcore_object_override_callback(CoreObject *co, const char *event, CoreObjectCallback callback, void *user_data); +TReturn tcore_object_add_callback(CoreObject *co, const char *event, tcore_object_callback callback, void *user_data); +TReturn tcore_object_del_callback(CoreObject *co, const char *event, tcore_object_callback callback); +TReturn tcore_object_override_callback(CoreObject *co, const char *event, tcore_object_callback callback, void *user_data); TReturn tcore_object_emit_callback(CoreObject *co, const char *event, const void *event_info); +gboolean tcore_object_add_mapping_tbl_entry(void *mapping_tbl, + unsigned int object_type, TcoreHal *hal); +void tcore_object_remove_mapping_tbl_entry(void *mapping_tbl, TcoreHal *hal); +void tcore_object_remove_mapping_tbl_entry_by_type(void *mapping_tbl, + unsigned int co_type); + +TReturn tcore_object_init_objects(TcorePlugin *plugin, + struct object_initializer *initializer_list); +void tcore_object_deinit_objects(TcorePlugin *plugin, + struct object_deinitializer *deinitializer_list); + + __END_DECLS #endif diff --git a/include/hal.h b/include/hal.h index e2e8644..f5bacc9 100644 --- a/include/hal.h +++ b/include/hal.h @@ -50,48 +50,45 @@ struct tcore_hal_operations { gboolean enable); }; -TcoreHal* tcore_hal_new(TcorePlugin *plugin, const char *name, - struct tcore_hal_operations *hops, - enum tcore_hal_mode mode); -void tcore_hal_free(TcoreHal *hal); +TcoreHal *tcore_hal_new(TcorePlugin *plugin, const char *name, + struct tcore_hal_operations *hops, + enum tcore_hal_mode mode); +void tcore_hal_free(TcoreHal *hal); -TReturn tcore_hal_set_name(TcoreHal *hal, const char *name); -char* tcore_hal_get_name(TcoreHal *hal); +TReturn tcore_hal_set_name(TcoreHal *hal, const char *name); +char *tcore_hal_get_name(TcoreHal *hal); -TcoreAT* tcore_hal_get_at(TcoreHal *hal); +TcoreAT *tcore_hal_get_at(TcoreHal *hal); enum tcore_hal_mode tcore_hal_get_mode(TcoreHal *hal); -TReturn tcore_hal_set_mode(TcoreHal *hal, enum tcore_hal_mode mode); +TReturn tcore_hal_set_mode(TcoreHal *hal, enum tcore_hal_mode mode); -TReturn tcore_hal_set_power(TcoreHal *hal, gboolean flag); +TReturn tcore_hal_set_power(TcoreHal *hal, gboolean flag); -TReturn tcore_hal_link_user_data(TcoreHal *hal, void *user_data); -void* tcore_hal_ref_user_data(TcoreHal *hal); +TReturn tcore_hal_link_user_data(TcoreHal *hal, void *user_data); +void *tcore_hal_ref_user_data(TcoreHal *hal); -TReturn tcore_hal_send_data(TcoreHal *hal, unsigned int data_len, void *data); -TReturn tcore_hal_send_request(TcoreHal *hal, TcorePending *pending); -TReturn tcore_hal_send_force(TcoreHal *hal); +TReturn tcore_hal_send_data(TcoreHal *hal, unsigned int data_len, void *data); +TReturn tcore_hal_send_request(TcoreHal *hal, TcorePending *pending); +TReturn tcore_hal_send_force(TcoreHal *hal); -TReturn tcore_hal_dispatch_response_data(TcoreHal *hal, int id, - unsigned int data_len, const void *data); +TReturn tcore_hal_dispatch_response_data(TcoreHal *hal, int id, + unsigned int data_len, const void *data); -TReturn tcore_hal_add_recv_callback(TcoreHal *hal, - TcoreHalReceiveCallback func, void *user_data); -TReturn tcore_hal_remove_recv_callback(TcoreHal *hal, - TcoreHalReceiveCallback func); -TReturn tcore_hal_emit_recv_callback(TcoreHal *hal, - unsigned int data_len, const void *data); +TReturn tcore_hal_add_recv_callback(TcoreHal *hal, TcoreHalReceiveCallback func, + void *user_data); +TReturn tcore_hal_remove_recv_callback(TcoreHal *hal, TcoreHalReceiveCallback func); +TReturn tcore_hal_emit_recv_callback(TcoreHal *hal, unsigned int data_len, + const void *data); +TReturn tcore_hal_add_send_hook(TcoreHal *hal, TcoreHalSendHook func, void *user_data); +TReturn tcore_hal_remove_send_hook(TcoreHal *hal, TcoreHalSendHook func); -TReturn tcore_hal_add_send_hook(TcoreHal *hal, TcoreHalSendHook func, - void *user_data); -TReturn tcore_hal_remove_send_hook(TcoreHal *hal, TcoreHalSendHook func); +TReturn tcore_hal_set_power_state(TcoreHal *hal, gboolean flag); +gboolean tcore_hal_get_power_state(TcoreHal *hal); -TReturn tcore_hal_set_power_state(TcoreHal *hal, gboolean flag); -gboolean tcore_hal_get_power_state(TcoreHal *hal); +TcoreQueue *tcore_hal_ref_queue(TcoreHal *hal); +TcorePlugin *tcore_hal_ref_plugin(TcoreHal *hal); -TcoreQueue* tcore_hal_ref_queue(TcoreHal *hal); -TcorePlugin* tcore_hal_ref_plugin(TcoreHal *hal); - -TReturn tcore_hal_setup_netif(TcoreHal *hal, CoreObject *co, +TReturn tcore_hal_setup_netif(TcoreHal *hal, CoreObject *co, TcoreHalSetupNetifCallback func, void *user_data, unsigned int cid, gboolean enable); diff --git a/include/mux.h b/include/mux.h index 1b11776..6fb0daa 100644 --- a/include/mux.h +++ b/include/mux.h @@ -21,8 +21,41 @@ #ifndef __MUX_H__ #define __MUX_H__ -TReturn tcore_cmux_init(TcorePlugin *plugin, TcoreHal *hal); -void tcore_cmux_close(void); -int tcore_cmux_rcv_from_hal(unsigned char *data, size_t length); +#include "queue.h" + +/* CMUX modes */ +typedef enum { + CMUX_MODE_BASIC = 0x00, + CMUX_MODE_ADVANCED +} tcore_cmux_mode; + +/* CMUX Channel */ +typedef struct cmux_channel tcore_cmux_channel; + +/* Global MUX Object */ +typedef struct cmux_obj tcore_cmux_object; + +/* Internal CMUX setup complete callback prototype */ +typedef void (*cmux_setup_complete_cb_func) (gpointer user_data); + +/* CMUX setup callback prototype */ +typedef void (*cmux_setup_cb_func) (int channel_id, TcoreHal *hal, + gpointer user_data); + +/* CMUX initialization - Internal and Kernel */ +TReturn tcore_cmux_init(TcoreHal *phy_hal, unsigned int frame_size, + TcorePendingResponseCallback resp_cb, void *resp_cb_data); + +/* Setup Internal CMUX */ +TReturn tcore_cmux_setup_internal_mux(tcore_cmux_mode mode, + int max_channels, unsigned int cmux_buf_size, TcoreHal *phy_hal, + cmux_setup_cb_func channel_setup_cb, gpointer channel_setup_user_data, + cmux_setup_complete_cb_func setup_complete_cb, gpointer setup_complete_user_data); + +/* Close CMUX */ +void tcore_cmux_close(TcoreHal *phy_hal); + +/* HAL Receive for Internal CMUX */ +void tcore_cmux_rcv_from_hal(TcoreHal *hal, unsigned char *data, size_t length); #endif /* __MUX_H__ */ diff --git a/include/plugin.h b/include/plugin.h index f4eded2..47d12aa 100644 --- a/include/plugin.h +++ b/include/plugin.h @@ -39,32 +39,31 @@ struct tcore_plugin_define_desc { }; -TcorePlugin* tcore_plugin_new(Server *server, - const struct tcore_plugin_define_desc *desc, - const char *filename, void *handle); -void tcore_plugin_free(TcorePlugin *plugin); +TcorePlugin *tcore_plugin_new(Server *server, + const struct tcore_plugin_define_desc *desc, + const char *filename, void *handle); +void tcore_plugin_free(TcorePlugin *plugin); -const struct tcore_plugin_define_desc* - tcore_plugin_get_description(TcorePlugin *plugin); +const struct tcore_plugin_define_desc *tcore_plugin_get_description(TcorePlugin *plugin); -char* tcore_plugin_get_filename(TcorePlugin *plugin); -char* tcore_plugin_ref_plugin_name(TcorePlugin *plugin); -Server* tcore_plugin_ref_server(TcorePlugin *plugin); +char *tcore_plugin_get_filename(TcorePlugin *plugin); +char *tcore_plugin_ref_plugin_name(TcorePlugin *plugin); +Server *tcore_plugin_ref_server(TcorePlugin *plugin); -TReturn tcore_plugin_link_user_data(TcorePlugin *plugin, void *user_data); -void* tcore_plugin_ref_user_data(TcorePlugin *plugin); +TReturn tcore_plugin_link_user_data(TcorePlugin *plugin, void *user_data); +void *tcore_plugin_ref_user_data(TcorePlugin *plugin); -TReturn tcore_plugin_add_core_object(TcorePlugin *plugin, CoreObject *co); -CoreObject* tcore_plugin_ref_core_object(TcorePlugin *plugin, const char *name); -GSList* tcore_plugin_get_core_objects_bytype(TcorePlugin *plugin, - unsigned int type); +TReturn tcore_plugin_add_core_object(TcorePlugin *plugin, CoreObject *co); +CoreObject *tcore_plugin_ref_core_object(TcorePlugin *plugin, unsigned int type); +GSList *tcore_plugin_get_core_objects_bytype(TcorePlugin *plugin, + unsigned int type); -TReturn tcore_plugin_core_object_event_emit(TcorePlugin *plugin, - const char *event, const void *event_info); +TReturn tcore_plugin_core_object_event_emit(TcorePlugin *plugin, + const char *event, const void *event_info); -TReturn tcore_plugin_link_property(TcorePlugin *plugin, const char *key, - void *data); -void* tcore_plugin_ref_property(TcorePlugin *plugin, const char *key); +TReturn tcore_plugin_link_property(TcorePlugin *plugin, const char *key, + void *data); +void *tcore_plugin_ref_property(TcorePlugin *plugin, const char *key); __END_DECLS diff --git a/include/server.h b/include/server.h index 1292824..2570ac6 100644 --- a/include/server.h +++ b/include/server.h @@ -23,56 +23,66 @@ __BEGIN_DECLS -typedef enum tcore_hook_return (*TcoreServerRequestHook)(Server *s, - UserRequest *ur, void *user_data); -typedef enum tcore_hook_return (*TcoreServerNotificationHook)(Server *s, - CoreObject *source, enum tcore_notification_command command, - unsigned int data_len, void *data, void *user_data); +typedef enum tcore_hook_return (*tcore_server_request_hook)(Server *s, + UserRequest *ur, void *user_data); +typedef enum tcore_hook_return (*tcore_server_notification_hook)(Server *s, + CoreObject *source, enum tcore_notification_command command, + unsigned int data_len, void *data, void *user_data); -Server* tcore_server_new(); -void tcore_server_free(Server *s); +Server *tcore_server_new(); +void tcore_server_free(Server *s); -TReturn tcore_server_run(Server *s); -TReturn tcore_server_exit(Server *s); +TReturn tcore_server_run(Server *s); +TReturn tcore_server_exit(Server *s); -TReturn tcore_server_add_plugin(Server *s, TcorePlugin *plugin); -GSList* tcore_server_ref_plugins(Server *s); -TcorePlugin* tcore_server_find_plugin(Server *s, const char *name); +TReturn tcore_server_add_plugin(Server *s, TcorePlugin *plugin); +GSList *tcore_server_ref_plugins(Server *s); +TcorePlugin *tcore_server_find_plugin(Server *s, const char *name); -TReturn tcore_server_add_communicator(Server *s, Communicator *comm); -GSList* tcore_server_ref_communicators(Server *s); -Communicator* tcore_server_find_communicator(Server *s, const char *name); +TReturn tcore_server_add_communicator(Server *s, Communicator *comm); +GSList *tcore_server_ref_communicators(Server *s); +Communicator *tcore_server_find_communicator(Server *s, const char *name); -TReturn tcore_server_add_storage(Server *s, Storage *strg); -GSList* tcore_server_ref_storages(Server *s); -Storage* tcore_server_find_storage(Server *s, const char *name); - -TReturn tcore_server_add_hal(Server *s, TcoreHal *hal); -GSList* tcore_server_ref_hals(Server *s); -TcoreHal* tcore_server_find_hal(Server *s, const char *name); +TReturn tcore_server_add_storage(Server *s, Storage *strg); +GSList *tcore_server_ref_storages(Server *s); +Storage * tcore_server_find_storage(Server *s, const char *name); TReturn tcore_server_add_template_object(Server *s, CoreObject *template_co); GSList *tcore_server_ref_template_object(Server *s); CoreObject *tcore_server_find_template_object(Server *s, unsigned int type); -TReturn tcore_server_link_udev(Server *s, TcoreUdev *udev); -TcoreUdev* tcore_server_ref_udev(Server *s); - -TReturn tcore_server_dispatch_request(Server *s, UserRequest *ur); -TReturn tcore_server_send_notification(Server *s, CoreObject *source, - enum tcore_notification_command command, - unsigned int data_len, void *data); - -TReturn tcore_server_add_request_hook(Server *s, - enum tcore_request_command command, - TcoreServerRequestHook func, void *user_data); -TReturn tcore_server_remove_request_hook(Server *s, - TcoreServerRequestHook func); -TReturn tcore_server_add_notification_hook(Server *s, - enum tcore_notification_command command, - TcoreServerNotificationHook func, void *user_data); -TReturn tcore_server_remove_notification_hook(Server *s, - TcoreServerNotificationHook func); +TReturn tcore_server_link_udev(Server *s, TcoreUdev *udev); +TcoreUdev *tcore_server_ref_udev(Server *s); + +TReturn tcore_server_dispatch_request(Server *s, UserRequest *ur); +TReturn tcore_server_send_notification(Server *s, CoreObject *source, + enum tcore_notification_command command, + unsigned int data_len, void *data); + +TReturn tcore_server_add_request_hook(Server *s, + enum tcore_request_command command, + tcore_server_request_hook func, void *user_data); +TReturn tcore_server_remove_request_hook(Server *s, + tcore_server_request_hook func); +TReturn tcore_server_add_notification_hook(Server *s, + enum tcore_notification_command command, + tcore_server_notification_hook func, void *user_data); +TReturn tcore_server_remove_notification_hook(Server *s, + tcore_server_notification_hook func); + +gboolean tcore_server_register_modem(Server *s, TcorePlugin *modem_iface_plugin); +void tcore_server_unregister_modem(Server *s, TcorePlugin *modem_iface_plugin); +gboolean tcore_server_update_modem_plugin(TcorePlugin *modem_iface_plugin, + TcorePlugin *modem_plugin); +char **tcore_server_get_cp_name_list(Server *s); +const char *tcore_server_get_cp_name_by_plugin(TcorePlugin *plugin); + +gboolean tcore_server_add_cp_mapping_tbl_entry(TcorePlugin *modem_iface_plugin, + unsigned int co_type, TcoreHal *hal); +void tcore_server_remove_cp_mapping_tbl_entry(TcorePlugin *modem_iface_plugin, + TcoreHal *hal); +void *tcore_server_get_cp_mapping_tbl(TcorePlugin *modem_plugin); + __END_DECLS diff --git a/include/tcore.h b/include/tcore.h index 82867d2..88d60db 100644 --- a/include/tcore.h +++ b/include/tcore.h @@ -47,6 +47,7 @@ typedef struct tcore_object_type CoreObject; typedef struct tcore_hal_type TcoreHal; typedef struct tcore_plugin_type TcorePlugin; +typedef struct tcore_modem_type TcoreModem; typedef struct tcore_queue_type TcoreQueue; typedef struct tcore_pending_type TcorePending; typedef struct tcore_communicator_type Communicator; diff --git a/src/at.c b/src/at.c index bde8ee1..e27e774 100755 --- a/src/at.c +++ b/src/at.c @@ -135,7 +135,7 @@ static struct tcore_at_response* _response_new() struct tcore_at_response *resp; resp = calloc(1, sizeof(struct tcore_at_response)); - if (!resp) + if (resp == NULL) return NULL; return resp; @@ -143,7 +143,7 @@ static struct tcore_at_response* _response_new() static void _response_free(struct tcore_at_response *resp) { - if (!resp) + if (resp == NULL) return; if (resp->lines) { @@ -160,7 +160,7 @@ static void _response_free(struct tcore_at_response *resp) static void _response_add(struct tcore_at_response *resp, const char *line) { - if (!resp || !line) + if (resp == NULL || !line) return; dbg("current lines = %d", g_slist_length(resp->lines)); @@ -172,14 +172,14 @@ static void _emit_pending_response(TcoreAT *at) { TcorePending *p; - if (!at) + if (at == NULL) return; tcore_at_request_free(at->req); at->req = NULL; p = tcore_queue_pop(tcore_hal_ref_queue(at->hal)); - if (!p) { + if (p == NULL) { dbg("no pending"); } @@ -201,7 +201,7 @@ static void _emit_unsolicited_message(TcoreAT *at, const char *line) gboolean ret; GSList *data = NULL; - if (!at || !line) + if ((at == NULL) || !line) return; dbg("at->pdu_status %d line 0x%x at->data_mode %d", at->pdu_status, line, at->data_mode); @@ -326,13 +326,13 @@ TcoreAT* tcore_at_new(TcoreHal *hal) { TcoreAT *at; - at = calloc(1, sizeof(struct tcore_at_type)); - if (!at) + at = g_try_new0(struct tcore_at_type, 1); + if (at == NULL) return NULL; at->hal = hal; at->buf_size = MAX_AT_RESPONSE; - at->buf = calloc(at->buf_size + 1, 1); + at->buf = g_try_malloc0(at->buf_size + 1); at->buf_read_pos = at->buf; at->buf_write_pos = at->buf; at->data_mode = MODE_HEX; @@ -342,7 +342,7 @@ TcoreAT* tcore_at_new(TcoreHal *hal) void tcore_at_free(TcoreAT *at) { - if (!at) + if (at == NULL) return; if (at->buf) @@ -360,7 +360,7 @@ TReturn tcore_at_remove_notification_full(TcoreAT *at, const char *prefix, Tcore struct _notification_callback *item; GSList *p; - if (!at || !prefix) + if ((at == NULL) || !prefix) return TCORE_RETURN_EINVAL; if (!callback) { @@ -408,12 +408,12 @@ TReturn tcore_at_add_notification(TcoreAT *at, const char *prefix, struct _notification *noti; struct _notification_callback *item; - if (!at || !prefix || !callback) + if ((at == NULL) || !prefix || !callback) return TCORE_RETURN_EINVAL; noti = g_hash_table_lookup(at->unsolicited_table, prefix); if (!noti) { - noti = calloc(1, sizeof(struct _notification)); + noti = g_try_new0(struct _notification, 1); if (!noti) return TCORE_RETURN_ENOMEM; @@ -426,7 +426,7 @@ TReturn tcore_at_add_notification(TcoreAT *at, const char *prefix, if (noti->type_pdu != pdu) return TCORE_RETURN_EINVAL; - item = calloc(1, sizeof(struct _notification_callback)); + item = g_try_new0(struct _notification_callback, 1); if (!item) return TCORE_RETURN_ENOMEM; @@ -444,7 +444,7 @@ TReturn tcore_at_set_request(TcoreAT *at, TcoreATRequest *req, gboolean send) char *end; char next; - if (!at) + if (at == NULL) return TCORE_RETURN_EINVAL; at->req = req; @@ -477,7 +477,7 @@ TReturn tcore_at_set_request(TcoreAT *at, TcoreATRequest *req, gboolean send) TcoreATRequest* tcore_at_get_request(TcoreAT *at) { - if (!at) + if (at == NULL) return NULL; return at->req; @@ -486,7 +486,7 @@ TcoreATRequest* tcore_at_get_request(TcoreAT *at) TcoreATResponse* tcore_at_get_response(TcoreAT *at) { - if (!at) + if (at == NULL) return NULL; return at->resp; @@ -497,7 +497,7 @@ TReturn tcore_at_buf_write(TcoreAT *at, unsigned int data_len, const char *data) unsigned int read_pos; unsigned int write_pos; - if (!at) + if (at == NULL) return TCORE_RETURN_EINVAL; read_pos = at->buf_read_pos - at->buf; @@ -542,14 +542,14 @@ TcoreATRequest* tcore_at_request_new(const char *cmd, const char *prefix, enum t { TcoreATRequest *req; - if (!cmd) + if (cmd == NULL) return NULL; if (strlen(cmd) < 1) return NULL; - req = calloc(1, sizeof(struct tcore_at_request)); - if (!req) + req = g_try_new0(struct tcore_at_request, 1); + if (req == NULL) return NULL; if (!strchr(cmd, CR)) @@ -567,7 +567,7 @@ TcoreATRequest* tcore_at_request_new(const char *cmd, const char *prefix, enum t void tcore_at_request_free(TcoreATRequest *req) { - if (!req) + if (req == NULL) return; if (req->cmd) @@ -627,7 +627,7 @@ gboolean tcore_at_process(TcoreAT *at, unsigned int data_len, const char *data) char *next_pos; int ret; - if (!at || !data) + if ((at == NULL) || (data == NULL)) return FALSE; tcore_at_buf_write(at, data_len, data); @@ -659,7 +659,7 @@ gboolean tcore_at_process(TcoreAT *at, unsigned int data_len, const char *data) // dbg("complete line found."); dbg("line = [%s]", pos); // check request - if (!at->req) { + if (at->req == NULL) { dbg(" Not At request " ); _emit_unsolicited_message(at, pos); } @@ -675,7 +675,7 @@ gboolean tcore_at_process(TcoreAT *at, unsigned int data_len, const char *data) } } - if (!at->resp) { + if (at->resp == NULL) { at->resp = _response_new(); } @@ -774,15 +774,15 @@ TcorePending* tcore_at_pending_new(CoreObject *co, const char *cmd, const char * TcorePending *p; TcoreATRequest *req; - if (!cmd) + if (cmd == NULL) return NULL; req = tcore_at_request_new(cmd, prefix, type); - if (!req) + if (req == NULL) return NULL; p = tcore_pending_new(co, 0); - if (!p) { + if (p == NULL) { tcore_at_request_free(req); return NULL; } @@ -809,7 +809,7 @@ GSList* tcore_at_tok_new(const char *line) int type = TYPE_NONE; GSList *tokens = NULL; - if (!line) + if (line == NULL) return NULL; if (strlen(line) == 0) @@ -858,7 +858,7 @@ GSList* tcore_at_tok_new(const char *line) case TYPE_STR: if (*pos == '"') { type = TYPE_STR_FIN; - buf = calloc(pos - begin + 2, 1); + buf = g_try_malloc0(pos - begin + 2); memcpy(buf, begin, pos - begin + 1); tokens = g_slist_append(tokens, buf); } @@ -867,7 +867,7 @@ GSList* tcore_at_tok_new(const char *line) case TYPE_PAREN: if (*pos == ')') { type = TYPE_PAREN_FIN; - buf = calloc(pos - begin + 2, 1); + buf = g_try_malloc0(pos - begin + 2); memcpy(buf, begin, pos - begin + 1); tokens = g_slist_append(tokens, buf); } @@ -876,7 +876,7 @@ GSList* tcore_at_tok_new(const char *line) case TYPE_RAW: if (*pos == ',' || *pos == '\0') { type = TYPE_NONE; - buf = calloc(pos - begin + 1, 1); + buf = g_try_malloc0(pos - begin + 1); memcpy(buf, begin, pos - begin); tokens = g_slist_append(tokens, buf); } @@ -897,7 +897,7 @@ GSList* tcore_at_tok_new(const char *line) } while (1); if (type == TYPE_RAW) { - buf = calloc(pos - begin + 1, 1); + buf = g_try_malloc0(pos - begin + 1); memcpy(buf, begin, pos - begin); tokens = g_slist_append(tokens, buf); } @@ -907,7 +907,7 @@ GSList* tcore_at_tok_new(const char *line) void tcore_at_tok_free(GSList *tokens) { - if (!tokens) + if (tokens == NULL) return; g_slist_free_full(tokens, g_free); @@ -918,7 +918,7 @@ char* tcore_at_tok_extract(const char *src) char *dest = NULL; char *last = NULL; - if (!src) + if (src == NULL) return NULL; if (strlen(src) < 2) @@ -951,7 +951,7 @@ char* tcore_at_tok_extract(const char *src) char* tcore_at_tok_nth(GSList *tokens, unsigned int token_index) { - if (!tokens) + if (tokens == NULL) return NULL; if (token_index > g_slist_length(tokens)) @@ -1004,7 +1004,7 @@ TReturn tcore_prepare_and_send_at_request(CoreObject *co, /* Create AT-Command Request */ req = tcore_at_request_new(at_cmd, at_cmd_prefix, at_cmd_type); - if (!req) { + if (req == NULL) { dbg("Request is NULL"); tcore_pending_free(pending); return ret; diff --git a/src/co_call.c b/src/co_call.c old mode 100755 new mode 100644 index 7854113..7ad6893 --- a/src/co_call.c +++ b/src/co_call.c @@ -1262,8 +1262,8 @@ void tcore_call_override_ops(CoreObject *o, _clone_call_control_operations(po, control_ops); } -CoreObject *tcore_call_new(TcorePlugin *p, const char *name, - struct tcore_call_operations *ops, TcoreHal *hal) +CoreObject *tcore_call_new(TcorePlugin *p, + struct tcore_call_operations *ops, TcoreHal *hal) { CoreObject *o; struct private_object_data *po; @@ -1271,8 +1271,8 @@ CoreObject *tcore_call_new(TcorePlugin *p, const char *name, if (NULL == p) return NULL; - o = tcore_object_new(p, name, hal); - if (NULL == o) + o = tcore_object_new(p, hal); + if (!o) return NULL; po = g_try_new0(struct private_object_data, 1); @@ -1292,22 +1292,6 @@ CoreObject *tcore_call_new(TcorePlugin *p, const char *name, return o; } -CoreObject *tcore_call_clone(TcorePlugin *p, const char *name, TcoreHal *hal) -{ - CoreObject *o; - - if (NULL == p) - return NULL; - - o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_CALL); - if (NULL == o) - return NULL; - - tcore_object_set_hal(o, hal); - - return o; -} - void tcore_call_free(CoreObject *o) { struct private_object_data *po; diff --git a/src/co_context.c b/src/co_context.c index fd2b6b9..c351821 100644 --- a/src/co_context.c +++ b/src/co_context.c @@ -73,7 +73,7 @@ static void _free_hook(CoreObject *o) } } -CoreObject *tcore_context_new(TcorePlugin *p, const char *name, TcoreHal *hal) +CoreObject *tcore_context_new(TcorePlugin *p, TcoreHal *hal) { CoreObject *o = NULL; struct private_object_data *po = NULL; @@ -81,7 +81,7 @@ CoreObject *tcore_context_new(TcorePlugin *p, const char *name, TcoreHal *hal) if (!p) return NULL; - o = tcore_object_new(p, name, hal); + o = tcore_object_new(p, hal); if (!o) return NULL; @@ -104,22 +104,6 @@ CoreObject *tcore_context_new(TcorePlugin *p, const char *name, TcoreHal *hal) return o; } -CoreObject *tcore_context_clone(TcorePlugin *p, const char *name, TcoreHal *hal) -{ - CoreObject *o = NULL; - - if (!p) - return NULL; - - o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_PS_CONTEXT); - if (!o) - return NULL; - - tcore_object_set_hal(o, hal); - - return o; -} - void tcore_context_free(CoreObject *o) { struct private_object_data *po = NULL; diff --git a/src/co_gps.c b/src/co_gps.c index 36d8c05..903875c 100644 --- a/src/co_gps.c +++ b/src/co_gps.c @@ -117,8 +117,8 @@ void tcore_gps_override_ops(CoreObject *o, struct tcore_gps_operations *gps_ops) return; } -CoreObject *tcore_gps_new(TcorePlugin *p, const char *name, - struct tcore_gps_operations *ops, TcoreHal *hal) +CoreObject *tcore_gps_new(TcorePlugin *p, + struct tcore_gps_operations *ops, TcoreHal *hal) { CoreObject *o = NULL; struct private_object_data *po = NULL; @@ -126,7 +126,7 @@ CoreObject *tcore_gps_new(TcorePlugin *p, const char *name, if (!p) return NULL; - o = tcore_object_new(p, name, hal); + o = tcore_object_new(p, hal); if (!o) return NULL; @@ -146,22 +146,6 @@ CoreObject *tcore_gps_new(TcorePlugin *p, const char *name, return o; } -CoreObject *tcore_gps_clone(TcorePlugin *p, const char *name, TcoreHal *hal) -{ - CoreObject *o = NULL; - - if (!p) - return NULL; - - o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_GPS); - if (!o) - return NULL; - - tcore_object_set_hal(o, hal); - - return o; -} - void tcore_gps_free(CoreObject *o) { struct private_object_data *po = NULL; diff --git a/src/co_modem.c b/src/co_modem.c index f0ac61f..929384f 100755 --- a/src/co_modem.c +++ b/src/co_modem.c @@ -202,8 +202,8 @@ void tcore_modem_override_ops(CoreObject *o, struct tcore_modem_operations *mode return; } -CoreObject *tcore_modem_new(TcorePlugin *p, const char *name, - struct tcore_modem_operations *ops, TcoreHal *hal) +CoreObject *tcore_modem_new(TcorePlugin *p, + struct tcore_modem_operations *ops, TcoreHal *hal) { CoreObject *o = NULL; struct private_object_data *po = NULL; @@ -211,7 +211,8 @@ CoreObject *tcore_modem_new(TcorePlugin *p, const char *name, //dbg("Entered"); if (!p) return NULL; - o = tcore_object_new(p, name, hal); + + o = tcore_object_new(p, hal); if (!o) return NULL; @@ -231,22 +232,6 @@ CoreObject *tcore_modem_new(TcorePlugin *p, const char *name, return o; } -CoreObject *tcore_modem_clone(TcorePlugin *p, const char *name, TcoreHal *hal) -{ - CoreObject *o = NULL; - - if (!p) - return NULL; - - o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_MODEM); - if (!o) - return NULL; - - tcore_object_set_hal(o, hal); - - return o; -} - void tcore_modem_free(CoreObject *o) { struct private_object_data *po = NULL; diff --git a/src/co_network.c b/src/co_network.c index 212ee88..c2aff65 100644 --- a/src/co_network.c +++ b/src/co_network.c @@ -312,8 +312,8 @@ void tcore_network_override_ops(CoreObject *o, struct tcore_network_operations * return; } -CoreObject *tcore_network_new(TcorePlugin *plugin, const char *name, - struct tcore_network_operations *ops, TcoreHal *hal) +CoreObject *tcore_network_new(TcorePlugin *plugin, + struct tcore_network_operations *ops, TcoreHal *hal) { CoreObject *o = NULL; struct private_object_data *po = NULL; @@ -321,7 +321,7 @@ CoreObject *tcore_network_new(TcorePlugin *plugin, const char *name, if (!plugin) return NULL; - o = tcore_object_new(plugin, name, hal); + o = tcore_object_new(plugin, hal); if (!o) return NULL; @@ -342,22 +342,6 @@ CoreObject *tcore_network_new(TcorePlugin *plugin, const char *name, return o; } -CoreObject *tcore_network_clone(TcorePlugin *p, const char *name, TcoreHal *hal) -{ - CoreObject *o = NULL; - - if (!p) - return NULL; - - o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_NETWORK); - if (!o) - return NULL; - - tcore_object_set_hal(o, hal); - - return o; -} - void tcore_network_free(CoreObject *co) { struct private_object_data *po = NULL; diff --git a/src/co_phonebook.c b/src/co_phonebook.c index a81f621..fd2e23e 100644 --- a/src/co_phonebook.c +++ b/src/co_phonebook.c @@ -229,8 +229,8 @@ void tcore_phonebook_override_ops(CoreObject *o, struct tcore_phonebook_operatio return; } -CoreObject *tcore_phonebook_new(TcorePlugin *p, const char *name, - struct tcore_phonebook_operations *ops, TcoreHal *hal) +CoreObject *tcore_phonebook_new(TcorePlugin *p, + struct tcore_phonebook_operations *ops, TcoreHal *hal) { CoreObject *o = NULL; struct private_object_data *po = NULL; @@ -238,7 +238,7 @@ CoreObject *tcore_phonebook_new(TcorePlugin *p, const char *name, if (!p) return NULL; - o = tcore_object_new(p, name, hal); + o = tcore_object_new(p, hal); if (!o) return NULL; @@ -260,22 +260,6 @@ CoreObject *tcore_phonebook_new(TcorePlugin *p, const char *name, return o; } -CoreObject *tcore_phonebook_clone(TcorePlugin *p, const char *name, TcoreHal *hal) -{ - CoreObject *o = NULL; - - if (!p) - return NULL; - - o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_PHONEBOOK); - if (!o) - return NULL; - - tcore_object_set_hal(o, hal); - - return o; -} - void tcore_phonebook_free(CoreObject *o) { struct private_object_data *po = NULL; diff --git a/src/co_ps.c b/src/co_ps.c index b876710..6e24c8d 100644 --- a/src/co_ps.c +++ b/src/co_ps.c @@ -225,8 +225,8 @@ void tcore_ps_override_ops(CoreObject *o, struct tcore_ps_operations *ps_ops) return; } -CoreObject *tcore_ps_new(TcorePlugin *p, const char *name, - struct tcore_ps_operations *ops, TcoreHal *hal) +CoreObject *tcore_ps_new(TcorePlugin *p, + struct tcore_ps_operations *ops, TcoreHal *hal) { CoreObject *o = NULL; struct private_object_data *po = NULL; @@ -234,7 +234,7 @@ CoreObject *tcore_ps_new(TcorePlugin *p, const char *name, if (!p) return NULL; - o = tcore_object_new(p, name, hal); + o = tcore_object_new(p, hal); if (!o) return NULL; @@ -255,22 +255,6 @@ CoreObject *tcore_ps_new(TcorePlugin *p, const char *name, return o; } -CoreObject *tcore_ps_clone(TcorePlugin *p, const char *name, TcoreHal *hal) -{ - CoreObject *o = NULL; - - if (!p) - return NULL; - - o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_PS); - if (!o) - return NULL; - - tcore_object_set_hal(o, hal); - - return o; -} - void tcore_ps_free(CoreObject *o) { struct private_object_data *po = NULL; diff --git a/src/co_sap.c b/src/co_sap.c index 1c844cd..0060ee5 100644 --- a/src/co_sap.c +++ b/src/co_sap.c @@ -191,8 +191,8 @@ void tcore_sap_override_ops(CoreObject *o, struct tcore_sap_operations *sap_ops) return; } -CoreObject *tcore_sap_new(TcorePlugin *p, const char *name, - struct tcore_sap_operations *ops, TcoreHal *hal) +CoreObject *tcore_sap_new(TcorePlugin *p, + struct tcore_sap_operations *ops, TcoreHal *hal) { CoreObject *o = NULL; struct private_object_data *po = NULL; @@ -200,7 +200,7 @@ CoreObject *tcore_sap_new(TcorePlugin *p, const char *name, if (!p) return NULL; - o = tcore_object_new(p, name, hal); + o = tcore_object_new(p, hal); if (!o) return NULL; @@ -221,22 +221,6 @@ CoreObject *tcore_sap_new(TcorePlugin *p, const char *name, return o; } -CoreObject *tcore_sap_clone(TcorePlugin *p, const char *name, TcoreHal *hal) -{ - CoreObject *o = NULL; - - if (!p) - return NULL; - - o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_SAP); - if (!o) - return NULL; - - tcore_object_set_hal(o, hal); - - return o; -} - void tcore_sap_free(CoreObject *o) { struct private_object_data *po = NULL; diff --git a/src/co_sat.c b/src/co_sat.c index e0b6e9c..6e1dccd 100644 --- a/src/co_sat.c +++ b/src/co_sat.c @@ -6884,8 +6884,8 @@ void tcore_sat_override_ops(CoreObject *o, struct tcore_sat_operations *sat_ops) return; } -CoreObject *tcore_sat_new(TcorePlugin *p, const char *name, - struct tcore_sat_operations *ops, TcoreHal *hal) +CoreObject *tcore_sat_new(TcorePlugin *p, + struct tcore_sat_operations *ops, TcoreHal *hal) { CoreObject *o = NULL; struct private_object_data *po = NULL; @@ -6893,7 +6893,7 @@ CoreObject *tcore_sat_new(TcorePlugin *p, const char *name, if (!p) return NULL; - o = tcore_object_new(p, name, hal); + o = tcore_object_new(p, hal); if (!o) return NULL; @@ -6914,22 +6914,6 @@ CoreObject *tcore_sat_new(TcorePlugin *p, const char *name, return o; } -CoreObject *tcore_sat_clone(TcorePlugin *p, const char *name, TcoreHal *hal) -{ - CoreObject *o = NULL; - - if (!p) - return NULL; - - o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_SAT); - if (!o) - return NULL; - - tcore_object_set_hal(o, hal); - - return o; -} - void tcore_sat_free(CoreObject *o) { struct private_object_data *po = NULL; diff --git a/src/co_sim.c b/src/co_sim.c index f8bdb16..f1d247d 100644 --- a/src/co_sim.c +++ b/src/co_sim.c @@ -2536,8 +2536,8 @@ void tcore_sim_override_ops(CoreObject *o, struct tcore_sim_operations *sim_ops) return; } -CoreObject *tcore_sim_new(TcorePlugin *p, const char *name, - struct tcore_sim_operations *ops, TcoreHal *hal) +CoreObject *tcore_sim_new(TcorePlugin *p, + struct tcore_sim_operations *ops, TcoreHal *hal) { CoreObject *o = NULL; struct private_object_data *po = NULL; @@ -2545,7 +2545,7 @@ CoreObject *tcore_sim_new(TcorePlugin *p, const char *name, if (!p) return NULL; - o = tcore_object_new(p, name, hal); + o = tcore_object_new(p, hal); if (!o) return NULL; @@ -2568,22 +2568,6 @@ CoreObject *tcore_sim_new(TcorePlugin *p, const char *name, return o; } -CoreObject *tcore_sim_clone(TcorePlugin *p, const char *name, TcoreHal *hal) -{ - CoreObject *o = NULL; - - if (!p) - return NULL; - - o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_SIM); - if (!o) - return NULL; - - tcore_object_set_hal(o, hal); - - return o; -} - void tcore_sim_free(CoreObject *o) { struct private_object_data *po = NULL; diff --git a/src/co_sms.c b/src/co_sms.c index 6e8d7dc..98f994e 100644 --- a/src/co_sms.c +++ b/src/co_sms.c @@ -484,8 +484,8 @@ void tcore_sms_override_ops(CoreObject *o, struct tcore_sms_operations *sms_ops) return; } -CoreObject *tcore_sms_new(TcorePlugin *p, const char *name, - struct tcore_sms_operations *ops, TcoreHal *hal) +CoreObject *tcore_sms_new(TcorePlugin *p, + struct tcore_sms_operations *ops, TcoreHal *hal) { CoreObject *o = NULL; struct private_object_data *po = NULL; @@ -493,7 +493,7 @@ CoreObject *tcore_sms_new(TcorePlugin *p, const char *name, if (!p) return NULL; - o = tcore_object_new(p, name, hal); + o = tcore_object_new(p, hal); if (!o) return NULL; @@ -514,22 +514,6 @@ CoreObject *tcore_sms_new(TcorePlugin *p, const char *name, return o; } -CoreObject *tcore_sms_clone(TcorePlugin *p, const char *name, TcoreHal *hal) -{ - CoreObject *o = NULL; - - if (!p) - return NULL; - - o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_SMS); - if (!o) - return NULL; - - tcore_object_set_hal(o, hal); - - return o; -} - void tcore_sms_free(CoreObject *o) { struct private_object_data *po = NULL; diff --git a/src/co_ss.c b/src/co_ss.c index 4c8b0ce..a2d3af9 100644 --- a/src/co_ss.c +++ b/src/co_ss.c @@ -243,7 +243,7 @@ static void _ussd_session_init(struct ussd_session *ussd_s) } struct ussd_session* tcore_ss_ussd_create_session(CoreObject *o, - enum tcore_ss_ussd_type type, void *data, int data_len) + enum tcore_ss_ussd_type type, void *data, int data_len) { struct private_object_data *po = NULL; @@ -313,8 +313,8 @@ enum tcore_ss_ussd_type tcore_ss_ussd_get_session_type(struct ussd_session *ussd } } -void tcore_ss_ussd_set_session_type(struct ussd_session *ussd_s, - enum tcore_ss_ussd_type type) +void tcore_ss_ussd_set_session_type(struct ussd_session* ussd_s, + enum tcore_ss_ussd_type type) { if (!ussd_s || !ussd_s->session) { dbg("[ error ] there is no session"); @@ -340,7 +340,8 @@ int tcore_ss_ussd_get_session_data(struct ussd_session* ussd_s, void **data) } } -void tcore_ss_ussd_set_session_data(struct ussd_session* ussd_s, void *data, int data_len) +void tcore_ss_ussd_set_session_data(struct ussd_session* ussd_s, + void* data, int data_len) { if (!ussd_s || !ussd_s->session) { dbg("[ error ] there is no session"); @@ -372,8 +373,8 @@ void tcore_ss_override_ops(CoreObject *o, struct tcore_ss_operations *ss_ops) return; } -CoreObject *tcore_ss_new(TcorePlugin *p, const char *name, - struct tcore_ss_operations *ops, TcoreHal *hal) +CoreObject *tcore_ss_new(TcorePlugin *p, + struct tcore_ss_operations *ops, TcoreHal *hal) { CoreObject *o = NULL; struct private_object_data *po = NULL; @@ -381,7 +382,7 @@ CoreObject *tcore_ss_new(TcorePlugin *p, const char *name, if (!p) return NULL; - o = tcore_object_new(p, name, hal); + o = tcore_object_new(p, hal); if (!o) return NULL; @@ -404,22 +405,6 @@ CoreObject *tcore_ss_new(TcorePlugin *p, const char *name, return o; } -CoreObject *tcore_ss_clone(TcorePlugin *p, const char *name, TcoreHal *hal) -{ - CoreObject *o = NULL; - - if (!p) - return NULL; - - o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_SS); - if (!o) - return NULL; - - tcore_object_set_hal(o, hal); - - return o; -} - void tcore_ss_free(CoreObject *o) { CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_SS); diff --git a/src/core_object.c b/src/core_object.c index b92dde8..ff2c959 100644 --- a/src/core_object.c +++ b/src/core_object.c @@ -31,43 +31,86 @@ #include "hal.h" #include "at.h" +#include "co_call.h" +#include "co_modem.h" +#include "co_ps.h" +#include "co_network.h" +#include "co_ss.h" +#include "co_sim.h" +#include "co_sat.h" +#include "co_sap.h" +#include "co_sms.h" +#include "co_phonebook.h" +#include "co_gps.h" + +#define INIT_CORE_OBJECT(initializer, plugin, type, hal) do { \ + CoreObject *co; \ + if (initializer != NULL) { \ + co = tcore_object_clone_template_object(plugin, type); \ + if (co == NULL) { \ + break; \ + } \ + \ + tcore_object_set_hal(co, hal); \ + \ + ret = initializer(plugin, co); \ + } \ +} while(0); + +#define DEINIT_CORE_OBJECT(deinitializer, plugin, type) do { \ + if (deinitializer != NULL) { \ + /* Assuming only one Core Object is present of a specific TYPE */ \ + co = tcore_plugin_ref_core_object(plugin, type); \ + if (co == NULL) { \ + break; \ + } \ + \ + deinitializer(plugin, co); \ + \ + tcore_object_free(co); \ + } \ +} while(0); + + struct callback_type { CoreObject *co; char *event; - CoreObjectCallback callback; + tcore_object_callback callback; void *user_data; }; struct tcore_object_type { unsigned int type; - char *name; TcorePlugin *parent_plugin; void *object; void *user_data; - CoreObjectFreeHook free_hook; - CoreObjectCloneHook clone_hook; - CoreObjectDispatcher dispatcher; + tcore_object_free_hook free_hook; + tcore_object_clone_hook clone_hook; + tcore_object_dispatcher dispatcher; GSList *callbacks; TcoreHal *hal; }; -static CoreObject *_object_new(TcorePlugin *plugin, const char *name, unsigned int type) +/* Mapping Table */ +struct tcore_object_mapping_tbl { + TcoreHal *hal; + GSList *object_type; +}; + +static CoreObject *_object_new(TcorePlugin *plugin, unsigned int type) { CoreObject *co; - co = calloc(1, sizeof(struct tcore_object_type)); - if (!co) + co = g_try_new0(struct tcore_object_type, 1); + if (co == NULL) return NULL; co->parent_plugin = plugin; - if (name) - co->name = strdup(name); - co->type = type; return co; @@ -92,13 +135,197 @@ static void _remove_at_callback(TcoreAT *at, struct callback_type *cb) tcore_at_remove_notification_full(at, cb->event, _on_at_event, cb); } -CoreObject *tcore_object_new(TcorePlugin *plugin, - const char *name, TcoreHal *hal) +static object_mapping_table_t *_object_search_mapping_tbl_entry(GSList *mapping_tbl_list, + TcoreHal *hal) +{ + GSList *list; + object_mapping_table_t *tbl_entry = NULL; + + for (list = mapping_tbl_list; list ; list = list->next) { + tbl_entry = list->data; + if (tbl_entry == NULL) + continue; + + /* Search for Table entry with matching 'hal' */ + if (tbl_entry->hal == hal) { + return tbl_entry; + } + } + + return tbl_entry; +} + +static object_mapping_table_t *_object_search_mapping_tbl_entry_by_type( + GSList *mapping_tbl_list, unsigned int type) +{ + GSList *list; + GSList *co_list; + object_mapping_table_t *tbl_entry = NULL; + + for (list = mapping_tbl_list; list ; list = list->next) { + tbl_entry = list->data; + if (tbl_entry == NULL) + continue; + + /* Search all the Table entries with matching 'type' */ + for (co_list = tbl_entry->object_type ; co_list ; co_list = co_list->next) { + if (co_list->data == NULL) + continue; + + if (type == (unsigned int)co_list->data) { + return tbl_entry; + } + } + } + + return tbl_entry; +} + + +static gboolean _init_core_object_by_type(unsigned int type, + TcorePlugin *plugin, TcoreHal *hal, struct object_initializer *initializer_list) +{ + gboolean ret = FALSE; + + switch (type) { + case CORE_OBJECT_TYPE_MODEM: + INIT_CORE_OBJECT(initializer_list->modem_init, + plugin, type, hal); + break; + + case CORE_OBJECT_TYPE_CALL: + INIT_CORE_OBJECT(initializer_list->call_init, + plugin, type, hal); + break; + + case CORE_OBJECT_TYPE_SS: + INIT_CORE_OBJECT(initializer_list->ss_init, + plugin, type, hal); + break; + + case CORE_OBJECT_TYPE_NETWORK: + INIT_CORE_OBJECT(initializer_list->network_init, + plugin, type, hal); + break; + + case CORE_OBJECT_TYPE_PS: + INIT_CORE_OBJECT(initializer_list->ps_init, + plugin, type, hal); + break; + + case CORE_OBJECT_TYPE_SIM: + INIT_CORE_OBJECT(initializer_list->sim_init, + plugin, type, hal); + break; + + case CORE_OBJECT_TYPE_SAT: + INIT_CORE_OBJECT(initializer_list->sat_init, + plugin, type, hal); + break; + + case CORE_OBJECT_TYPE_SAP: + INIT_CORE_OBJECT(initializer_list->sap_init, + plugin, type, hal); + break; + + case CORE_OBJECT_TYPE_SMS: + INIT_CORE_OBJECT(initializer_list->sms_init, + plugin, type, hal); + break; + + case CORE_OBJECT_TYPE_PHONEBOOK: + INIT_CORE_OBJECT(initializer_list->phonebook_init, + plugin, type, hal); + break; + + case CORE_OBJECT_TYPE_GPS: + INIT_CORE_OBJECT(initializer_list->gps_init, + plugin, type, hal); + break; + + case CORE_OBJECT_TYPE_SOUND: /* Fall through */ + case CORE_OBJECT_TYPE_CUSTOM: /* Fall through */ + default: + dbg("Unsupport/Invalid Core Object Type [0x%x]", type); + } + + return ret; +} + +static void _deinit_core_object_by_type(unsigned int type, + TcorePlugin *plugin, struct object_deinitializer *deinitializer_list) { CoreObject *co; - co = _object_new(plugin, name, CORE_OBJECT_TYPE_DEFAULT); - if (!co) + switch (type) { + case CORE_OBJECT_TYPE_MODEM: + DEINIT_CORE_OBJECT(deinitializer_list->modem_deinit, + plugin, type); + break; + + case CORE_OBJECT_TYPE_CALL: + DEINIT_CORE_OBJECT(deinitializer_list->call_deinit, + plugin, type); + break; + + case CORE_OBJECT_TYPE_SS: + DEINIT_CORE_OBJECT(deinitializer_list->ss_deinit, + plugin, type); + break; + + case CORE_OBJECT_TYPE_NETWORK: + DEINIT_CORE_OBJECT(deinitializer_list->network_deinit, + plugin, type); + break; + + case CORE_OBJECT_TYPE_PS: + DEINIT_CORE_OBJECT(deinitializer_list->ps_deinit, + plugin, type); + break; + + case CORE_OBJECT_TYPE_SIM: + DEINIT_CORE_OBJECT(deinitializer_list->sim_deinit, + plugin, type); + break; + + case CORE_OBJECT_TYPE_SAT: + DEINIT_CORE_OBJECT(deinitializer_list->sat_deinit, + plugin, type); + break; + + case CORE_OBJECT_TYPE_SAP: + DEINIT_CORE_OBJECT(deinitializer_list->sap_deinit, + plugin, type); + break; + + case CORE_OBJECT_TYPE_SMS: + DEINIT_CORE_OBJECT(deinitializer_list->sms_deinit, + plugin, type); + break; + + case CORE_OBJECT_TYPE_PHONEBOOK: + DEINIT_CORE_OBJECT(deinitializer_list->phonebook_deinit, + plugin, type); + break; + + case CORE_OBJECT_TYPE_GPS: + DEINIT_CORE_OBJECT(deinitializer_list->gps_deinit, + plugin, type); + break; + + case CORE_OBJECT_TYPE_SOUND: /* Fall through */ + case CORE_OBJECT_TYPE_CUSTOM: /* Fall through */ + default: + dbg("Unsupport/Invalid Core Object Type [0x%x]", type); + } +} + +CoreObject *tcore_object_new(TcorePlugin *plugin, TcoreHal *hal) +{ + CoreObject *co; + + co = _object_new(plugin, CORE_OBJECT_TYPE_DEFAULT); + if (co == NULL) return NULL; tcore_object_set_hal(co, hal); @@ -114,10 +341,10 @@ void tcore_object_free(CoreObject *co) GSList *l = NULL; struct callback_type *cb = NULL; - if (!co) + if (co == NULL) return; - dbg("co_name=%s", co->name); + dbg("Type: [0x%x]", co->type); if (co->free_hook) co->free_hook(co); @@ -125,12 +352,11 @@ void tcore_object_free(CoreObject *co) if (co->callbacks) { for (l = co->callbacks; l; l = l->next) { cb = l->data; - if (!cb) + if (cb == NULL) continue; - if (cb->event) - g_free(cb->event); - + /* Freeing 'event' and 'cb' node */ + g_free(cb->event); g_free(cb); } @@ -138,21 +364,17 @@ void tcore_object_free(CoreObject *co) co->callbacks = NULL; } - if (co->name) - g_free(co->name); - g_free(co); } -CoreObject *tcore_object_clone(CoreObject *src, TcorePlugin *new_parent, const char *new_name) +CoreObject *tcore_object_clone(CoreObject *src, TcorePlugin *new_parent) { CoreObject *dest; TcorePlugin *p; - const char *name; - GSList *l = NULL; + GSList *l; struct callback_type *cb = NULL; - if (!src) + if (src == NULL) return NULL; if (new_parent) @@ -160,13 +382,8 @@ CoreObject *tcore_object_clone(CoreObject *src, TcorePlugin *new_parent, const c else p = src->parent_plugin; - if (new_name) - name = new_name; - else - name = src->name; - - dest = _object_new(p, name, src->type); - if (!dest) + dest = _object_new(p, src->type); + if (dest == NULL) return NULL; dest->object = src->object; @@ -178,7 +395,7 @@ CoreObject *tcore_object_clone(CoreObject *src, TcorePlugin *new_parent, const c for (l = src->callbacks; l; l = l->next) { cb = l->data; - if (!cb) + if (cb == NULL) continue; tcore_object_add_callback(dest, cb->event, cb->callback, cb->user_data); @@ -192,35 +409,28 @@ CoreObject *tcore_object_clone(CoreObject *src, TcorePlugin *new_parent, const c return dest; } -CoreObject *tcore_object_clone_template_object(TcorePlugin *p, const char *co_name, unsigned int co_type) +CoreObject *tcore_object_clone_template_object(TcorePlugin *p, + unsigned int co_type) { CoreObject *co = NULL; CoreObject *template_co = NULL; template_co = tcore_server_find_template_object(tcore_plugin_ref_server(p), co_type); - if(!template_co) { + if(template_co == NULL) { return NULL; - } - co = tcore_object_clone(template_co, p, co_name); - if(!co) { + + co = tcore_object_clone(template_co, p); + if (co == NULL) return NULL; } return co; } -const char *tcore_object_ref_name(CoreObject *co) -{ - if (!co) - return NULL; - - return co->name; -} - TReturn tcore_object_set_free_hook(CoreObject *co, - CoreObjectFreeHook free_hook) + tcore_object_free_hook free_hook) { - if (!co) + if (co == NULL) return TCORE_RETURN_EINVAL; co->free_hook = free_hook; @@ -230,9 +440,9 @@ TReturn tcore_object_set_free_hook(CoreObject *co, TReturn tcore_object_set_clone_hook(CoreObject *co, - CoreObjectCloneHook clone_hook) + tcore_object_clone_hook clone_hook) { - if (!co) + if (co == NULL) return TCORE_RETURN_EINVAL; co->clone_hook = clone_hook; @@ -240,25 +450,9 @@ TReturn tcore_object_set_clone_hook(CoreObject *co, return TCORE_RETURN_SUCCESS; } -TReturn tcore_object_set_name(CoreObject *co, const char *name) -{ - if (!co) - return TCORE_RETURN_EINVAL; - - if (co->name) { - free(co->name); - co->name = NULL; - } - - if (name) - co->name = strdup(name); - - return TCORE_RETURN_SUCCESS; -} - TcorePlugin *tcore_object_ref_plugin(CoreObject *co) { - if (!co) + if (co == NULL) return NULL; return co->parent_plugin; @@ -266,7 +460,7 @@ TcorePlugin *tcore_object_ref_plugin(CoreObject *co) TReturn tcore_object_link_object(CoreObject *co, void *object) { - if (!co) + if (co == NULL) return TCORE_RETURN_EINVAL; co->object = object; @@ -276,7 +470,7 @@ TReturn tcore_object_link_object(CoreObject *co, void *object) void *tcore_object_ref_object(CoreObject *co) { - if (!co) + if (co == NULL) return NULL; return co->object; @@ -284,7 +478,7 @@ void *tcore_object_ref_object(CoreObject *co) TReturn tcore_object_set_type(CoreObject *co, unsigned int type) { - if (!co) + if (co == NULL) return TCORE_RETURN_EINVAL; co->type = type; @@ -294,7 +488,7 @@ TReturn tcore_object_set_type(CoreObject *co, unsigned int type) unsigned int tcore_object_get_type(CoreObject *co) { - if (!co) + if (co == NULL) return 0; return co->type; @@ -306,11 +500,11 @@ TReturn tcore_object_set_hal(CoreObject *co, TcoreHal *hal) struct callback_type *cb = NULL; GSList *l = NULL; - if (!co) + if (co == NULL) return TCORE_RETURN_EINVAL; if (co->hal) { - // remove unsolicited callbacks + /* Remove unsolicited callbacks */ if (tcore_hal_get_mode(co->hal) == TCORE_HAL_MODE_AT) { at = tcore_hal_get_at(co->hal); for (l = co->callbacks; l != NULL; l = l->next) { @@ -328,7 +522,7 @@ TReturn tcore_object_set_hal(CoreObject *co, TcoreHal *hal) if (hal == NULL) return TCORE_RETURN_SUCCESS; - // register unsolicited callbacks + /* Register unsolicited callbacks */ if (tcore_hal_get_mode(hal) == TCORE_HAL_MODE_AT) { at = tcore_hal_get_at(hal); for (l = co->callbacks; l != NULL; l = l->next) { @@ -350,7 +544,7 @@ TReturn tcore_object_set_hal(CoreObject *co, TcoreHal *hal) TcoreHal *tcore_object_get_hal(CoreObject *co) { - if (!co) + if (co == NULL) return NULL; return co->hal; @@ -359,7 +553,7 @@ TcoreHal *tcore_object_get_hal(CoreObject *co) TReturn tcore_object_link_user_data(CoreObject *co, void *user_data) { - if (!co) + if (co == NULL) return TCORE_RETURN_EINVAL; co->user_data = user_data; @@ -369,7 +563,7 @@ TReturn tcore_object_link_user_data(CoreObject *co, void *tcore_object_ref_user_data(CoreObject *co) { - if (!co) + if (co == NULL) return NULL; return co->user_data; @@ -378,19 +572,19 @@ void *tcore_object_ref_user_data(CoreObject *co) TReturn tcore_object_dispatch_request(CoreObject *co, UserRequest *ur) { - if (!co || !ur) + if ((co == NULL) || (ur == NULL)) return TCORE_RETURN_EINVAL; - if (!co->dispatcher) + if (co->dispatcher == NULL) return TCORE_RETURN_ENOSYS; return co->dispatcher(co, ur); } TReturn tcore_object_set_dispatcher(CoreObject *co, - CoreObjectDispatcher func) + tcore_object_dispatcher func) { - if (!co || !func) + if ((co == NULL) || (func == NULL)) return TCORE_RETURN_EINVAL; co->dispatcher = func; @@ -399,13 +593,13 @@ TReturn tcore_object_set_dispatcher(CoreObject *co, } TReturn tcore_object_override_callback(CoreObject *co, - const char *event, CoreObjectCallback callback, void *user_data) + const char *event, tcore_object_callback callback, void *user_data) { struct callback_type *cb = NULL; GSList *l = NULL; TcoreAT *at = NULL; - if (!co || !event || !callback) + if ((co == NULL) || (event == NULL) || (callback == NULL)) return TCORE_RETURN_EINVAL; if (strlen(event) < 1) @@ -418,7 +612,7 @@ TReturn tcore_object_override_callback(CoreObject *co, for (l = co->callbacks; l; l = l->next) { cb = l->data; - if (!cb) + if (cb == NULL) continue; if (g_strcmp0(cb->event, event) != 0) @@ -427,32 +621,32 @@ TReturn tcore_object_override_callback(CoreObject *co, if (at) _remove_at_callback(at, cb); - free(cb->event); + g_free(cb->event); co->callbacks = g_slist_remove(co->callbacks, cb); - free(cb); + g_free(cb); } return tcore_object_add_callback(co, event, callback, user_data); } TReturn tcore_object_add_callback(CoreObject *co, - const char *event, CoreObjectCallback callback, void *user_data) + const char *event, tcore_object_callback callback, void *user_data) { struct callback_type *cb = NULL; TcoreAT *at = NULL; - if (!co || !event || !callback) + if ((co == NULL) || (event == NULL) || (callback == NULL)) return TCORE_RETURN_EINVAL; if (strlen(event) < 1) return TCORE_RETURN_EINVAL; - cb = calloc(1, sizeof(struct callback_type)); - if (!cb) + cb = g_try_new0(struct callback_type, 1); + if (cb == NULL) return TCORE_RETURN_ENOMEM; cb->co = co; - cb->event = strdup(event); + cb->event = g_strdup(event); cb->callback = callback; cb->user_data = user_data; @@ -473,13 +667,13 @@ TReturn tcore_object_add_callback(CoreObject *co, } TReturn tcore_object_del_callback(CoreObject *co, - const char *event, CoreObjectCallback callback) + const char *event, tcore_object_callback callback) { struct callback_type *cb = NULL; GSList *l = NULL; TcoreAT *at = NULL; - if (!co || !event || !callback || !co->callbacks) + if ((co == NULL) || (event == NULL) || (callback == NULL) || (co->callbacks == NULL)) return TCORE_RETURN_EINVAL; if (strlen(event) < 1) @@ -492,7 +686,7 @@ TReturn tcore_object_del_callback(CoreObject *co, for (l = co->callbacks; l; l = l->next) { cb = l->data; - if (!cb) + if (cb == NULL) continue; if (cb->callback != callback) @@ -504,9 +698,9 @@ TReturn tcore_object_del_callback(CoreObject *co, if (at) _remove_at_callback(at, cb); - free(cb->event); + g_free(cb->event); co->callbacks = g_slist_remove(co->callbacks, cb); - free(cb); + g_free(cb); } return TCORE_RETURN_SUCCESS; @@ -519,13 +713,13 @@ TReturn tcore_object_emit_callback(CoreObject *co, GSList *l = NULL; TReturn ret; - if (!co || !event) + if ((co == NULL) || (event == NULL)) return TCORE_RETURN_EINVAL; l = co->callbacks; while (l) { cb = l->data; - if (!cb) { + if (cb == NULL) { l = l->next; continue; } @@ -549,3 +743,187 @@ TReturn tcore_object_emit_callback(CoreObject *co, return TCORE_RETURN_SUCCESS; } + +gboolean tcore_object_add_mapping_tbl_entry(void *mapping_tbl, + unsigned int object_type, TcoreHal *hal) +{ + GSList *mapping_tbl_list; + object_mapping_table_t *tbl_entry; + + if ((mapping_tbl == NULL) || (hal == NULL)) + return FALSE; + + mapping_tbl_list = mapping_tbl; + + tbl_entry = _object_search_mapping_tbl_entry(mapping_tbl_list, hal); + if (tbl_entry == NULL) { + /* + * If there is NO previously added Table entry for the 'hal' then + * new Table entry is created + */ + tbl_entry = g_try_new0(object_mapping_table_t, 1); + if (tbl_entry != NULL) + tbl_entry->hal = hal; + else { + err("Failed to allocate memory"); + return FALSE; + } + } + + /* + * Appending the Core Object type to the list of Core Objects types + */ + tbl_entry->object_type = g_slist_append(tbl_entry->object_type, (gpointer)object_type); + + return TRUE; +} + +void tcore_object_remove_mapping_tbl_entry(void *mapping_tbl, TcoreHal *hal) +{ + GSList *mapping_tbl_list; + object_mapping_table_t *tbl_entry; + + if (mapping_tbl == NULL) + return; + + mapping_tbl_list = mapping_tbl; + + tbl_entry = _object_search_mapping_tbl_entry(mapping_tbl_list, hal); + if (tbl_entry == NULL) { + err("Table entry is NOT available"); + return; + } + + /* Free Core Object types list */ + g_slist_free(tbl_entry->object_type); + + /* Remove mapping Table entry */ + mapping_tbl_list = g_slist_remove(mapping_tbl_list, tbl_entry); + + /* Free Table entry */ + g_free(tbl_entry); +} + +void tcore_object_remove_mapping_tbl_entry_by_type(void *mapping_tbl, + unsigned int co_type) +{ + GSList *mapping_tbl_list; + object_mapping_table_t *tbl_entry; + + if (mapping_tbl == NULL) + return; + + mapping_tbl_list = mapping_tbl; + + tbl_entry = + _object_search_mapping_tbl_entry_by_type(mapping_tbl_list, co_type); + if (tbl_entry == NULL) { + err("Table entry is NOT available"); + return; + } + + /* Remove the Core Object type from the list */ + tbl_entry->object_type = g_slist_remove(tbl_entry->object_type, (gconstpointer)co_type); +} + +/* Initialize Core Objects */ +TReturn tcore_object_init_objects(TcorePlugin *plugin, + struct object_initializer *initializer_list) +{ + GSList *mapping_tbl_list; + gboolean ret = FALSE; + + /* Refer mapping_tbl from Server's Modem list */ + mapping_tbl_list = tcore_server_get_cp_mapping_tbl(plugin); + + /* + * Mapping Table is a MUST + * If Mapping Table is NOT NULL, then initialization would be guided by the + * Mapping Table entries, + * else, it is treated as a Failure. + */ + if (mapping_tbl_list != NULL) { + object_mapping_table_t *tbl_entry; + GSList *object_type_list; + unsigned int type; + + /* Initialize each Core Object based on the Mapping Table entries */ + for ( ; mapping_tbl_list ; mapping_tbl_list = mapping_tbl_list->next) { + tbl_entry = mapping_tbl_list->data; + if (tbl_entry == NULL) + continue; + + /* To handle NULL 'init' function case */ + ret = FALSE; + + object_type_list = tbl_entry->object_type; + + for ( ; object_type_list ; object_type_list = object_type_list->next) { + type = (unsigned int)object_type_list->data; + dbg("Core Object type: [0x%x]", type); + + ret = _init_core_object_by_type(type, plugin, tbl_entry->hal, initializer_list); + if (ret == FALSE) { + err("Failed to initialize Core Object Type [0x%x]", type); + + /* + * Will stop initializing other Modules in case of Error, + * but we need to check if we need to continue OR not as we cannot + * define which Modules are Mandatory and which are NOT. + */ + break; + } + } + } + } else + err("Mapping Table is NOT present"); + + if (ret == FALSE) { + err("Failed to initialize Core Objects"); + return TCORE_RETURN_FAILURE; + } + + dbg("Successfully initialized Core Objects"); + return TCORE_RETURN_SUCCESS; +} + +/* De-initialize Core Objects */ +void tcore_object_deinit_objects(TcorePlugin *plugin, + struct object_deinitializer *deinitializer_list) +{ + GSList *mapping_tbl_list; + + /* Refer mapping_tbl from Server's Modem list */ + mapping_tbl_list = tcore_server_get_cp_mapping_tbl(plugin); + + /* + * Mapping Table is a MUST + * If Mapping Table is NOT NULL, then de-initialization would be guided by the + * Mapping Table entries, + * else, + * just return with an Error log. + */ + if (mapping_tbl_list != NULL) { + object_mapping_table_t *tbl_entry; + GSList *object_type_list; + unsigned int type; + + /* De-initialize each Core Object based on the Mapping Table entries */ + for ( ; mapping_tbl_list ; mapping_tbl_list = mapping_tbl_list->next) { + tbl_entry = mapping_tbl_list->data; + if (tbl_entry == NULL) + continue; + + object_type_list = tbl_entry->object_type; + + for ( ; object_type_list ; object_type_list = object_type_list->next) { + type = (unsigned int)object_type_list->data; + dbg("Core Object type: [0x%x]", type); + + _deinit_core_object_by_type(type, plugin, deinitializer_list); + } + } + dbg("Successfully de-initialized Core Objects"); + } else + err("Mapping Table is NOT present"); +} diff --git a/src/hal.c b/src/hal.c index c5d901b..550846b 100644 --- a/src/hal.c +++ b/src/hal.c @@ -66,7 +66,7 @@ struct tcore_hal_type { static gboolean _hal_idle_send(void *user_data) { - TcoreHal *h = user_data; + TcoreHal *hal = user_data; TcorePending *p = NULL; TcoreQueue *q; int ret = 0; @@ -74,26 +74,26 @@ static gboolean _hal_idle_send(void *user_data) unsigned int data_len = 0; gboolean renew = FALSE; - if (!h) + if (hal == NULL) return FALSE; msg("--[Queue SEND]-------------------"); - p = tcore_queue_ref_next_pending(h->queue); - if (!p) { - dbg("next pending is NULL. no send, queue len=%d", tcore_queue_get_length(h->queue)); + p = tcore_queue_ref_next_pending(hal->queue); + if (p == NULL) { + dbg("next pending is NULL. no send, queue len=%d", tcore_queue_get_length(hal->queue)); goto out; } data = tcore_pending_ref_request_data(p, &data_len); dbg("queue len=%d, pending=0x%x, id=0x%x, data_len=%d", - tcore_queue_get_length(h->queue), (unsigned int)p, tcore_pending_get_id(p), data_len); + tcore_queue_get_length(hal->queue), (unsigned int)p, tcore_pending_get_id(p), data_len); - if (h->mode == TCORE_HAL_MODE_AT) { - ret = tcore_at_set_request(h->at, data, TRUE); + if (hal->mode == TCORE_HAL_MODE_AT) { + ret = tcore_at_set_request(hal->at, data, TRUE); } else { - ret = tcore_hal_send_data(h, data_len, data); + ret = tcore_hal_send_data(hal, data_len, data); } if (ret == TCORE_RETURN_SUCCESS) { @@ -105,7 +105,7 @@ static gboolean _hal_idle_send(void *user_data) if (ret != TCORE_RETURN_HOOK_STOP) { if (tcore_pending_get_auto_free_status_after_sent(p)) { - q = tcore_hal_ref_queue(h); + q = tcore_hal_ref_queue(hal); tcore_queue_pop_by_pending(q, p); tcore_pending_free(p); @@ -116,7 +116,7 @@ static gboolean _hal_idle_send(void *user_data) /* Send fail */ if (ret != TCORE_RETURN_SUCCESS) { dbg("send fail."); - q = tcore_hal_ref_queue(h); + q = tcore_hal_ref_queue(hal); p = tcore_queue_pop(q); tcore_pending_free(p); } @@ -132,82 +132,86 @@ TcoreHal *tcore_hal_new(TcorePlugin *plugin, const char *name, struct tcore_hal_operations *hops, enum tcore_hal_mode mode) { - TcoreHal *h; + TcoreHal *hal; - if (!name) + if (name == NULL) return NULL; - h = calloc(1, sizeof(struct tcore_hal_type)); - if (!h) + hal = g_try_new0(struct tcore_hal_type, 1); + if (hal == NULL) return NULL; - h->parent_plugin = plugin; - h->ops = hops; - h->name = strdup(name); - h->queue = tcore_queue_new(h); - h->mode = mode; + hal->parent_plugin = plugin; + hal->ops = hops; + hal->name = g_strdup(name); + hal->queue = tcore_queue_new(hal); + hal->mode = mode; + /* Create and link AT parser if HAL mode is AT */ if (mode == TCORE_HAL_MODE_AT) - h->at = tcore_at_new(h); - - if (plugin) - tcore_server_add_hal(tcore_plugin_ref_server(plugin), h); + hal->at = tcore_at_new(hal); - return h; + return hal; } void tcore_hal_free(TcoreHal *hal) { - if (!hal) + if (hal == NULL) return; dbg("hal=%s", hal->name); - if (hal->name) - free(hal->name); + /* Freeing HAL name */ + g_free(hal->name); - if (hal->callbacks) - g_slist_free(hal->callbacks); + /* Freeing HAL callbacks list */ + g_slist_free(hal->callbacks); - if (hal->queue) - tcore_queue_free(hal->queue); + /* Freeing HAL Queue */ + tcore_queue_free(hal->queue); - if (hal->at) - tcore_at_free(hal->at); + /* Freeing AT parser linked to HAL */ + tcore_at_free(hal->at); - free(hal); + /* Freeing HAL */ + g_free(hal); } TReturn tcore_hal_set_name(TcoreHal *hal, const char *name) { - if (!hal) + if (hal == NULL) return TCORE_RETURN_EINVAL; - if (hal->name) { - free(hal->name); - hal->name = NULL; - } + /* Freeing the previously assigned HAL name */ + g_free(hal->name); + hal->name = NULL; - if (name) - hal->name = strdup(name); + /* + * Assign the new HAL name irrespective of if 'name' is NULL, + * g_strdup would take care of this scenario. + */ + hal->name = g_strdup(name); return TCORE_RETURN_SUCCESS; } char *tcore_hal_get_name(TcoreHal *hal) { - if (!hal) + if (hal == NULL) return NULL; - if (hal->name) - return strdup(hal->name); - - return NULL; + /* + * Return copy of HAL name, + * + * it CAN even be NULL if hal->name is NULL, + * g_strdup will take care of this scenario. + */ + return g_strdup(hal->name); } TcoreAT *tcore_hal_get_at(TcoreHal *hal) { - if (!hal) + if (hal == NULL) return NULL; return hal->at; @@ -215,7 +219,7 @@ TcoreAT *tcore_hal_get_at(TcoreHal *hal) enum tcore_hal_mode tcore_hal_get_mode(TcoreHal *hal) { - if (!hal) + if (hal == NULL) return TCORE_HAL_MODE_UNKNOWN; return hal->mode; @@ -223,7 +227,7 @@ enum tcore_hal_mode tcore_hal_get_mode(TcoreHal *hal) TReturn tcore_hal_set_mode(TcoreHal *hal, enum tcore_hal_mode mode) { - if (!hal) + if (hal == NULL) return TCORE_RETURN_EINVAL; hal->mode = mode; @@ -233,7 +237,7 @@ TReturn tcore_hal_set_mode(TcoreHal *hal, enum tcore_hal_mode mode) TReturn tcore_hal_link_user_data(TcoreHal *hal, void *user_data) { - if (!hal) + if (hal == NULL) return TCORE_RETURN_EINVAL; hal->user_data = user_data; @@ -243,7 +247,7 @@ TReturn tcore_hal_link_user_data(TcoreHal *hal, void *user_data) void *tcore_hal_ref_user_data(TcoreHal *hal) { - if (!hal) + if (hal == NULL) return NULL; return hal->user_data; @@ -255,12 +259,12 @@ TReturn tcore_hal_send_data(TcoreHal *hal, unsigned int data_len, void *data) struct hook_send_type *hook; GSList *list; - if (!hal || !hal->ops || !hal->ops->send) + if ((hal == NULL) || (hal->ops == NULL) || (hal->ops->send == NULL)) return TCORE_RETURN_EINVAL; for (list = hal->hook_list_send; list; list = list->next) { hook = list->data; - if (!hook) { + if (hook == NULL) { continue; } @@ -278,7 +282,7 @@ TReturn tcore_hal_send_request(TcoreHal *hal, TcorePending *pending) int qlen = 0; enum tcore_pending_priority priority; - if (!hal || !pending) + if ((hal == NULL) || (pending == NULL)) return TCORE_RETURN_EINVAL; if (hal->power_state == FALSE) @@ -303,7 +307,7 @@ TReturn tcore_hal_send_request(TcoreHal *hal, TcorePending *pending) TReturn tcore_hal_send_force(TcoreHal *hal) { - if (!hal) + if (hal == NULL) return TCORE_RETURN_EINVAL; _hal_idle_send(hal); @@ -316,7 +320,7 @@ TReturn tcore_hal_dispatch_response_data(TcoreHal *hal, int id, { TcorePending *p = NULL; - if (!hal) + if (hal == NULL) return TCORE_RETURN_EINVAL; if (data_len > 0 && data == NULL) @@ -334,7 +338,7 @@ TReturn tcore_hal_dispatch_response_data(TcoreHal *hal, int id, if(hal->mode == TCORE_HAL_MODE_CUSTOM) { dbg("TCORE_HAL_MODE_CUSTOM"); p = tcore_queue_pop_by_id(hal->queue, id); - if (!p) { + if (p == NULL) { dbg("unknown pending (id=0x%x)", id); return TCORE_RETURN_PENDING_WRONG_ID; } @@ -347,8 +351,9 @@ TReturn tcore_hal_dispatch_response_data(TcoreHal *hal, int id, dbg("TCORE_HAL_MODE_TRANSPARENT"); /* Invoke CMUX receive API for decoding */ - tcore_cmux_rcv_from_hal((unsigned char *)data, data_len); + tcore_cmux_rcv_from_hal(hal, (unsigned char *)data, data_len); } + /* Send next request in queue */ g_idle_add_full(IDLE_SEND_PRIORITY, _hal_idle_send, hal, NULL ); } @@ -361,11 +366,11 @@ TReturn tcore_hal_add_recv_callback(TcoreHal *hal, TcoreHalReceiveCallback func, { struct recv_callback_item_type *item; - if (!hal) + if (hal == NULL) return TCORE_RETURN_EINVAL; - item = calloc(1, sizeof(struct recv_callback_item_type)); - if (!item) + item = g_try_new0(struct recv_callback_item_type, 1); + if (item == NULL) return TCORE_RETURN_ENOMEM; item->func = func; @@ -381,19 +386,19 @@ TReturn tcore_hal_remove_recv_callback(TcoreHal *hal, TcoreHalReceiveCallback fu struct recv_callback_item_type *item; GSList *list; - if (!hal) + if (hal == NULL) return TCORE_RETURN_EINVAL; for (list = hal->callbacks; list; list = list->next) { item = list->data; - if (!item) { + if (item == NULL) { continue; } if (item->func == func) { hal->callbacks = g_slist_remove(hal->callbacks, item); - free(item); - if (!hal->callbacks) + g_free(item); + if (hal->callbacks == NULL) break; list = hal->callbacks; @@ -409,7 +414,7 @@ TReturn tcore_hal_emit_recv_callback(TcoreHal *hal, unsigned int data_len, GSList *list; struct recv_callback_item_type *item; - if (!hal) + if (hal == NULL) return TCORE_RETURN_EINVAL; for (list = hal->callbacks; list; list = list->next) { @@ -428,11 +433,11 @@ TReturn tcore_hal_add_send_hook(TcoreHal *hal, TcoreHalSendHook func, void *user { struct hook_send_type *hook; - if (!hal || !func) + if ((hal == NULL) || (func == NULL)) return TCORE_RETURN_EINVAL; - hook = calloc(1, sizeof(struct hook_send_type)); - if (!hook) + hook = g_try_new0(struct hook_send_type, 1); + if (hook == NULL) return TCORE_RETURN_ENOMEM; hook->func = func; @@ -448,18 +453,18 @@ TReturn tcore_hal_remove_send_hook(TcoreHal *hal, TcoreHalSendHook func) struct hook_send_type *hook; GSList *list; - if (!hal) + if (hal == NULL) return TCORE_RETURN_EINVAL; for (list = hal->hook_list_send; list; list = list->next) { hook = list->data; - if (!hook) { + if (hook == NULL) { continue; } if (hook->func == func) { hal->hook_list_send = g_slist_remove(hal->hook_list_send, hook); - free(hook); + g_free(hook); list = hal->hook_list_send; } } @@ -469,7 +474,7 @@ TReturn tcore_hal_remove_send_hook(TcoreHal *hal, TcoreHalSendHook func) TcoreQueue *tcore_hal_ref_queue(TcoreHal *hal) { - if (!hal) + if (hal == NULL) return NULL; return hal->queue; @@ -477,7 +482,7 @@ TcoreQueue *tcore_hal_ref_queue(TcoreHal *hal) TcorePlugin *tcore_hal_ref_plugin(TcoreHal *hal) { - if (!hal) + if (hal == NULL) return NULL; return hal->parent_plugin; @@ -485,7 +490,7 @@ TcorePlugin *tcore_hal_ref_plugin(TcoreHal *hal) TReturn tcore_hal_set_power_state(TcoreHal *hal, gboolean flag) { - if (!hal) + if (hal == NULL) return TCORE_RETURN_EINVAL; hal->power_state = flag; @@ -495,7 +500,7 @@ TReturn tcore_hal_set_power_state(TcoreHal *hal, gboolean flag) gboolean tcore_hal_get_power_state(TcoreHal *hal) { - if (!hal) + if (hal == NULL) return FALSE; return hal->power_state; @@ -503,7 +508,7 @@ gboolean tcore_hal_get_power_state(TcoreHal *hal) TReturn tcore_hal_set_power(TcoreHal *hal, gboolean flag) { - if (!hal || !hal->ops || !hal->ops->power) + if ((hal == NULL) || (hal->ops == NULL) || (hal->ops->power == NULL)) return TCORE_RETURN_EINVAL; return hal->ops->power(hal, flag); @@ -514,7 +519,7 @@ TReturn tcore_hal_setup_netif(TcoreHal *hal, CoreObject *co, void *user_data, unsigned int cid, gboolean enable) { - if (!hal || !hal->ops || !hal->ops->setup_netif) + if ((hal == NULL) || (hal->ops == NULL) || (hal->ops->setup_netif == NULL)) return TCORE_RETURN_EINVAL; return hal->ops->setup_netif(co, func, user_data, cid, enable); diff --git a/src/mux.c b/src/mux.c old mode 100755 new mode 100644 index d4853b1..fb59d29 --- a/src/mux.c +++ b/src/mux.c @@ -2,7 +2,6 @@ * libtcore * * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * * Contact: Arijit Sen * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,89 +22,87 @@ #include #include +#include + #include #include "tcore.h" #include "hal.h" +#include "core_object.h" #include "plugin.h" #include "user_request.h" #include "server.h" +#include "at.h" #include "mux.h" -#include "core_object.h" -/* Maximum Core objects per Logical HAL (indirectly per Channel) */ -#define MAX_CMUX_CORE_OBJECTS 3 +/* Channel name maximum length */ +#define CMUX_MAX_CHANNEL_NAME 16 -/* Max CMUX Buffer size */ -#define MAX_CMUX_BUFFER_SIZE 4096 +/* CMUX Commands */ +#define CMUX_COMMAND_SABM 0x2F +#define CMUX_COMMAND_UA 0x63 +#define CMUX_COMMAND_DM 0x0F +#define CMUX_COMMAND_DISC 0x43 +#define CMUX_COMMAND_UIH 0xEF +#define CMUX_COMMAND_UI 0x03 -/* Max muber of CMUX Channels */ -#define MAX_CMUX_CHANNELS_SUPPORTED 8 +/* CMUX Delimiter Byte */ +#define CMUX_FRAME_DELIMITER 0xF9 -/* CMUX Commands */ -#define CMUX_COMMAND_SABM 0x2F -#define CMUX_COMMAND_UA 0x63 -#define CMUX_COMMAND_DM 0x0F -#define CMUX_COMMAND_DISC 0x43 -#define CMUX_COMMAND_UIH 0xEF -#define CMUX_COMMAND_UI 0x03 - -/* MUX CONTROL COMMANDS - * We are supporting only MSC command for phase 1 - */ -#define CMUX_COMMAND_MSC 0xE3 // Modem Status Command -#define CMUX_COMMAND_CLD 0xC3 // Multiplexer close down - -/* CMUX Channels [0-7] - - * Channel 0 - Control Channel for CMUX - * Channel 1 - CALL - * Channel 2 - SIM - * Channel 3 - SAT - * Channel 4 - SMS - * Channel 5 - SS - * Channel 6 - NETWORK - * Channel 7 - MODEM & PS - */ -typedef enum CMUX_Channels { - CMUX_CHANNEL_0, - CMUX_CHANNEL_1, - CMUX_CHANNEL_2, - CMUX_CHANNEL_3, - CMUX_CHANNEL_4, - CMUX_CHANNEL_5, - CMUX_CHANNEL_6, - CMUX_CHANNEL_7 -} CMUX_Channels; - -/* MUX Channel States */ -typedef enum MuxChannelState { - MUX_CHANNEL_CLOSED, - MUX_CHANNEL_SABM_SEND_WAITING_FOR_UA, - MUX_CHANNEL_ESTABLISHED, - MUX_CHANNEL_UA_NOT_RECEIVED_RETRY, - MUX_CHANNEL_DM_RECEIVED_CLOSING, - MUX_CHANNEL_DM_SEND, - MUX_CHANNEL_DISC_RECEIVED_CLOSING, - MUX_CHANNEL_DISC_SEND_WAITING_FOR_UA, - MUX_CHANNEL_UA_SEND_CLOSING, - MUX_CHANNEL_UA_RECEIVED, - MUX_CHANNEL_UA_SENDING, -} MuxChannelState; - -/* MUX State */ -typedef enum MuxState { - MUX_NOT_INITIALIZED, - MUX_INITIALIZED, - MUX_CLOSED -} MuxState; +/* + * CMUX Channels [0-64] - + * + * CMUX_CHANNEL_0 is dedicated CMUX Control Channnel. + */ +typedef enum { + CMUX_CHANNEL_NONE = -1, /* No CMUX */ + CMUX_CHANNEL_0 = 0, /* CMUX Control Channel */ + + CMUX_CHANNEL_MAX = 65 /* Based on #GPP 27.010 */ +} tcore_cmux_channel_id; + +/* + * CMUX Channel States + * + * Only Internal CMUX Channel states are managed, + * Kernel CMUX Channel states are managed by Kernel directly. + */ +typedef enum { + CMUX_CHANNEL_CLOSED, + CMUX_CHANNEL_SABM_SEND_WAITING_FOR_UA, + CMUX_CHANNEL_ESTABLISHED, + CMUX_CHANNEL_UA_NOT_RECEIVED_RETRY, + CMUX_CHANNEL_DM_RECEIVED_CLOSING, + CMUX_CHANNEL_DM_SEND, + CMUX_CHANNEL_DISC_RECEIVED_CLOSING, + CMUX_CHANNEL_DISC_SEND_WAITING_FOR_UA, + CMUX_CHANNEL_UA_SEND_CLOSING, + CMUX_CHANNEL_UA_RECEIVED, + CMUX_CHANNEL_UA_SENDING, +} tcore_cmux_channel_state; + +/* CMUX State */ +typedef enum { + CMUX_NOT_INITIALIZED, + CMUX_INITIALIZED, + CMUX_CLOSED +} tcore_cmux_state; + +/* + * CMUX CONTROL COMMANDS + * We are supporting only MSC and CLD commands for phase 1 + */ +/* Modem Status Command */ +#define CMUX_COMMAND_MSC 0xE3 +/* Multiplexer close down */ +#define CMUX_COMMAND_CLD 0xC3 #define FIND_LENGTH(buf, header_length, total_length) do { \ if (*buf & 0x01) { \ total_length = *buf++ >> 1; \ header_length = 6; \ - } \ - else { \ + } else { \ total_length = *(buf + 0x01) << 7; \ total_length = total_length | (*buf & 0xFE) >> 1; \ header_length = 7; \ @@ -113,854 +110,1069 @@ typedef enum MuxState { } while (0) /*================= CRC TABLE=========================*/ -const unsigned char crc_table[256] = { // reversed, 8-bit, poly=0x07 - 0x00, 0x91, 0xE3, 0x72, 0x07, 0x96, 0xE4, 0x75, 0x0E, 0x9F, 0xED, 0x7C, 0x09, 0x98, 0xEA, 0x7B, - 0x1C, 0x8D, 0xFF, 0x6E, 0x1B, 0x8A, 0xF8, 0x69, 0x12, 0x83, 0xF1, 0x60, 0x15, 0x84, 0xF6, 0x67, - 0x38, 0xA9, 0xDB, 0x4A, 0x3F, 0xAE, 0xDC, 0x4D, 0x36, 0xA7, 0xD5, 0x44, 0x31, 0xA0, 0xD2, 0x43, - 0x24, 0xB5, 0xC7, 0x56, 0x23, 0xB2, 0xC0, 0x51, 0x2A, 0xBB, 0xC9, 0x58, 0x2D, 0xBC, 0xCE, 0x5F, - 0x70, 0xE1, 0x93, 0x02, 0x77, 0xE6, 0x94, 0x05, 0x7E, 0xEF, 0x9D, 0x0C, 0x79, 0xE8, 0x9A, 0x0B, - 0x6C, 0xFD, 0x8F, 0x1E, 0x6B, 0xFA, 0x88, 0x19, 0x62, 0xF3, 0x81, 0x10, 0x65, 0xF4, 0x86, 0x17, - 0x48, 0xD9, 0xAB, 0x3A, 0x4F, 0xDE, 0xAC, 0x3D, 0x46, 0xD7, 0xA5, 0x34, 0x41, 0xD0, 0xA2, 0x33, - 0x54, 0xC5, 0xB7, 0x26, 0x53, 0xC2, 0xB0, 0x21, 0x5A, 0xCB, 0xB9, 0x28, 0x5D, 0xCC, 0xBE, 0x2F, - 0xE0, 0x71, 0x03, 0x92, 0xE7, 0x76, 0x04, 0x95, 0xEE, 0x7F, 0x0D, 0x9C, 0xE9, 0x78, 0x0A, 0x9B, - 0xFC, 0x6D, 0x1F, 0x8E, 0xFB, 0x6A, 0x18, 0x89, 0xF2, 0x63, 0x11, 0x80, 0xF5, 0x64, 0x16, 0x87, - 0xD8, 0x49, 0x3B, 0xAA, 0xDF, 0x4E, 0x3C, 0xAD, 0xD6, 0x47, 0x35, 0xA4, 0xD1, 0x40, 0x32, 0xA3, - 0xC4, 0x55, 0x27, 0xB6, 0xC3, 0x52, 0x20, 0xB1, 0xCA, 0x5B, 0x29, 0xB8, 0xCD, 0x5C, 0x2E, 0xBF, - 0x90, 0x01, 0x73, 0xE2, 0x97, 0x06, 0x74, 0xE5, 0x9E, 0x0F, 0x7D, 0xEC, 0x99, 0x08, 0x7A, 0xEB, - 0x8C, 0x1D, 0x6F, 0xFE, 0x8B, 0x1A, 0x68, 0xF9, 0x82, 0x13, 0x61, 0xF0, 0x85, 0x14, 0x66, 0xF7, - 0xA8, 0x39, 0x4B, 0xDA, 0xAF, 0x3E, 0x4C, 0xDD, 0xA6, 0x37, 0x45, 0xD4, 0xA1, 0x30, 0x42, 0xD3, - 0xB4, 0x25, 0x57, 0xC6, 0xB3, 0x22, 0x50, 0xC1, 0xBA, 0x2B, 0x59, 0xC8, 0xBD, 0x2C, 0x5E, 0xCF +const unsigned char crc_table[256] = { /* reversed, 8-bit, poly=0x07 */ + 0x00, 0x91, 0xE3, 0x72, 0x07, 0x96, 0xE4, 0x75, + 0x0E, 0x9F, 0xED, 0x7C, 0x09, 0x98, 0xEA, 0x7B, + 0x1C, 0x8D, 0xFF, 0x6E, 0x1B, 0x8A, 0xF8, 0x69, + 0x12, 0x83, 0xF1, 0x60, 0x15, 0x84, 0xF6, 0x67, + 0x38, 0xA9, 0xDB, 0x4A, 0x3F, 0xAE, 0xDC, 0x4D, + 0x36, 0xA7, 0xD5, 0x44, 0x31, 0xA0, 0xD2, 0x43, + 0x24, 0xB5, 0xC7, 0x56, 0x23, 0xB2, 0xC0, 0x51, + 0x2A, 0xBB, 0xC9, 0x58, 0x2D, 0xBC, 0xCE, 0x5F, + 0x70, 0xE1, 0x93, 0x02, 0x77, 0xE6, 0x94, 0x05, + 0x7E, 0xEF, 0x9D, 0x0C, 0x79, 0xE8, 0x9A, 0x0B, + 0x6C, 0xFD, 0x8F, 0x1E, 0x6B, 0xFA, 0x88, 0x19, + 0x62, 0xF3, 0x81, 0x10, 0x65, 0xF4, 0x86, 0x17, + 0x48, 0xD9, 0xAB, 0x3A, 0x4F, 0xDE, 0xAC, 0x3D, + 0x46, 0xD7, 0xA5, 0x34, 0x41, 0xD0, 0xA2, 0x33, + 0x54, 0xC5, 0xB7, 0x26, 0x53, 0xC2, 0xB0, 0x21, + 0x5A, 0xCB, 0xB9, 0x28, 0x5D, 0xCC, 0xBE, 0x2F, + 0xE0, 0x71, 0x03, 0x92, 0xE7, 0x76, 0x04, 0x95, + 0xEE, 0x7F, 0x0D, 0x9C, 0xE9, 0x78, 0x0A, 0x9B, + 0xFC, 0x6D, 0x1F, 0x8E, 0xFB, 0x6A, 0x18, 0x89, + 0xF2, 0x63, 0x11, 0x80, 0xF5, 0x64, 0x16, 0x87, + 0xD8, 0x49, 0x3B, 0xAA, 0xDF, 0x4E, 0x3C, 0xAD, + 0xD6, 0x47, 0x35, 0xA4, 0xD1, 0x40, 0x32, 0xA3, + 0xC4, 0x55, 0x27, 0xB6, 0xC3, 0x52, 0x20, 0xB1, + 0xCA, 0x5B, 0x29, 0xB8, 0xCD, 0x5C, 0x2E, 0xBF, + 0x90, 0x01, 0x73, 0xE2, 0x97, 0x06, 0x74, 0xE5, + 0x9E, 0x0F, 0x7D, 0xEC, 0x99, 0x08, 0x7A, 0xEB, + 0x8C, 0x1D, 0x6F, 0xFE, 0x8B, 0x1A, 0x68, 0xF9, + 0x82, 0x13, 0x61, 0xF0, 0x85, 0x14, 0x66, 0xF7, + 0xA8, 0x39, 0x4B, 0xDA, 0xAF, 0x3E, 0x4C, 0xDD, + 0xA6, 0x37, 0x45, 0xD4, 0xA1, 0x30, 0x42, 0xD3, + 0xB4, 0x25, 0x57, 0xC6, 0xB3, 0x22, 0x50, 0xC1, + 0xBA, 0x2B, 0x59, 0xC8, 0xBD, 0x2C, 0x5E, 0xCF }; /*================= CRC TABLE=========================*/ /* CMUX Channel */ -typedef struct cmux_channel { - GSList *co; +struct cmux_channel { TcoreHal *hal; - MuxChannelState state; - CMUX_Channels channel_id; + + tcore_cmux_channel_state channel_state; + tcore_cmux_channel_id channel_id; + int frame_type; unsigned char ext_bit; unsigned char cr_bit; unsigned char poll_final_bit; -} CHANNEL; +}; -/* CMUX callback prototype */ -typedef gboolean (*mux_cb_func)(CHANNEL *channel_ptr); +/* CMUX structure - Internal */ +struct cmux_internal { + tcore_cmux_channel *channel_info[CMUX_CHANNEL_MAX]; -/* CMUX structure */ -typedef struct cmux { - MuxState state; - CHANNEL *channel_info[MAX_CMUX_CHANNELS_SUPPORTED]; int is_waiting; + int msg_len; int cur_main_buf_len; - TcorePlugin *plugin; - TcoreHal *phy_hal; - CoreObject *modem_co; - mux_cb_func cb_func; - int info_field_len; - unsigned char *info_field; -} MUX; -/* Global pointer MUX Object pointer */ -MUX *g_mux_obj_ptr = NULL; + /* Channel Setup callbacks */ + cmux_setup_cb_func channel_setup_cb; + gpointer channel_setup_user_data; -/* CMUX mode of operation */ -int g_mux_mode = 0; /* BASIC mode */ - -struct cmux_channel_object { - char *channel_id_name; - char *core_object_name[MAX_CMUX_CORE_OBJECTS]; -}; + /* Channel Setup complete callback */ + cmux_setup_complete_cb_func setup_complete_cb; + gpointer setup_complete_user_data; -/* Core Object names need to be verified, define a MACRO globally */ -struct cmux_channel_object cmux_channel_core_object[] = { - {"channel_0", {"control", NULL, NULL}}, - {"channel_1", {"call", NULL, NULL}}, - {"channel_2", {"sim", "phonebook", NULL}}, - {"channel_3", {"sat", "sap", NULL}}, - {"channel_4", {"umts_sms", NULL, NULL}}, - {"channel_5", {"ss", NULL, NULL}}, - {"channel_6", {"umts_network", "gps", NULL}}, - {"channel_7", {"modem", "umts_ps", NULL}}, + int info_field_len; + unsigned char *info_field; }; -/* All the local functions declared below */ -static unsigned char calc_crc(unsigned char *header, int length); -static int rcv_crc_check(unsigned char *data, unsigned char len, unsigned char rcv_FCS); -MUX* tcore_cmux_new(void); -static void tcore_cmux_free(void); -void tcore_cmux_link_core_object_hal(CMUX_Channels channel_id, TcorePlugin *plugin); -static gboolean tcore_cmux_recv_mux_data(CHANNEL *channel_ptr); -static void tcore_cmux_process_rcv_frame(unsigned char *data, int len); -static void tcore_cmux_process_channel_data(CHANNEL *channel_info_ptr); -static void tcore_cmux_control_channel_handle(void); -static void tcore_cmux_flush_channel_data(void); -static void tcore_cmux_channel_init(CMUX_Channels channel_id); -static void tcore_cmux_close_channel(int channel_id); -static unsigned char* tcore_encode_cmux_frame(unsigned char *data, int length, int channel_id, int frame_type, unsigned char EA_bit, unsigned char CR_bit, unsigned char PF_bit, int *out_data_len); -static TReturn tcore_cmux_send_data(int data_len, unsigned char *data); -static TReturn tcore_cmux_hal_power(TcoreHal *h, gboolean flag) -{ - TcorePlugin *p = NULL; - struct custom_data *user_data = NULL; - - dbg("Entry"); - - p = tcore_hal_ref_plugin(h); - if (!p) { - err("Plugin is undefined"); - return TCORE_RETURN_FAILURE; - } - - user_data = tcore_hal_ref_user_data(h); - if (!user_data) { - err("User data is undefined"); - return TCORE_RETURN_FAILURE; - } - - tcore_hal_set_power_state(h, TRUE); - - dbg("Exit"); - return TCORE_RETURN_SUCCESS; -} - -static TReturn tcore_cmux_hal_send(TcoreHal *h, unsigned int data_len, void *data) -{ - unsigned char *send_data = NULL; - char *channel_name = NULL; - int channel_id = MAX_CMUX_CHANNELS_SUPPORTED; - int len = 0; - int i = 0; - int ret; +/* Global CMUX Object */ +struct cmux_obj { + /* Physical HAL */ + TcoreHal *phy_hal; - dbg("Entry"); + /* Modem Interface Plug-in */ + TcorePlugin *plugin; - /* Check if Logical HAL is Powered ON */ - if (tcore_hal_get_power_state(h) == FALSE) { - err("HAL is not Powered UP"); - return TCORE_RETURN_FAILURE; - } + tcore_cmux_state cmux_state; - channel_name = tcore_hal_get_name(h); - dbg("HAL name: %s", channel_name) - if (channel_name) { - while (i < MAX_CMUX_CHANNELS_SUPPORTED) { - if (0 == strcmp((char *) cmux_channel_core_object[i].channel_id_name, (char *) channel_name)) { - channel_id = i; - dbg("Found Channel ID: %d", channel_id); + tcore_cmux_mode cmux_mode; + int max_cmux_channels; + unsigned int max_cmux_buf_size; - /* Free memory */ - free(channel_name); - break; - } - i++; - } - } else { - err("No name defined for HAL"); - return TCORE_RETURN_FAILURE; - } + /* CMUX frame processing buffer */ + unsigned char *cmux_buffer; - if (channel_id > MAX_CMUX_CHANNELS_SUPPORTED) { - err("Failed to find Channel ID"); - return TCORE_RETURN_FAILURE; - } + /* Only Internal MUX is managed by libtcore */ + struct cmux_internal internal_mux; +}; - /* Muxing operation and Frame creation */ - /* Encoding frame */ - send_data = tcore_encode_cmux_frame(data, data_len, channel_id, CMUX_COMMAND_UIH, 1, 1, 0, &len); - if (0 == len) { - err("Failed to encode"); - return TCORE_RETURN_FAILURE; - } +/* CMUX Object */ +static GSList *g_cmux_obj = NULL; - /* Send CMUX data */ - ret = tcore_cmux_send_data(len, send_data); +/* All the local functions declared below */ +static void _cmux_on_confirmation_message_send(TcorePending *plugin, + gboolean result, void *user_data); - dbg("Exit"); - return TCORE_RETURN_SUCCESS; -} +tcore_cmux_object *_cmux_new(int max_channels, unsigned int buffer_size); +static void _cmux_free(tcore_cmux_object *cmux_obj); -static TReturn tcore_cmux_hal_setup_netif(CoreObject *co, - TcoreHalSetupNetifCallback func, - void *user_data, unsigned int cid, - gboolean enable) -{ - TcoreHal *hal = g_mux_obj_ptr->phy_hal; +static void _cmux_channel_init(tcore_cmux_object *cmux_obj, int channel_id); +static void _cmux_close_channel(tcore_cmux_object *cmux_obj, int channel_id); - if (hal == NULL) - return TCORE_RETURN_EINVAL; +static TcoreHal *_cmux_create_logical_hal(tcore_cmux_object *cmux_obj, + tcore_cmux_channel *channel); - return tcore_hal_setup_netif(hal, co, func, user_data, cid, enable); -} +static gboolean _cmux_recv_cmux_data(tcore_cmux_object *cmux_obj, + tcore_cmux_channel *channel); +static void _cmux_process_rcv_frame(tcore_cmux_object *cmux_obj, int length); +static void _cmux_process_channel_data(tcore_cmux_object *cmux_obj, + tcore_cmux_channel *channel); -/* CMUX supported HAL (Logical HAL) operations */ -static struct tcore_hal_operations mux_hops = { - .power = tcore_cmux_hal_power, - .send = tcore_cmux_hal_send, - .setup_netif = tcore_cmux_hal_setup_netif, -}; +static void _cmux_control_channel_handle(tcore_cmux_object *cmux_obj); +static void _cmux_flush_channel_data(tcore_cmux_object *cmux_obj); -static TReturn tcore_cmux_send_data(int data_len, unsigned char *data) -{ - TReturn ret = TCORE_RETURN_SUCCESS; +static TReturn _cmux_send_data(TcoreHal *hal, int data_len, unsigned char *data); +static unsigned char *_cmux_encode_cmux_frame(tcore_cmux_object *cmux_obj, + unsigned char *data, unsigned int length, int channel_id, + int frame_type, unsigned char EA_bit, unsigned char CR_bit, + unsigned char PF_bit, int *out_data_len); - dbg("Entry"); +static tcore_cmux_object *_cmux_get_cmux_object(TcorePlugin *plugin); - /* Directly send to Physical HAL */ - ret = tcore_hal_send_data(g_mux_obj_ptr->phy_hal, data_len, (void *) data); - if (TCORE_RETURN_SUCCESS != ret) { - err("Failed to send CMUX data"); - } else { - dbg("Successfully sent CMUX data"); - } +static unsigned char _cmux_calc_crc(unsigned char *header, int length); +static int _cmux_check_recv_crc(unsigned char *data, + unsigned char length, + unsigned char rcv_fcs); - dbg("Exit"); - return ret; -} -static gboolean tcore_cmux_recv_mux_data(CHANNEL *channel_ptr) +static unsigned char _cmux_calc_crc(unsigned char *header, int length) { - TcoreHal *hal = NULL; - - dbg("Entry"); + unsigned char fcs = 0xFF; /* Init */ + unsigned char crc = 0x00; - /* Dereferencing HAL from Channel Pointer */ - hal = channel_ptr->hal; + /* + * 'length' is the number of bytes in the message, + * 'header' points to message + */ + while (length--) + fcs = crc_table[fcs ^ *header++]; - dbg("Dispatching to logical HAL - hal: %x", (unsigned int)hal); - tcore_hal_dispatch_response_data(hal, 0, g_mux_obj_ptr->info_field_len, g_mux_obj_ptr->info_field); + /* Ones complement */ + crc = (0xFF - fcs); - dbg("Exit"); - return TRUE; + dbg("Exit - crc: 0x%02x", crc) + return crc; } -void tcore_cmux_link_core_object_hal(CMUX_Channels channel_id, TcorePlugin *plugin) +static int _cmux_check_recv_crc(unsigned char *data, + unsigned char length, + unsigned char rcv_fcs) { - TcoreHal *hal = NULL; - CoreObject *co = NULL; - int index; - - dbg("Entry"); - - if (CMUX_CHANNEL_0 != channel_id) { - dbg("Normal channel [%d]", channel_id); - - /* Creating Logical HAL for Core Object - Mode - 'AT mode' */ - hal = tcore_hal_new(plugin, cmux_channel_core_object[channel_id].channel_id_name, &mux_hops, TCORE_HAL_MODE_AT); - dbg("hal: %p", hal); - - /* Update Logical HAL of CMUX Channel */ - g_mux_obj_ptr->channel_info[channel_id]->hal = hal; - - index = 0; - while (NULL != cmux_channel_core_object[channel_id].core_object_name[index]) { - /* Retrieving Core Object */ - dbg("Core Object: '%s'", cmux_channel_core_object[channel_id].core_object_name[index]); - co = tcore_plugin_ref_core_object(plugin, cmux_channel_core_object[channel_id].core_object_name[index]); - dbg("co: %p", co); - - if (0 == strcmp((const char *) cmux_channel_core_object[channel_id].core_object_name[index], "modem")) { - g_mux_obj_ptr->modem_co = co; - dbg("'modem' Core object reference is stored"); - } - - /* Set Logical HAL to Core objects */ - tcore_object_set_hal(co, hal); - - /* Update Core Object list of CMUX Channel */ - g_mux_obj_ptr->channel_info[channel_id]->co = g_slist_append(g_mux_obj_ptr->channel_info[channel_id]->co, co); - - /* Next Core Object of the channel */ - index++; - } - } else { - /* Control Channel */ - dbg("Control channel"); + unsigned char fcs = 0xFF; /* Init */ - /* Creating Logical HAL for Core Object - Mode - 'AT mode' */ - hal = tcore_hal_new(plugin, cmux_channel_core_object[channel_id].channel_id_name, &mux_hops, TCORE_HAL_MODE_AT); - dbg("hal: %p", hal); - - /* Update Logical HAL of CMUX Channel */ - g_mux_obj_ptr->channel_info[channel_id]->hal = hal; - } + /* + * 'length' is the number of bytes in the message, + * 'data' points to message + */ + while (length--) + fcs = crc_table[fcs ^ *data++]; - /* Set Logical HAL Power State to TRUE */ - tcore_hal_set_power_state(hal, TRUE); - dbg("HAL Power is SET"); + /* Ones complement */ + fcs = crc_table[fcs ^ rcv_fcs]; - dbg("Exit"); - return; + /* 0xCF is the reversed order of 11110011 */ + if (fcs == 0xCF) /* FCS is OK */ + return 1; + else /* FCS is NOT OK */ + return 0; } -MUX* tcore_cmux_new(void) +static tcore_cmux_object *_cmux_get_cmux_object(TcorePlugin *plugin) { - MUX *mux = NULL; - int i = 0; - - /* Allocating memory for mux */ - mux = (MUX *) calloc(1, sizeof(MUX)); - if (!mux) { - err("Failed to allocate memory"); - return NULL; - } - - /* Allocating memory for info_field */ - mux->info_field = (unsigned char *) calloc(MAX_CMUX_BUFFER_SIZE, 1); - if (!mux->info_field) { - err("Failed to allocate memory for info field"); - goto ERROR; - } - - /* MUX State initialize to MUX_NOT_INITIALIZED */ - mux->state = MUX_NOT_INITIALIZED; - - /* Allocating memory for channel_info */ - for (i = 0; i < MAX_CMUX_CHANNELS_SUPPORTED; i++) { - mux->channel_info[i] = (CHANNEL *) calloc(1, sizeof(CHANNEL)); - /* Check for Memory allocation failure */ - if (!mux->channel_info[i]) { - err("Failed to allocate memory for channel_info of channel: %d", i); - goto ERROR; - } - } - - return mux; + tcore_cmux_object *cmux_obj; + GSList *tmp_obj; -ERROR: - /* Free allocated memory */ - if (mux) { - if (mux->info_field) { - free(mux->info_field); - } + /* Check across CMUX Objects list for specific CMUX Object */ + tmp_obj = g_cmux_obj; + while (tmp_obj) { + cmux_obj = tmp_obj->data; + tmp_obj = tmp_obj->next; - for (i = 0; i < MAX_CMUX_CHANNELS_SUPPORTED; i++) { - if (mux->channel_info[i]) { - free(mux->channel_info[i]); - } - } + if (cmux_obj == NULL) + continue; - free(mux); + /* Check for matching 'plugin' */ + if (plugin == cmux_obj->plugin) + return cmux_obj; } - err("Exit"); return NULL; } -static unsigned char calc_crc(unsigned char *header, int length) -{ - unsigned char FCS = 0xFF; /*Init*/ - unsigned char crc = 0x00; - - /* 'length' is the number of bytes in the message, 'header' points to message */ - while (length--) { - FCS = crc_table[FCS ^ *header++]; - } - - /*Ones complement*/ - crc = (0xFF - FCS); - - dbg("Exit - crc: 0x%02x", crc) - return crc; -} - -static unsigned char* tcore_encode_cmux_frame(unsigned char *data, - int length, - int channel_id, - int frame_type, - unsigned char EA_bit, - unsigned char CR_bit, - unsigned char PF_bit, - int *out_data_len) +static unsigned char *_cmux_encode_cmux_frame(tcore_cmux_object *cmux_obj, + unsigned char *data, unsigned int length, int channel_id, + int frame_type, unsigned char EA_bit, unsigned char CR_bit, + unsigned char PF_bit, int *out_data_len) { int frame_length = 0; int total_frame_length = 0; int crc_len = 0; - dbg("Entry"); /* Flush channel data */ - tcore_cmux_flush_channel_data(); + _cmux_flush_channel_data(cmux_obj); - if (length > MAX_CMUX_BUFFER_SIZE) { + if (length > cmux_obj->max_cmux_buf_size) { err("Length - %d exceeds the limit", length); return NULL; } /* Flag Octet */ - g_mux_obj_ptr->info_field[frame_length++] = (char) 0xF9; + cmux_obj->internal_mux.info_field[frame_length++] = CMUX_FRAME_DELIMITER; /* Mode of Operation */ - if (0x00 == g_mux_mode) { /* BASIC */ - /* EA: Extension Bit - * C/R: Command Response - */ - g_mux_obj_ptr->info_field[frame_length] = g_mux_obj_ptr->info_field[frame_length] | ((EA_bit & 0x01) | ((CR_bit << 1) & 0x02)); + if (cmux_obj->cmux_mode == CMUX_MODE_BASIC) { /* BASIC */ + /* + * EA: Extension Bit + * C/R: Command Response + */ + cmux_obj->internal_mux.info_field[frame_length] = + (cmux_obj->internal_mux.info_field[frame_length] + | ((EA_bit & 0x01) | ((CR_bit << 1) & 0x02))); /* DLCI: Data Link Connection Identifier */ /* Check if the channel is within range */ - if (channel_id < MAX_CMUX_CHANNELS_SUPPORTED && channel_id >= 0) { + if (channel_id < cmux_obj->max_cmux_channels && channel_id >= 0) { dbg("Channel ID: %d", channel_id); - g_mux_obj_ptr->info_field[frame_length] = g_mux_obj_ptr->info_field[frame_length] | ((unsigned char) channel_id << 2); + cmux_obj->internal_mux.info_field[frame_length] = + (cmux_obj->internal_mux.info_field[frame_length] + | ((unsigned char)channel_id << 2)); } else { - err("Channel is out of range[0-8]"); + err("Channel ID [%d] is out of range [0-%d]", + channel_id, cmux_obj->max_cmux_channels); return NULL; } frame_length++; - /* Control Field - * The content of the control field defines the type of frame. - * **************************************************************** - * Frame Type 0 1 2 3 4 5 6 7 - * SABM (Set Asynchronous Balanced Mode) 1 1 1 1 P/F 1 0 0 - * UA (Unnumbered Acknowledgement) 1 1 0 0 P/F 1 1 0 - * DM (Disconnected Mode) 1 1 1 1 P/F 0 0 0 - * DISC (Disconnect) 1 1 0 0 P/F 0 1 0 - * UIH (Unnumbered Information with Header check) 1 1 1 1 P/F 1 1 1 - *****************************************************************/ - if (PF_bit) { - g_mux_obj_ptr->info_field[frame_length++] = frame_type | 0x10; - } else { - g_mux_obj_ptr->info_field[frame_length++] = frame_type; - } + /* + * Control Field + * + * The content of the control field defines the type of frame. + * **************************************************************** + * Frame Type 0 1 2 3 4 5 6 7 + * SABM (Set Asynchronous Balanced Mode) 1 1 1 1 P/F 1 0 0 + * UA (Unnumbered Acknowledgement) 1 1 0 0 P/F 1 1 0 + * DM (Disconnected Mode) 1 1 1 1 P/F 0 0 0 + * DISC (Disconnect) 1 1 0 0 P/F 0 1 0 + * UIH (Unnumbered Information with Header check) 1 1 1 1 P/F 1 1 1 + ******************************************************************/ + if (PF_bit) + cmux_obj->internal_mux.info_field[frame_length++] = + frame_type | 0x10; + else + cmux_obj->internal_mux.info_field[frame_length++] = frame_type; /* 5.2.1.5 Length Indicator */ if (length < 128) { - g_mux_obj_ptr->info_field[frame_length++] = (char) length << 1 | 0x01; + cmux_obj->internal_mux.info_field[frame_length++] = + (char) length << 1 | 0x01; /* CRC calculatable length */ crc_len = 3; } else { - g_mux_obj_ptr->info_field[frame_length++] = (char) (length << 1); // Need to change - g_mux_obj_ptr->info_field[frame_length++] = (char) (length >> 7); // Need to change + cmux_obj->internal_mux.info_field[frame_length++] = + (char) (length << 1); + cmux_obj->internal_mux.info_field[frame_length++] = + (char) (length >> 7); /* CRC calculatable length */ crc_len = 4; } - /* We need to divide the frames into maximum frame length supported by IMC. - * If IMC supports length according to 27.010 , we can send max of 16,384 bytes. - * Need to discuss with IMC. - */ + /* + * We need to divide the frames into maximum frame length supported by IMC. + * If IMC supports length according to 27.010 , we can send max of 16,384 bytes. + * Need to discuss with IMC. + */ - /* 5.2.1.4 Information Field*/ + /* 5.2.1.4 Information Field */ if (length > 0) { - memcpy((g_mux_obj_ptr->info_field + frame_length), data, length); + memcpy((cmux_obj->internal_mux.info_field + frame_length), + data, length); frame_length += length; - } else { + } else dbg("info field length is zero"); - } - /*5.2.1.6 Frame Checking Sequence Field (FCS)*/ - g_mux_obj_ptr->info_field[frame_length++] = calc_crc(g_mux_obj_ptr->info_field + 1, crc_len); + /* 5.2.1.6 Frame Checking Sequence Field (FCS) */ + cmux_obj->internal_mux.info_field[frame_length++] = + _cmux_calc_crc(cmux_obj->internal_mux.info_field + 1, crc_len); - /*Flag Octet*/ - g_mux_obj_ptr->info_field[frame_length++] = 0xF9; + /* Flag Octet */ + cmux_obj->internal_mux.info_field[frame_length++] = CMUX_FRAME_DELIMITER; total_frame_length = frame_length; - } else if (0x01 == g_mux_mode) { /* TBD MUX_MODE_ADVANCE */ - dbg("Advanced MUX mode : TBD"); + } else if (cmux_obj->cmux_mode == CMUX_MODE_ADVANCED) { + /* TBD CMUX_MODE_ADVANCE */ + dbg("Advanced CMUX mode : TBD"); } *out_data_len = total_frame_length; - dbg("*out_data_len: %d", *out_data_len); + dbg("Data Length: %d", *out_data_len); dbg("Exit total_frame_length: %d", total_frame_length); - return g_mux_obj_ptr->info_field; -} - -static int rcv_crc_check(unsigned char *data, unsigned char len, unsigned char rcv_FCS) -{ - unsigned char FCS = 0xFF; - - /* 'len' is the number of bytes in the message, 'data' points to message */ - while (len--) { - FCS = crc_table[FCS ^ *data++]; - } - - /*Ones complement*/ - FCS = crc_table[FCS ^ rcv_FCS]; - - /* 0xCF is the reversed order of 11110011 */ - if (0xCF == FCS) { /* FCS is OK */ - return 1; - } else { /* FCS is NOT OK */ - return 0; - } -} - -static void tcore_cmux_flush_channel_data(void) -{ - dbg("Entry"); - - g_mux_obj_ptr->info_field_len = 0x0; - memset(g_mux_obj_ptr->info_field, 0x0, MAX_CMUX_BUFFER_SIZE); - - dbg("Exit"); - return; + return cmux_obj->internal_mux.info_field; } -static void tcore_cmux_control_channel_handle(void) +static void _cmux_control_channel_handle(tcore_cmux_object *cmux_obj) { unsigned char cmd_type; int msg_len = 0; - unsigned char *msg_start_ptr = NULL; - + unsigned char *msg_start_ptr; dbg("Entry"); - /* 5.4.6.1 Message format - * All messages sent between the multiplexers conform to the following type, length, value format: - * Type Length Value 1 Value2 \85 - */ - if (g_mux_obj_ptr->info_field_len > 0) { - msg_start_ptr = g_mux_obj_ptr->info_field; - cmd_type = g_mux_obj_ptr->info_field[0]; - - /* The EA bit is an extension bit. The EA bit is set to 1 in the last octet of the sequence; - * in other octets EA is set to 0. - * - * Search for the last octet - */ - while ((*msg_start_ptr++ & 0x01)) { // TBD + /* + * 5.4.6.1 Message format + * All messages sent between the multiplexers conform to the following + * type, length, value format: + * Type Length Value 1 Value2 \85 + */ + if (cmux_obj->internal_mux.info_field_len > 0) { + msg_start_ptr = cmux_obj->internal_mux.info_field; + cmd_type = cmux_obj->internal_mux.info_field[0]; + + /* + * The EA bit is an extension bit. The EA bit is set to 1 in the last octet + * of the sequence; in other octets EA is set to 0. + * + * Search for the last octet + */ + while ((*msg_start_ptr++ & 0x01)) msg_len++; - } - if ((cmd_type & 0x02) == 0x02) { // This is a command Request + if ((cmd_type & 0x02) == 0x02) { /* This is a command Request */ switch (cmd_type) { - case CMUX_COMMAND_MSC: - { - dbg("Modem Status Command"); - break; - } - - case CMUX_COMMAND_CLD: - { - dbg("Multiplexer close down"); - tcore_cmux_close(); - break; - } - - default: - { - /* We will be supporting these commands in Phase 2 */ - dbg("Default"); - break; - } + case CMUX_COMMAND_MSC: + dbg("Modem Status Command"); + break; + case CMUX_COMMAND_CLD: + dbg("Multiplexer close down"); + + cmux_obj->cmux_state = CMUX_CLOSED; + tcore_cmux_close(cmux_obj->phy_hal); + break; + default: + /* We will be supporting these commands in Phase 2 */ + dbg("Default"); + break; } } - } else { + } else err("Frame length is less than ZERO"); - } dbg("Exit"); - return; } -static void tcore_cmux_process_channel_data(CHANNEL *channel_info_ptr) +static void _cmux_process_channel_data(tcore_cmux_object *cmux_obj, + tcore_cmux_channel *channel) { int frame_type; int channel_id; int len; - unsigned char *send_data = NULL; + unsigned char *send_data; static int count = 0; int ret; - dbg("Entry"); - channel_id = channel_info_ptr->channel_id; + channel_id = channel->channel_id; dbg("Channel ID: %d", channel_id); - frame_type = channel_info_ptr->frame_type & 0xEF; + frame_type = channel->frame_type & 0xEF; dbg("frame_type: 0x%x", frame_type); switch (frame_type) { - case CMUX_COMMAND_UI: - case CMUX_COMMAND_UIH: - { - dbg("Received UI/UIH Frame"); - if (0 == channel_id) { /* This is control info */ - dbg("Control information"); - tcore_cmux_control_channel_handle(); - } else { - dbg("Normal information"); - // put in the logical HAL queue, this goes to the Cobject - tcore_cmux_recv_mux_data(channel_info_ptr); - } - break; - } + case CMUX_COMMAND_UI: + case CMUX_COMMAND_UIH: + dbg("Received UI/UIH Frame"); + if (channel_id == CMUX_CHANNEL_0) { /* This is control info */ + dbg("Control information"); + _cmux_control_channel_handle(cmux_obj); + } else { + dbg("Normal information"); - case CMUX_COMMAND_UA: - { - dbg("Received UA Frame"); - dbg("channel_info_ptr->state: %d", channel_info_ptr->state); - if (MUX_CHANNEL_SABM_SEND_WAITING_FOR_UA == channel_info_ptr->state) { - channel_info_ptr->state = MUX_CHANNEL_ESTABLISHED; - - count++; - dbg("Count: %d", count); - if (MAX_CMUX_CHANNELS_SUPPORTED == count) { - /* Indicate to CoreObject */ - CoreObject *co = NULL; - - /* 'modem' Core Object */ - co = g_mux_obj_ptr->modem_co; - if (NULL == co) { - err("'modem' Core object is not present"); - return; + /* Put in the logical HAL queue, this goes to the Cobject */ + if (FALSE == _cmux_recv_cmux_data(cmux_obj, channel)) + err("Failed receive callback"); + } + break; + case CMUX_COMMAND_UA: + dbg("Received UA Frame"); + dbg("channel->channel_state: %d", channel->channel_state); + if (CMUX_CHANNEL_SABM_SEND_WAITING_FOR_UA == channel->channel_state) { + channel->channel_state = CMUX_CHANNEL_ESTABLISHED; + + if (channel->channel_id != CMUX_CHANNEL_0) { + TcoreHal *hal; + + /* Create Logical HAL */ + hal = _cmux_create_logical_hal(cmux_obj, channel); + if (hal != NULL) { + dbg("Invoking CMUX Channel Setup callback for [%d] channel", + channel->channel_id); + /* + * 'channel_setup_cb' cannot be NULL as it is MANDATED during + * CMUX setup operation. + */ + cmux_obj->internal_mux.channel_setup_cb(channel->channel_id, hal, + cmux_obj->internal_mux.channel_setup_user_data); + } else + err("Failed to Create Logical HAL"); } - /* Emit callback */ - dbg("Emit Core object callback"); - tcore_object_emit_callback(co, "CMUX-UP", NULL); - dbg("Emitted Core object callback"); - - /* Reset 'count' */ - count = 0; - } - } else if (MUX_CHANNEL_DISC_SEND_WAITING_FOR_UA == channel_info_ptr->state) { - channel_info_ptr->state = MUX_CHANNEL_CLOSED; + count++; + dbg("Count: %d", count); + if (cmux_obj->max_cmux_channels == count) { + dbg("Invoking CMUX Channel Setup Complete callback - Total Channels: [%d]", + count); + /* + * 'setup_complete_cb' cannot be NULL as it is MANDATED during + * CMUX setup operation. + */ + cmux_obj->internal_mux.setup_complete_cb( + cmux_obj->internal_mux.setup_complete_user_data); + + /* Reset 'count' */ + count = 0; + } + } else if (CMUX_CHANNEL_DISC_SEND_WAITING_FOR_UA == + channel->channel_state) { + channel->channel_state = CMUX_CHANNEL_CLOSED; - if (0 == channel_id) { - g_mux_obj_ptr->state = MUX_CLOSED; - tcore_cmux_close(); + if (channel_id == CMUX_CHANNEL_0) { + cmux_obj->cmux_state = CMUX_CLOSED; + tcore_cmux_close(cmux_obj->phy_hal); + } + } else + err("Received UA in wrong state!!!"); + + break; + case CMUX_COMMAND_DM: + /* + * 5.4.1 DLC Establishment : If the responding station is not ready or unwilling + * to establish the particular DLC it will reply with a DM frame with the + * F-bit set to 1. + */ + dbg("Received DM Frame"); + if ((channel->channel_state == CMUX_CHANNEL_ESTABLISHED) + || (channel->channel_state == + CMUX_CHANNEL_SABM_SEND_WAITING_FOR_UA)) { + /* Channel State set to Close */ + channel->channel_state = CMUX_CHANNEL_CLOSED; } - } else { - err("Received UA in wrong state!!!"); - } - break; - } - - case CMUX_COMMAND_DM: - { - /* 5.4.1 DLC Establishment : If the responding station is not ready or unwilling - * to establish the particular DLC it will reply with a DM frame with the - * F-bit set to 1. - */ - dbg("Received DM Frame"); - if ((MUX_CHANNEL_ESTABLISHED == channel_info_ptr->state) - || (MUX_CHANNEL_SABM_SEND_WAITING_FOR_UA == channel_info_ptr->state)) { - /* Channel State set to Close */ - channel_info_ptr->state = MUX_CHANNEL_CLOSED; - } - - /* Flush the Channel data */ - tcore_cmux_flush_channel_data(); - - break; - } - - case CMUX_COMMAND_DISC: - { - dbg("Received DISC Frame"); - if (0 == channel_info_ptr->poll_final_bit) { - /* In the case where a CMUX_COMMAND_SABM or CMUX_COMMAND_DISC command with - * the P bit set to 0 is received then the received frame shall be discarded. - */ /* Flush the Channel data */ - tcore_cmux_flush_channel_data(); - } else { - if (MUX_CHANNEL_CLOSED == channel_info_ptr->state) { - /* If a CMUX_COMMAND_DISC command is received while in disconnected mode - * a CMUX_COMMAND_DM response should be sent - */ - - /* Encoding frame */ - send_data = tcore_encode_cmux_frame(NULL, 0, channel_id, CMUX_COMMAND_DM, 1, 1, 1, &len); - } else { // send Unnumbered Acknowledgement - send_data = tcore_encode_cmux_frame(NULL, 0, channel_id, CMUX_COMMAND_UA, 1, 1, 1, &len); - } + _cmux_flush_channel_data(cmux_obj); + break; + case CMUX_COMMAND_DISC: + dbg("Received DISC Frame"); + if (channel->poll_final_bit == 0) { + /* + * In the case where a CMUX_COMMAND_SABM or + * CMUX_COMMAND_DISC command with + * the P bit set to 0 is received then the received frame shall be + * discarded. + */ + + /* Flush the Channel data */ + _cmux_flush_channel_data(cmux_obj); + } else { + if (channel->channel_state == CMUX_CHANNEL_CLOSED) { + /* + * If a CMUX_COMMAND_DISC command is received while in + * disconnected mode a CMUX_COMMAND_DM response should + * be sent + */ + + /* Encoding frame */ + send_data = _cmux_encode_cmux_frame(cmux_obj, NULL, + 0, channel_id, CMUX_COMMAND_DM, + 0x01, 0x01, 0x01, &len); + } else { /* Send Unnumbered Acknowledgement */ + /* Encoding frame */ + send_data = _cmux_encode_cmux_frame(cmux_obj, NULL, + 0, channel_id, CMUX_COMMAND_UA, + 0x01, 0x01, 0x01, &len); + } - if (0 == len) { - err("Failed to encode"); - return; - } + if (len == 0) { + err("Failed to encode"); + return; + } - /* Send CMUX data */ - ret = tcore_cmux_send_data(len, send_data); + /* Send CMUX data */ + ret = _cmux_send_data(cmux_obj->phy_hal, len, send_data); - /* Flush the Channel data */ - tcore_cmux_flush_channel_data(); + /* Flush the Channel data */ + _cmux_flush_channel_data(cmux_obj); - /* 5.3.4 Disconnect (DISC) command: CMUX_COMMAND_DISC command sent at DLCI 0 - * have the same meaning as the Multiplexer Close Down command - */ - if (0 == channel_id) { - g_mux_obj_ptr->state = MUX_CLOSED; + /* + * 5.3.4 Disconnect (DISC) command: CMUX_COMMAND_DISC + * command sent at DLCI 0 have the same meaning as the + * Multiplexer Close Down command. + */ + if (channel_id == CMUX_CHANNEL_0) { + cmux_obj->cmux_state = CMUX_CLOSED; - /* Close CMUX */ - tcore_cmux_close(); + /* Close CMUX */ + tcore_cmux_close(cmux_obj->phy_hal); + } + } + break; + case CMUX_COMMAND_SABM: + dbg("Received SABM Frame"); + if (channel->poll_final_bit == 0) { + /* + * In the case where a CMUX_COMMAND_SABM or CMUX_COMMAND_DISC + * command with the P bit set to 0 is received then the received frame + * shall be discarded. + */ + + /* Flush the Channel data */ + _cmux_flush_channel_data(cmux_obj); + } else { + /* Encoding frame */ + send_data = _cmux_encode_cmux_frame(cmux_obj, NULL, + 0, channel_id, CMUX_COMMAND_UA, + 0x01, 0x01, 0x01, &len); + if (len != 0) + /* Send CMUX data */ + ret = _cmux_send_data(cmux_obj->phy_hal, len, send_data); + else + err("Failed to encode"); + + if (channel->channel_state != CMUX_CHANNEL_ESTABLISHED) + /* Channel State set to Established */ + channel->channel_state = CMUX_CHANNEL_ESTABLISHED; } - } break; } - case CMUX_COMMAND_SABM: - { - dbg("Received SABM Frame"); - if (0 == channel_info_ptr->poll_final_bit) { - /* In the case where a CMUX_COMMAND_SABM or CMUX_COMMAND_DISC command with - * the P bit set to 0 is received then the received frame shall be discarded. - */ + dbg("Exit"); +} - /* Flush the Channel data */ - tcore_cmux_flush_channel_data(); - } else { - /* Encoding frame */ - send_data = tcore_encode_cmux_frame(NULL, 0, channel_id, CMUX_COMMAND_UA, 1, 1, 1, &len); - if (0 != len) { - /* Send CMUX data */ - ret = tcore_cmux_send_data(len, send_data); - } else { - err("Failed to encode"); - } +static void _cmux_flush_channel_data(tcore_cmux_object *cmux_obj) +{ + dbg("Entry"); - if (channel_info_ptr->state != MUX_CHANNEL_ESTABLISHED) { - /* Channel State set to Established */ - channel_info_ptr->state = MUX_CHANNEL_ESTABLISHED; - } - } - break; - } - } + if (cmux_obj == NULL) + return; + + cmux_obj->internal_mux.info_field_len = 0x0; + memset(cmux_obj->internal_mux.info_field, 0x0, cmux_obj->max_cmux_buf_size); dbg("Exit"); - return; } -static void tcore_cmux_process_rcv_frame(unsigned char *data, int len) +static void _cmux_process_rcv_frame(tcore_cmux_object *cmux_obj, int length) { - unsigned char *frame_process_ptr = data; - unsigned char *buf_start_ptr = data; + unsigned char *frame_process_ptr = cmux_obj->cmux_buffer; + unsigned char *buf_start_ptr = cmux_obj->cmux_buffer; - CHANNEL *ch = NULL; + tcore_cmux_channel *ch; unsigned char channel_id; int header_length; - dbg("Entry"); - tcore_cmux_flush_channel_data(); + /* Flush channel data */ + _cmux_flush_channel_data(cmux_obj); - /* Get the Channel ID : 1st byte will be flag (F9)..Flag checking is already done.*/ + /* Get the Channel ID: 1st byte will be flag (F9). Flag checking is already done */ channel_id = (*++frame_process_ptr >> 2) & 0x3F; - if (channel_id < MAX_CMUX_CHANNELS_SUPPORTED) { // max channel is 8 - ch = g_mux_obj_ptr->channel_info[channel_id]; + if (channel_id < cmux_obj->max_cmux_channels) { + ch = cmux_obj->internal_mux.channel_info[channel_id]; ch->channel_id = channel_id; - // get the EA bit + /* get the EA bit */ ch->ext_bit = *frame_process_ptr & 0x01; - // get the CR bit + /* get the CR bit */ ch->cr_bit = (*frame_process_ptr++ >> 1) & 0x01; - // get the Frame Type + /* get the Frame Type */ ch->frame_type = *frame_process_ptr++; - // get the poll/Final bit + /* get the poll/Final bit */ ch->poll_final_bit = (ch->frame_type & 0x10) >> 4; - // get the length . TBD - dbg("*frame_process_ptr: %02x", *frame_process_ptr); - dbg("*(frame_process_ptr+1): %02x", *(frame_process_ptr+1)); - if (*frame_process_ptr & 0x01) { // if, len < 127 - dbg("Length < 127"); - g_mux_obj_ptr->info_field_len = *frame_process_ptr++ >> 1; + /* get the length . TBD */ + if (*frame_process_ptr & 0x01) { /* if, len < 127 */ + cmux_obj->internal_mux.info_field_len = *frame_process_ptr++ >> 1; header_length = 3; } else { - dbg("Length > 127"); - g_mux_obj_ptr->info_field_len = *(frame_process_ptr + 1) << 7; - g_mux_obj_ptr->info_field_len = g_mux_obj_ptr->info_field_len | ((*frame_process_ptr++ & 0xFE) >> 1); + cmux_obj->internal_mux.info_field_len = *(frame_process_ptr + 1) << 7; + cmux_obj->internal_mux.info_field_len = + (cmux_obj->internal_mux.info_field_len + | ((*frame_process_ptr++ & 0xFE) >> 1)); header_length = 4; frame_process_ptr++; } - dbg("info_field_len: %d", g_mux_obj_ptr->info_field_len); + dbg("info_field_len: %d", cmux_obj->internal_mux.info_field_len); /* Copy received information field */ - memcpy(g_mux_obj_ptr->info_field, frame_process_ptr, g_mux_obj_ptr->info_field_len); + memcpy(cmux_obj->internal_mux.info_field, frame_process_ptr, + cmux_obj->internal_mux.info_field_len); - frame_process_ptr = frame_process_ptr + g_mux_obj_ptr->info_field_len; + frame_process_ptr = frame_process_ptr + cmux_obj->internal_mux.info_field_len; - // CRC check of the header - if (rcv_crc_check(buf_start_ptr + 1, header_length, *frame_process_ptr)) { - dbg("Calling tcore_cmux_process_channel_data"); - tcore_cmux_process_channel_data(ch); - } else { + /* CRC check of the header */ + if (_cmux_check_recv_crc((buf_start_ptr + 1), header_length, *frame_process_ptr)) { + dbg("Calling _cmux_process_channel_data"); + _cmux_process_channel_data(cmux_obj, ch); + } else err("CRC check of the header FAILED.. Drop the packet !!"); - } - } else { + } else err("Incorrect channel... Drop the packet !!"); - } dbg("Exit"); - return; } -int tcore_cmux_rcv_from_hal(unsigned char *data, size_t length) +static TReturn _cmux_send_data(TcoreHal *hal, int data_len, unsigned char *data) { - #define TCORE_MUX_DECODE_FLAG_HUNT 0 - #define TCORE_MUX_DECODE_ADDR_HUNT 1 - #define TCORE_MUX_DECODE_CONTROL_HUNT 2 - #define TCORE_MUX_DECODE_LENGTH1_HUNT 3 - #define TCORE_MUX_DECODE_LENGTH2_HUNT 4 - #define TCORE_MUX_DECODE_DATA_HUNT 5 - #define TCORE_MUX_DECODE_FCS_HUNT 6 - - static int decode_state = TCORE_MUX_DECODE_FLAG_HUNT; - static unsigned char dec_fcs = 0xff; - static unsigned char mux_buffer[4096]; - static unsigned char* dec_data = mux_buffer; - static unsigned short dec_length = 0; - static size_t full_frame_len = 0; + TReturn ret; + dbg("Entry"); - size_t pos = -1; - int cp_len = 0; + /* Directly send to Physical HAL */ + ret = tcore_hal_send_data(hal, data_len, (void *) data); + if (ret != TCORE_RETURN_SUCCESS) { + err("Failed to send CMUX data"); + } else + dbg("Successfully sent CMUX data"); -DECODE_STATE_CHANGE: - if (++pos >= length) - { - return 1; + dbg("Exit"); + return ret; +} + +static gboolean _cmux_recv_cmux_data(tcore_cmux_object *cmux_obj, + tcore_cmux_channel *channel) +{ + TcoreHal *hal; + dbg("Entry"); + + /* Dereferencing HAL from Channel Pointer */ + hal = channel->hal; + if (hal == NULL) { + err("No HAL"); + return FALSE; } - switch(decode_state) - { - case TCORE_MUX_DECODE_FLAG_HUNT: full_frame_len = 0; dec_length = 0; dec_fcs = 0xff; dec_data = mux_buffer; goto FLAG_HUNT; break; - case TCORE_MUX_DECODE_ADDR_HUNT: goto ADDR_HUNT; break; - case TCORE_MUX_DECODE_CONTROL_HUNT: goto CONTROL_HUNT; break; - case TCORE_MUX_DECODE_LENGTH1_HUNT: goto LENGTH1_HUNT; break; - case TCORE_MUX_DECODE_LENGTH2_HUNT: goto LENGTH2_HUNT; break; - case TCORE_MUX_DECODE_DATA_HUNT: goto DATA_HUNT; break; - case TCORE_MUX_DECODE_FCS_HUNT: goto FCS_HUNT; break; + dbg("Dispatching to logical HAL - hal: %x", (unsigned int)hal); + if (tcore_hal_dispatch_response_data(hal, 0, + cmux_obj->internal_mux.info_field_len, + cmux_obj->internal_mux.info_field) + != TCORE_RETURN_SUCCESS) { + err("Exit"); + return FALSE; } -FLAG_HUNT: - while (data[pos] != 0xF9) { - if (++pos >= length) { - return 1; + dbg("Exit"); + return TRUE; +} + +static TReturn _cmux_hal_power(TcoreHal *hal, gboolean flag) +{ + dbg("Entry"); + + if (flag == TRUE) { /* Powering ON */ + dbg("Powering ON"); + return tcore_hal_set_power_state(hal, TRUE); + } else { /* Powering OFF */ + dbg("Powering ON"); + return tcore_hal_set_power_state(hal, FALSE); + } +} + +static TReturn _cmux_hal_send(TcoreHal *hal, unsigned int data_len, void *data) +{ + tcore_cmux_object *cmux_obj; + char *hal_name; + unsigned char *send_data; + char *channel_name; + int channel_id; + int len; + + TReturn ret = TCORE_RETURN_FAILURE; + dbg("Entry"); + + /* Check if Logical HAL is Powered ON */ + if (tcore_hal_get_power_state(hal) == FALSE) { + err("HAL is not Powered UP"); + return TCORE_RETURN_FAILURE; + } + + channel_name = tcore_hal_get_name(hal); + dbg("HAL name: %s", channel_name); + + /* + * Get CMUX Object from Modem Interface Plug-in + */ + cmux_obj = _cmux_get_cmux_object(tcore_hal_ref_plugin(hal)); + if (cmux_obj == NULL) { + /* Free memory */ + g_free(channel_name); + + return TCORE_RETURN_FAILURE; + } + + channel_id = cmux_obj->max_cmux_channels + 1; + + if (channel_name != NULL) { + int i = 0; + + while (cmux_obj->max_cmux_channels > i) { + hal_name = + tcore_hal_get_name(cmux_obj->internal_mux.channel_info[i]->hal); + + /* + * Comparing all Logical HAL names with required HAL name. + */ + if (strcmp(hal_name, channel_name) == 0) { + channel_id = cmux_obj->internal_mux.channel_info[i]->channel_id; + dbg("Found Channel ID: %d", channel_id); + + /* Free HAL name */ + g_free(hal_name); + + break; + } + + /* Free HAL name */ + g_free(hal_name); + + /* Increment to next Logical HAL */ + i++; } + + /* Free memory */ + g_free(channel_name); + } else { + err("No name defined for HAL"); + return ret; } - decode_state = TCORE_MUX_DECODE_ADDR_HUNT; - goto DECODE_STATE_CHANGE; -ADDR_HUNT: - while (data[pos] == 0xF9) { - if (++pos >= length) { - return 1; + if (channel_id > cmux_obj->max_cmux_channels) { + err("Failed to find Channel ID"); + return ret; + } + + /* Muxing operation and Frame creation */ + /* Encoding frame */ + send_data = _cmux_encode_cmux_frame(cmux_obj, data, data_len, channel_id, + CMUX_COMMAND_UIH, 0x1, 0x1, 0x0, &len); + if (len == 0) { + err("Failed to encode"); + return TCORE_RETURN_FAILURE; + } + + /* Send CMUX data */ + ret = _cmux_send_data(cmux_obj->phy_hal, len, send_data); + + dbg("Exit"); + return ret; +} + +static TReturn _cmux_hal_setup_netif(CoreObject *co, + TcoreHalSetupNetifCallback func, void *user_data, + unsigned int cid, gboolean enable) +{ + tcore_cmux_object *cmux_obj; + TcoreHal *hal; + dbg("Entry"); + + /* Get secondary HAL from Core Object */ + hal = tcore_object_get_hal(co); + + /* + * Get CMUX Object from Modem Interface Plug-in + */ + cmux_obj = _cmux_get_cmux_object(tcore_hal_ref_plugin(hal)); + if (cmux_obj == NULL) + return TCORE_RETURN_FAILURE; + + return tcore_hal_setup_netif(cmux_obj->phy_hal, + co, func, user_data, cid, enable); +} + +/* CMUX supported HAL (Logical HAL) operations */ +static struct tcore_hal_operations cmux_hops = { + .power = _cmux_hal_power, + .send = _cmux_hal_send, + .setup_netif = _cmux_hal_setup_netif, +}; + +static TcoreHal *_cmux_create_logical_hal(tcore_cmux_object *cmux_obj, + tcore_cmux_channel *channel) +{ + TcoreHal *hal; + char channel_id_name[CMUX_MAX_CHANNEL_NAME]; + dbg("Entry"); + + if ((cmux_obj == NULL) || (channel == NULL)) { + err("Invalid input parameters"); + return NULL; + } + + /* Creating Logical HAL for Core Object - Mode - 'AT mode' */ + snprintf(channel_id_name, sizeof(channel_id_name), + "channel_%d", channel->channel_id); + + /* Creating Logical HAL */ + hal = tcore_hal_new(cmux_obj->plugin, + channel_id_name, &cmux_hops, TCORE_HAL_MODE_AT); + dbg("hal: %p", hal); + if (hal == NULL) { + err("Failed to allocate memory"); + return NULL; + } + + /* Updating Logical HAL of CMUX Channel */ + channel->hal = hal; + + dbg("Exit"); + return hal; +} + +tcore_cmux_object *_cmux_new(int max_channels, unsigned int buffer_size) +{ + tcore_cmux_object *cmux_obj; + int i; + dbg("Entry"); + + /* Allocating memory for mux */ + cmux_obj = (tcore_cmux_object *)g_try_new0(tcore_cmux_object, 1); + if (cmux_obj == NULL) { + err("Failed to allocate memory"); + return NULL; + } + + /* Allocating memory for info_field */ + cmux_obj->internal_mux.info_field = + (unsigned char *)g_try_malloc0(buffer_size); + if (cmux_obj->internal_mux.info_field == NULL) { + err("Failed to allocate memory for info field"); + goto ERROR; + } + + /* CMUX State initialize to CMUX_NOT_INITIALIZED */ + cmux_obj->cmux_state = CMUX_NOT_INITIALIZED; + + /* + * Allocating memory for channel_info + * max_channels defines the maximum channels user requested, + * hence + 1 is required for CMUX Control Channel + */ + for (i = 0; i < (max_channels + 1) ; i++) { + /* Allocating memory for channel_info */ + cmux_obj->internal_mux.channel_info[i] = + (tcore_cmux_channel *)g_try_new0(tcore_cmux_channel, 1); + if (cmux_obj->internal_mux.channel_info[i] == NULL) { + err("Failed to allocate memory for channel_info of channel: [%d]", i); + goto ERROR; } } + dbg("Exit"); + return cmux_obj; + +ERROR: + /* Free allocated memory */ + if (cmux_obj != NULL) { + /* Free info_field */ + g_free(cmux_obj->internal_mux.info_field); + + for (i = 0; i < (max_channels + 1) ; i++) + /* Free channel_info */ + g_free(cmux_obj->internal_mux.channel_info[i]); + + /* Free CMUX object memory */ + g_free(cmux_obj); + } + + err("Exit"); + return NULL; +} + +static void _cmux_channel_init(tcore_cmux_object *cmux_obj, int channel_id) +{ + tcore_cmux_channel *ch; + dbg("Entry"); + + ch = cmux_obj->internal_mux.channel_info[channel_id]; + if (ch == NULL) + return; + + ch->channel_id = channel_id; + ch->channel_state = CMUX_CHANNEL_SABM_SEND_WAITING_FOR_UA; + + ch->hal = NULL; + + /* TODO - Check if required */ + ch->frame_type = CMUX_COMMAND_SABM; + ch->ext_bit = 0x01; + ch->cr_bit = 0x01; + ch->poll_final_bit = 0x01; + + dbg("Channel ID [%d] - Initialized", channel_id); +} + +static void _cmux_close_channel(tcore_cmux_object *cmux_obj, int channel_id) +{ + tcore_cmux_channel *ch; + unsigned char *send_data; + int ret, len = 0; + dbg("Entry"); + + ch = cmux_obj->internal_mux.channel_info[channel_id]; + if (ch == NULL) + return; + + if (ch->channel_state != CMUX_CHANNEL_CLOSED) { + ch->frame_type = CMUX_COMMAND_DISC; + ch->ext_bit = 0x01; + ch->cr_bit = 0x01; + ch->channel_state = CMUX_CHANNEL_DISC_SEND_WAITING_FOR_UA; + + /* Send DSC command */ + /* Encoding frame */ + send_data = _cmux_encode_cmux_frame(cmux_obj, NULL, 0, channel_id, + CMUX_COMMAND_DISC, 0x01, 0x01, 0x01, &len); + if (len != 0) + /* Send CMUX data */ + ret = _cmux_send_data(cmux_obj->phy_hal, len, send_data); + else + err("Failed to encode"); + } else + /* Channel is already closed */ + err("Channel is already closed"); + + dbg("Exit"); +} + +static void _cmux_free(tcore_cmux_object *cmux_obj) +{ + int channel; + dbg("Entry"); + + /* + * This function is used internally only, hence sanity check for 'cmux_obj' + * is NOT required. + */ + /* Free Information Field */ + g_free(cmux_obj->internal_mux.info_field); + cmux_obj->internal_mux.info_field = NULL; + + for (channel = 0; channel < cmux_obj->max_cmux_channels; channel++) { + /* Free Channel Information */ + g_free(cmux_obj->internal_mux.channel_info[channel]); + cmux_obj->internal_mux.channel_info[channel] = NULL; + } + + /* Free CMUX Object */ + g_free(cmux_obj); + cmux_obj = NULL; + + dbg("Exit"); +} + +static void _cmux_on_confirmation_message_send(TcorePending *plugin, + gboolean result, void *user_data) +{ + dbg("Message out from queue"); + + if (result == FALSE) { /* Fail */ + err("SEND FAIL"); + } else + dbg("SEND OK"); +} + +void tcore_cmux_rcv_from_hal(TcoreHal *hal, unsigned char *data, size_t length) +{ +#define TCORE_CMUX_DECODE_FLAG_HUNT 0 +#define TCORE_CMUX_DECODE_ADDR_HUNT 1 +#define TCORE_CMUX_DECODE_CONTROL_HUNT 2 +#define TCORE_CMUX_DECODE_LENGTH1_HUNT 3 +#define TCORE_CMUX_DECODE_LENGTH2_HUNT 4 +#define TCORE_CMUX_DECODE_DATA_HUNT 5 +#define TCORE_CMUX_DECODE_FCS_HUNT 6 + + tcore_cmux_object *cmux_obj; + + static int decode_state = TCORE_CMUX_DECODE_FLAG_HUNT; + static unsigned char dec_fcs; + static unsigned char *dec_data; + static unsigned short dec_length; + static size_t full_frame_len; + + size_t pos = -1; + int cp_len; + dbg("Entry"); + + /* + * Get CMUX Object from Modem Interface Plug-in + */ + cmux_obj = _cmux_get_cmux_object(tcore_hal_ref_plugin(hal)); + if (cmux_obj == NULL) + return; + +DECODE_STATE_CHANGE: + if (++pos >= length) + return; + + switch(decode_state) { + case TCORE_CMUX_DECODE_FLAG_HUNT: + full_frame_len = 0; + dec_length = 0; + dec_fcs = 0xFF; + dec_data = cmux_obj->cmux_buffer; + goto FLAG_HUNT; + break; + case TCORE_CMUX_DECODE_ADDR_HUNT: + goto ADDR_HUNT; + break; + case TCORE_CMUX_DECODE_CONTROL_HUNT: + goto CONTROL_HUNT; + break; + case TCORE_CMUX_DECODE_LENGTH1_HUNT: + goto LENGTH1_HUNT; + break; + case TCORE_CMUX_DECODE_LENGTH2_HUNT: + goto LENGTH2_HUNT; + break; + case TCORE_CMUX_DECODE_DATA_HUNT: + goto DATA_HUNT; + break; + case TCORE_CMUX_DECODE_FCS_HUNT: + goto FCS_HUNT; + break; + } + +FLAG_HUNT: + while (data[pos] != CMUX_FRAME_DELIMITER) + if (++pos >= length) + return; + + decode_state = TCORE_CMUX_DECODE_ADDR_HUNT; + goto DECODE_STATE_CHANGE; + +ADDR_HUNT: + while (data[pos] == CMUX_FRAME_DELIMITER) + if (++pos >= length) + return; + dec_fcs = crc_table[dec_fcs^data[pos]]; - decode_state = TCORE_MUX_DECODE_CONTROL_HUNT; - *dec_data++ = 0xF9; + decode_state = TCORE_CMUX_DECODE_CONTROL_HUNT; + *dec_data++ = CMUX_FRAME_DELIMITER; *dec_data++ = data[pos]; full_frame_len += 2; goto DECODE_STATE_CHANGE; CONTROL_HUNT: dec_fcs = crc_table[dec_fcs^data[pos]]; - decode_state = TCORE_MUX_DECODE_LENGTH1_HUNT; + decode_state = TCORE_CMUX_DECODE_LENGTH1_HUNT; *dec_data++ = data[pos]; full_frame_len++; goto DECODE_STATE_CHANGE; @@ -968,21 +1180,13 @@ CONTROL_HUNT: LENGTH1_HUNT: dec_length = data[pos] >> 1; dec_fcs = crc_table[dec_fcs^data[pos]]; - if (data[pos] & 0x1) - { // ea + if (data[pos] & 0x1) /* EA */ if (dec_length > 0) - { - decode_state = TCORE_MUX_DECODE_DATA_HUNT; - } + decode_state = TCORE_CMUX_DECODE_DATA_HUNT; else - { - decode_state = TCORE_MUX_DECODE_FCS_HUNT; - } - } + decode_state = TCORE_CMUX_DECODE_FCS_HUNT; else - { - decode_state = TCORE_MUX_DECODE_LENGTH2_HUNT; - } + decode_state = TCORE_CMUX_DECODE_LENGTH2_HUNT; *dec_data++ = data[pos]; full_frame_len++; @@ -991,21 +1195,18 @@ LENGTH1_HUNT: LENGTH2_HUNT: dec_length |= ((unsigned short)data[pos] << 7); dec_fcs = crc_table[dec_fcs^data[pos]]; - decode_state = TCORE_MUX_DECODE_DATA_HUNT; + decode_state = TCORE_CMUX_DECODE_DATA_HUNT; *dec_data++ = data[pos]; full_frame_len++; goto DECODE_STATE_CHANGE; DATA_HUNT: - if (dec_length < (length - pos)) // frame data fully available in the buffer - { + if (dec_length < (length - pos)) { /* frame data fully available in the buffer */ cp_len = dec_length; - decode_state = TCORE_MUX_DECODE_FCS_HUNT; - } - else // frame data partially available in the buffer - { + decode_state = TCORE_CMUX_DECODE_FCS_HUNT; + } else { /* frame data partially available in the buffer */ cp_len = (length - pos); - decode_state = TCORE_MUX_DECODE_DATA_HUNT; + decode_state = TCORE_CMUX_DECODE_DATA_HUNT; } memcpy(dec_data, data + pos, cp_len); @@ -1017,169 +1218,190 @@ DATA_HUNT: goto DECODE_STATE_CHANGE; FCS_HUNT: - //if (crc_table[dec_fcs^data[pos]] == 0xCF) // valid FCS, store frame. - { - *dec_data++ = data[pos]; - *dec_data++ = 0xF9; - full_frame_len += 2; - tcore_cmux_process_rcv_frame(mux_buffer, full_frame_len); - } + *dec_data++ = data[pos]; + *dec_data++ = CMUX_FRAME_DELIMITER; + full_frame_len += 2; + _cmux_process_rcv_frame(cmux_obj, full_frame_len); - // enter flag hunt mode - decode_state = TCORE_MUX_DECODE_FLAG_HUNT; + /* enter flag hunt mode */ + decode_state = TCORE_CMUX_DECODE_FLAG_HUNT; goto DECODE_STATE_CHANGE; } -static void tcore_cmux_channel_init(CMUX_Channels channel_id) +/* CMUX initialization */ +TReturn tcore_cmux_init(TcoreHal *phy_hal, unsigned int frame_size, + TcorePendingResponseCallback resp_cb, void *resp_cb_data) { - CHANNEL *ch = NULL; + TcorePending *pending = NULL; + TcoreATRequest *req = NULL; + TReturn ret = TCORE_RETURN_FAILURE; + char *cmd_str; + dbg("Entry"); - ch = g_mux_obj_ptr->channel_info[channel_id]; - memset(ch, 0x0, sizeof(CHANNEL)); + if ((phy_hal == NULL) || (resp_cb == NULL)) + return TCORE_RETURN_EINVAL; - ch->channel_id = channel_id; - ch->state = MUX_CHANNEL_SABM_SEND_WAITING_FOR_UA; + if (frame_size > 32768) + return TCORE_RETURN_EINVAL; - ch->co = NULL; - ch->hal = NULL; + /* + * 3GPP 27.010 Section 5.7.2 Maximum Frame Size (N1) + * If frame size is greater than Zero then, + * the request is sent for frame size + * else, + * request is sent for 'default' frame size + * (default Value: 31 (64 if Advanced option is used)). + */ + if (frame_size > 0) + cmd_str = g_strdup_printf("AT+CMUX=0,0,%d,1509,10,3,30,,", frame_size); + else + cmd_str = g_strdup_printf("AT+CMUX=0,0,,1509,10,3,30,,"); - /* TODO - Check if required */ - ch->frame_type = CMUX_COMMAND_SABM; - ch->ext_bit = 0x01; - ch->cr_bit = 0x01; - ch->poll_final_bit = 0x01; + if (cmd_str == NULL) + return TCORE_RETURN_ENOMEM; - dbg("Channel ID %d initialized", channel_id); + /* Create Pending Request */ + pending = tcore_pending_new(NULL, 0); + if (pending == NULL) { + dbg("Pending is NULL"); - return; -} + g_free(cmd_str); + return ret; + } -static void tcore_cmux_close_channel(int channel_id) -{ - CHANNEL *ch = NULL; - unsigned char *send_data = NULL; - int ret, len = 0; + /* Create AT-Command Request */ + req = tcore_at_request_new(cmd_str, "+CMUX:", TCORE_AT_NO_RESULT); - dbg("Entry"); + /* Free command string */ + g_free(cmd_str); - ch = g_mux_obj_ptr->channel_info[channel_id]; + if (req == NULL) { + dbg("Request is NULL"); + tcore_pending_free(pending); + return ret; + } + dbg("AT Command: %s, Prefix(if any):%s, AT-Command length: %d", req->cmd, req->prefix, strlen(req->cmd)); - if (ch->state != MUX_CHANNEL_CLOSED) { - ch->frame_type = CMUX_COMMAND_DISC; - ch->ext_bit = 0x01; - ch->cr_bit = 0x01; - ch->state = MUX_CHANNEL_DISC_SEND_WAITING_FOR_UA; + tcore_pending_set_request_data(pending, 0, req); + tcore_pending_set_response_callback(pending, resp_cb, resp_cb_data); + tcore_pending_set_send_callback(pending, _cmux_on_confirmation_message_send, NULL); - /* Send DSC command */ - /* Encoding frame */ - send_data = tcore_encode_cmux_frame(NULL, 0, channel_id, CMUX_COMMAND_DISC, 0x01, 0x01, 0x01, &len); - if (0 != len) { - /* Send CMUX data */ - ret = tcore_cmux_send_data(len, send_data); - } else { - err("Failed to encode"); - } - } else { - /* Channel is already closed */ - err("Channel is already closed"); - } + ret = tcore_hal_send_request(phy_hal, pending); dbg("Exit"); - return; + return ret; } -static void tcore_cmux_free(void) +/* Setup Internal CMUX */ +TReturn tcore_cmux_setup_internal_mux(tcore_cmux_mode mode, + int max_channels, unsigned int cmux_buf_size, TcoreHal *phy_hal, + cmux_setup_cb_func channel_setup_cb, gpointer channel_setup_user_data, + cmux_setup_complete_cb_func setup_complete_cb, gpointer setup_complete_user_data) { - int channel; + tcore_cmux_object *cmux_obj; + unsigned char *data; + int data_len; + int index; + TReturn ret = TCORE_RETURN_FAILURE; dbg("Entry"); - - if (g_mux_obj_ptr) { - /* Free Information Field */ - if (g_mux_obj_ptr->info_field) { - free(g_mux_obj_ptr->info_field); - g_mux_obj_ptr->info_field = NULL; - } - - for (channel = 0; channel < MAX_CMUX_CHANNELS_SUPPORTED; channel++) { - /* Free Channel Information */ - if (g_mux_obj_ptr->channel_info[channel]) { - free(g_mux_obj_ptr->channel_info[channel]); - g_mux_obj_ptr->channel_info[channel] = NULL; - } - } - - /* Free MUX Object */ - free(g_mux_obj_ptr); - g_mux_obj_ptr = NULL; - } else { - err("MUX Object doesn't exist"); + dbg("Internal CMUX setup request"); + + /* Sanity Check */ + if ((cmux_buf_size <= 0) + || (phy_hal == NULL) + || (channel_setup_cb == NULL) + || (setup_complete_cb == NULL)) { + err("CMUX Buffer size: [%d] Physical HAL: [0x%x] setup_complete_cb: [0x%x]", + cmux_buf_size, (unsigned int)phy_hal, setup_complete_cb); + return TCORE_RETURN_EINVAL; } - dbg("Exit"); - return; -} - -TReturn tcore_cmux_init(TcorePlugin *plugin, TcoreHal *hal) -{ - unsigned char *data = NULL; - int data_len = 0; + dbg("Physical HAL: [0x%x] cmux_buf_size: [%d]", + (unsigned int)phy_hal, cmux_buf_size); - int index; + /* + * Max Channels + * (+ 1) is for CMUX Control Channel + */ + if ((max_channels +1) >= CMUX_CHANNEL_MAX) { + err("Number of Channels requested is greater than supported"); + return TCORE_RETURN_EINVAL; + } - TReturn ret = TCORE_RETURN_SUCCESS; + /* Create new CMUX Object */ + cmux_obj = _cmux_new(max_channels, cmux_buf_size); + if (cmux_obj == NULL) { + err("Failed to create CMUX object"); + return TCORE_RETURN_ENOMEM; + } - dbg("Entry"); + /* Maximum Buffer size for CMUX frame processing */ + cmux_obj->max_cmux_buf_size = cmux_buf_size; - dbg("Physical HAL: %x", (unsigned int)hal); + /* Maximum Channels requested */ + cmux_obj->max_cmux_channels = max_channels + 1; - /* Creat new CMUX Object */ - g_mux_obj_ptr = tcore_cmux_new(); - if (NULL == g_mux_obj_ptr) { - err("Failed to create MUX object"); + /* Allocating buffer for CMUX frames proposing */ + cmux_obj->cmux_buffer = (unsigned char *)g_try_malloc0(cmux_buf_size); + if (cmux_obj->cmux_buffer == NULL) { + err("Failed to allocate memory"); - ret = TCORE_RETURN_FAILURE; + ret = TCORE_RETURN_ENOMEM; goto ERROR; } - /* Save Plugin */ - g_mux_obj_ptr->plugin = plugin; + /* Update 'mode' */ + cmux_obj->cmux_mode = mode; + dbg("Mode: \'%s\'", (mode == CMUX_MODE_BASIC ? "Basic" : "Advanced")); /* Save Physical HAL */ - g_mux_obj_ptr->phy_hal = hal; + cmux_obj->phy_hal = phy_hal; + + /* Save Modem Interface Plug-in */ + cmux_obj->plugin = tcore_hal_ref_plugin(phy_hal); + + /* CMUX setup callback function */ + cmux_obj->internal_mux.channel_setup_cb = channel_setup_cb; + cmux_obj->internal_mux.channel_setup_user_data = channel_setup_user_data; - /* Setting Receive callback function for data received from Physical HAL */ - g_mux_obj_ptr->cb_func = tcore_cmux_recv_mux_data; + /* CMUX setup complete callback function */ + cmux_obj->internal_mux.setup_complete_cb = setup_complete_cb; + cmux_obj->internal_mux.setup_complete_user_data = setup_complete_user_data; - /* After MUX setup, AT parse functionality of PHY HAL should be disabled, - * here we change the mode of PHYSICAL HAL to Transparent. - */ - tcore_hal_set_mode(g_mux_obj_ptr->phy_hal, TCORE_HAL_MODE_TRANSPARENT); + /* + * After CMUX setup, AT parse functionality of PHY HAL should be disabled, + * here we change the mode of PHYSICAL HAL to Transparent from AT. + */ + tcore_hal_set_mode(phy_hal, TCORE_HAL_MODE_TRANSPARENT); dbg("Physical HAL mode changed to Transparent"); - /* Initialize all the Channels */ + /* Adding CMUX object to Global List */ + g_cmux_obj = g_slist_insert(g_cmux_obj, cmux_obj, 0); + + /* Initialize all the Channels for the CMUX object */ /* Open all Channels */ - for (index = 0; index < MAX_CMUX_CHANNELS_SUPPORTED; index++) { - dbg("Initialize the Channel %d", index); - tcore_cmux_channel_init((CMUX_Channels) index); + for (index = 0; index < cmux_obj->max_cmux_channels; index++) { + dbg("Initializing CMUX Channel [%d]", index); + _cmux_channel_init(cmux_obj, index); - dbg("Opening Channel %d", index); + dbg("Opening Channel ID [%d]", index); /* Encode CMUX Frame */ - data = tcore_encode_cmux_frame(NULL, 0, index, CMUX_COMMAND_SABM, 0x01, 0x01, 0x01, &data_len); - if (0 == data_len) { + data = _cmux_encode_cmux_frame(cmux_obj, NULL, 0, index, + CMUX_COMMAND_SABM, 0x01, 0x01, 0x01, &data_len); + if (data_len == 0) { err("Failed to encode"); - - ret = TCORE_RETURN_FAILURE; goto ERROR; } dbg("data_len: %d data: %s", data_len, data); /* Send CMUX data */ - tcore_cmux_send_data(data_len, data); - dbg("CMUX Control Request sent to CP"); - - /* Set Core object and HAL */ - tcore_cmux_link_core_object_hal((CMUX_Channels) index, plugin); + ret = _cmux_send_data(cmux_obj->phy_hal, data_len, data); + if (ret != TCORE_RETURN_SUCCESS) { + err("Failed to send CMUX Control Request for Channel ID: [%d]", index); + goto ERROR; + } else + dbg("CMUX Control Request sent to CP"); } dbg("Exit"); @@ -1187,77 +1409,55 @@ TReturn tcore_cmux_init(TcorePlugin *plugin, TcoreHal *hal) ERROR: /* Free the allocated CMUX memory */ - tcore_cmux_free(); + _cmux_free(cmux_obj); err("Exit"); return ret; } -void tcore_cmux_close(void) +/* Close CMUX */ +void tcore_cmux_close(TcoreHal *phy_hal) { - int channel = 0; - int index = 0; - CoreObject *co = NULL; - GSList *co_list = NULL; - + tcore_cmux_object *cmux_obj; + int channel_id; dbg("Entry"); - for (channel = 0; channel < MAX_CMUX_CHANNELS_SUPPORTED; channel++) { - dbg("Channel ID: %d", channel); - index = 0; + /* + * Get CMUX Object from Modem Interface Plug-in + */ + cmux_obj = _cmux_get_cmux_object(tcore_hal_ref_plugin(phy_hal)); + if (cmux_obj == NULL) + return; - /* Close Channel - Send DSC command */ - tcore_cmux_close_channel(channel); - - /* Revert Physical HAL as HAL of each Core Object associated to this Channel */ - while (NULL != cmux_channel_core_object[channel].core_object_name[index]) { - co = NULL; - - /* Core Objects list */ - co_list = g_mux_obj_ptr->channel_info[channel]->co; - dbg("Core Objects list : %p", co_list); - - /* Core Object list may contain multiple Core Objects. - * Revert to Physical HAL for each of the Core Objects associated - * with this Channel - */ - while (NULL != co_list) { - if (NULL != co_list->data) { - if (!strcmp((const char *) cmux_channel_core_object[channel].core_object_name[index], (const char *) tcore_object_ref_name((CoreObject *) co_list->data))) { - co = (CoreObject *) co_list->data; - dbg("Core Object found "); - break; - } - } + /* Internal CMUX */ + dbg("Closing Internal CMUX"); - /* To next Core Object in the list */ - co_list = co_list->next; - } + /* Close all Channels */ + for (channel_id = 0; + channel_id < cmux_obj->max_cmux_channels; + channel_id++) { + dbg("Closing Channel - ID: [%d]", channel_id); - /* Set the previous Physical HAL as HAL for Core Object */ - if (NULL != co) { - tcore_object_set_hal(co, g_mux_obj_ptr->phy_hal); - } else { - /* Proceed to next Channel */ - err("No more Core Objects present in this Channel"); - break; - } - - /* To next Core Object */ - index++; - } + /* Close Channel - Send DSC command */ + _cmux_close_channel(cmux_obj, channel_id); /* Free Logical HAL for Channel */ - tcore_hal_free(g_mux_obj_ptr->channel_info[channel]->hal); - g_mux_obj_ptr->channel_info[channel]->hal = NULL; + tcore_hal_free(cmux_obj->internal_mux.channel_info[channel_id]->hal); + cmux_obj->internal_mux.channel_info[channel_id]->hal = NULL; } - /* Change the mode of PHYSICAL HAL to Custom */ - tcore_hal_set_mode(g_mux_obj_ptr->phy_hal, TCORE_HAL_MODE_AT); + /* Freeing CMUX frame processing buffer */ + g_free(cmux_obj->cmux_buffer); + cmux_obj->cmux_buffer = NULL; + + /* Change the mode of PHYSICAL HAL from Transparent to AT */ + tcore_hal_set_mode(cmux_obj->phy_hal, TCORE_HAL_MODE_AT); + + /* Remove from list */ + g_cmux_obj = g_slist_remove(g_cmux_obj, cmux_obj); /* Free all the allocated memory */ - tcore_cmux_free(); + _cmux_free(cmux_obj); dbg("Exit"); - return; } diff --git a/src/plugin.c b/src/plugin.c index 8989ac6..3a60dd0 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -52,12 +52,15 @@ TcorePlugin *tcore_plugin_new(Server *server, { TcorePlugin *p; - p = calloc(1, sizeof(struct tcore_plugin_type)); - if (!p) + p = g_try_new0(struct tcore_plugin_type, 1); + if (p == NULL) return NULL; - if (filename) - p->filename = strdup(filename); + /* + * Assign 'filename' name irrespective of if it is NULL, + * g_strdup would take care of this scenario. + */ + p->filename = g_strdup(filename); p->desc = desc; p->property = g_hash_table_new(g_str_hash, g_str_equal); @@ -72,7 +75,7 @@ void tcore_plugin_free(TcorePlugin *plugin) GSList *list; CoreObject *o; - if (!plugin) + if (plugin == NULL) return; dbg(""); @@ -80,7 +83,7 @@ void tcore_plugin_free(TcorePlugin *plugin) if (plugin->list_co) { for (list = plugin->list_co; list; list = list->next) { o = list->data; - if (!o) + if (o == NULL) continue; tcore_object_free(o); @@ -92,7 +95,7 @@ void tcore_plugin_free(TcorePlugin *plugin) } if (plugin->filename) { - free(plugin->filename); + g_free(plugin->filename); plugin->filename = NULL; } @@ -108,12 +111,12 @@ void tcore_plugin_free(TcorePlugin *plugin) plugin->handle = NULL; } - free(plugin); + g_free(plugin); } const struct tcore_plugin_define_desc *tcore_plugin_get_description(TcorePlugin *plugin) { - if (!plugin) + if (plugin == NULL) return NULL; return plugin->desc; @@ -121,21 +124,24 @@ const struct tcore_plugin_define_desc *tcore_plugin_get_description(TcorePlugin char *tcore_plugin_get_filename(TcorePlugin *plugin) { - if (!plugin) + if (plugin == NULL) return NULL; - if (!plugin->filename) - return NULL; - - return strdup(plugin->filename); + /* + * Return copy of 'filename', + * + * it CAN even be NULL if plugin->filename is NULL, + * g_strdup will take care of this scenario. + */ + return g_strdup(plugin->filename); } char* tcore_plugin_ref_plugin_name(TcorePlugin *plugin) { - if (!plugin) + if (plugin == NULL) return NULL; - if (!plugin->desc->name) + if (plugin->desc == NULL) return NULL; return plugin->desc->name; @@ -143,7 +149,7 @@ char* tcore_plugin_ref_plugin_name(TcorePlugin *plugin) Server *tcore_plugin_ref_server(TcorePlugin *plugin) { - if (!plugin) + if (plugin == NULL) return NULL; return plugin->parent_server; @@ -151,7 +157,7 @@ Server *tcore_plugin_ref_server(TcorePlugin *plugin) TReturn tcore_plugin_link_user_data(TcorePlugin *plugin, void *user_data) { - if (!plugin) + if (plugin == NULL) return TCORE_RETURN_EINVAL; plugin->user_data = user_data; @@ -161,7 +167,7 @@ TReturn tcore_plugin_link_user_data(TcorePlugin *plugin, void *user_data) void *tcore_plugin_ref_user_data(TcorePlugin *plugin) { - if (!plugin) + if (plugin == NULL) return FALSE; return plugin->user_data; @@ -169,30 +175,30 @@ void *tcore_plugin_ref_user_data(TcorePlugin *plugin) TReturn tcore_plugin_add_core_object(TcorePlugin *plugin, CoreObject *co) { - if (!plugin || !co) + if ((plugin == NULL) || (co == NULL)) return TCORE_RETURN_EINVAL; - dbg("add core_object! (name=%s)", tcore_object_ref_name(co)); + dbg("add core_object! (Type: [0x%x])", tcore_object_get_type(co)); plugin->list_co = g_slist_insert(plugin->list_co, co, 0); return TCORE_RETURN_SUCCESS; } -CoreObject *tcore_plugin_ref_core_object(TcorePlugin *plugin, const char *name) +CoreObject *tcore_plugin_ref_core_object(TcorePlugin *plugin, unsigned int type) { GSList *list; CoreObject *co; - if (!plugin) + if (plugin == NULL) return NULL; for (list = plugin->list_co; list; list = list->next) { co = list->data; - if (!co) + if (co == NULL) continue; - if (strcmp(tcore_object_ref_name(co), name) == 0) { + if (tcore_object_get_type(co) == type) { return co; } } @@ -200,18 +206,17 @@ CoreObject *tcore_plugin_ref_core_object(TcorePlugin *plugin, const char *name) return NULL; } - GSList *tcore_plugin_get_core_objects_bytype(TcorePlugin *plugin, unsigned int type) { GSList *list, *rlist = NULL; CoreObject *co; - if (!plugin) + if (plugin == NULL) return NULL; for (list = plugin->list_co; list; list = list->next) { co = list->data; - if (!co) + if (co == NULL) continue; if (tcore_object_get_type(co) == type) { @@ -227,14 +232,14 @@ TReturn tcore_plugin_core_object_event_emit(TcorePlugin *plugin, const char *eve GSList *list; CoreObject *co; - if (!plugin) + if (plugin == NULL) return TCORE_RETURN_EINVAL; dbg("event(%s) emit", event); for (list = plugin->list_co; list; list = list->next) { co = list->data; - if (!co) + if (co == NULL) continue; tcore_object_emit_callback(co, event, event_info); @@ -247,19 +252,19 @@ TReturn tcore_plugin_link_property(TcorePlugin *plugin, const char *key, void *d { void *prev; - if (!plugin) + if (plugin == NULL) return TCORE_RETURN_EINVAL; - if (!plugin->property) + if (plugin->property == NULL) return TCORE_RETURN_EINVAL; prev = g_hash_table_lookup(plugin->property, key); if (prev != NULL) { - free(prev); + g_free(prev); g_hash_table_replace(plugin->property, (gpointer)key, data); } else { - g_hash_table_insert(plugin->property, strdup(key), data); + g_hash_table_insert(plugin->property, g_strdup(key), data); } return TCORE_RETURN_SUCCESS; @@ -267,10 +272,10 @@ TReturn tcore_plugin_link_property(TcorePlugin *plugin, const char *key, void *d void *tcore_plugin_ref_property(TcorePlugin *plugin, const char *key) { - if (!plugin) + if (plugin == NULL) return NULL; - if (!plugin->property) + if (plugin->property == NULL) return NULL; return g_hash_table_lookup(plugin->property, key); diff --git a/src/queue.c b/src/queue.c index 84f2235..56bdfa0 100644 --- a/src/queue.c +++ b/src/queue.c @@ -85,7 +85,7 @@ static gboolean _on_pending_timeout(gpointer user_data) dbg("pending timeout!!"); - if (!p) + if (p == NULL) return FALSE; tcore_pending_emit_timeout_callback(p); @@ -100,8 +100,8 @@ TcorePending *tcore_pending_new(CoreObject *co, unsigned int id) { TcorePending *p; - p = calloc(1, sizeof(struct tcore_pending_type)); - if (!p) + p = g_try_new0(struct tcore_pending_type, 1); + if (p == NULL) return NULL; p->id = id; @@ -126,7 +126,7 @@ TcorePending *tcore_pending_new(CoreObject *co, unsigned int id) void tcore_pending_free(TcorePending *pending) { - if (!pending) + if (pending == NULL) return; dbg("pending(0x%x) free, id=0x%x", (unsigned int)pending, pending->id); @@ -135,19 +135,19 @@ void tcore_pending_free(TcorePending *pending) && (tcore_hal_get_mode(pending->queue->hal) != TCORE_HAL_MODE_TRANSPARENT)) { if (pending->data) - free(pending->data); + g_free(pending->data); } if (pending->timer_src) { g_source_remove(pending->timer_src); } - free(pending); + g_free(pending); } unsigned int tcore_pending_get_id(TcorePending *pending) { - if (!pending) + if (pending == NULL) return 0; return pending->id; @@ -156,7 +156,7 @@ unsigned int tcore_pending_get_id(TcorePending *pending) TReturn tcore_pending_set_auto_free_status_after_sent(TcorePending *pending, gboolean flag) { - if (!pending) + if (pending == NULL) return TCORE_RETURN_EINVAL; pending->flag_auto_free_after_sent = flag; @@ -166,7 +166,7 @@ TReturn tcore_pending_set_auto_free_status_after_sent(TcorePending *pending, gboolean tcore_pending_get_auto_free_status_after_sent(TcorePending *pending) { - if (!pending) + if (pending == NULL) return FALSE; return pending->flag_auto_free_after_sent; @@ -175,20 +175,20 @@ gboolean tcore_pending_get_auto_free_status_after_sent(TcorePending *pending) TReturn tcore_pending_set_request_data(TcorePending *pending, unsigned int data_len, void *data) { - if (!pending) + if (pending == NULL) return TCORE_RETURN_EINVAL; if (pending->data) { if (pending->data_len != 0) { - free(pending->data); + g_free(pending->data); pending->data = NULL; } } pending->data_len = data_len; if (pending->data_len > 0) { - pending->data = calloc(data_len, 1); - if (!pending->data) + pending->data = g_try_malloc0(data_len); + if (pending->data == NULL) return TCORE_RETURN_ENOMEM; memcpy(pending->data, data, data_len); @@ -202,7 +202,7 @@ TReturn tcore_pending_set_request_data(TcorePending *pending, void *tcore_pending_ref_request_data(TcorePending *pending, unsigned int *data_len) { - if (!pending) + if (pending == NULL) return NULL; if (data_len) @@ -214,7 +214,7 @@ void *tcore_pending_ref_request_data(TcorePending *pending, unsigned int *data_l TReturn tcore_pending_set_priority(TcorePending *pending, enum tcore_pending_priority priority) { - if (!pending) + if (pending == NULL) return TCORE_RETURN_EINVAL; pending->priority = priority; @@ -225,7 +225,7 @@ TReturn tcore_pending_set_priority(TcorePending *pending, TReturn tcore_pending_get_priority(TcorePending *pending, enum tcore_pending_priority *result_priority) { - if (!pending || !result_priority) + if ((pending == NULL) || (result_priority == NULL)) return TCORE_RETURN_EINVAL; *result_priority = pending->priority; @@ -235,7 +235,7 @@ TReturn tcore_pending_get_priority(TcorePending *pending, TReturn tcore_pending_set_timeout(TcorePending *pending, unsigned int timeout) { - if (!pending) + if (pending == NULL) return TCORE_RETURN_EINVAL; pending->timeout = timeout; @@ -246,7 +246,7 @@ TReturn tcore_pending_set_timeout(TcorePending *pending, unsigned int timeout) TReturn tcore_pending_get_send_status(TcorePending *pending, gboolean *result_status) { - if (!pending || !result_status) + if ((pending == NULL) || (result_status == NULL)) return TCORE_RETURN_EINVAL; *result_status = pending->flag_sent; @@ -257,7 +257,7 @@ TReturn tcore_pending_get_send_status(TcorePending *pending, TReturn tcore_pending_set_send_callback(TcorePending *pending, TcorePendingSendCallback func, void *user_data) { - if (!pending) + if (pending == NULL) return TCORE_RETURN_EINVAL; pending->on_send = func; @@ -269,7 +269,7 @@ TReturn tcore_pending_set_send_callback(TcorePending *pending, TReturn tcore_pending_set_timeout_callback(TcorePending *pending, TcorePendingTimeoutCallback func, void *user_data) { - if (!pending) + if (pending == NULL) return TCORE_RETURN_EINVAL; pending->on_timeout = func; @@ -281,7 +281,7 @@ TReturn tcore_pending_set_timeout_callback(TcorePending *pending, TReturn tcore_pending_set_response_callback(TcorePending *pending, TcorePendingResponseCallback func, void *user_data) { - if (!pending) + if (pending == NULL) return TCORE_RETURN_EINVAL; pending->on_response = func; @@ -292,7 +292,7 @@ TReturn tcore_pending_set_response_callback(TcorePending *pending, TReturn tcore_pending_emit_send_callback(TcorePending *pending, gboolean result) { - if (!pending) + if (pending == NULL) return TCORE_RETURN_EINVAL; pending->flag_sent = TRUE; @@ -313,7 +313,7 @@ TReturn tcore_pending_emit_send_callback(TcorePending *pending, gboolean result) TReturn tcore_pending_emit_timeout_callback(TcorePending *pending) { - if (!pending) + if (pending == NULL) return TCORE_RETURN_EINVAL; if (pending->on_timeout) @@ -325,7 +325,7 @@ TReturn tcore_pending_emit_timeout_callback(TcorePending *pending) TReturn tcore_pending_emit_response_callback(TcorePending *pending, int data_len, const void *data) { - if (!pending) + if (pending == NULL) return TCORE_RETURN_EINVAL; if (pending->on_response) @@ -337,7 +337,7 @@ TReturn tcore_pending_emit_response_callback(TcorePending *pending, CoreObject *tcore_pending_ref_core_object(TcorePending *pending) { - if (!pending) + if (pending == NULL) return NULL; return pending->co; @@ -345,7 +345,7 @@ CoreObject *tcore_pending_ref_core_object(TcorePending *pending) TcorePlugin *tcore_pending_ref_plugin(TcorePending *pending) { - if (!pending) + if (pending == NULL) return NULL; return pending->plugin; @@ -353,7 +353,7 @@ TcorePlugin *tcore_pending_ref_plugin(TcorePending *pending) TReturn tcore_pending_link_user_request(TcorePending *pending, UserRequest *ur) { - if (!pending) + if (pending == NULL) return TCORE_RETURN_EINVAL; pending->ur = ur; @@ -363,7 +363,7 @@ TReturn tcore_pending_link_user_request(TcorePending *pending, UserRequest *ur) UserRequest *tcore_pending_ref_user_request(TcorePending *pending) { - if (!pending) + if (pending == NULL) return NULL; return pending->ur; @@ -373,15 +373,15 @@ TcoreQueue *tcore_queue_new(TcoreHal *h) { TcoreQueue *queue; - queue = calloc(1, sizeof(struct tcore_queue_type)); - if (!queue) + queue = g_try_new0(struct tcore_queue_type, 1); + if (queue == NULL) return FALSE; queue->hal = h; queue->gq = g_queue_new(); - if (!queue->gq) { - free(queue); + if (queue->gq == NULL) { + g_free(queue); return FALSE; } @@ -392,13 +392,13 @@ TcoreQueue *tcore_queue_new(TcoreHal *h) void tcore_queue_free(TcoreQueue *queue) { - if (!queue) + if (queue == NULL) return; if (queue->gq) g_queue_free(queue->gq); - free(queue); + g_free(queue); } static void _tcore_queue_push_head(TcoreQueue *queue, TcorePending *pending) @@ -409,7 +409,7 @@ static void _tcore_queue_push_head(TcoreQueue *queue, TcorePending *pending) do { i++; tmp = g_queue_peek_nth(queue->gq, i); - if (!tmp) { + if (tmp == NULL) { break; } @@ -426,7 +426,7 @@ TReturn tcore_queue_push(TcoreQueue *queue, TcorePending *pending) { enum tcore_pending_priority priority; - if (!queue || !pending) + if ((queue == NULL) || (pending == NULL)) return TCORE_RETURN_EINVAL; if (pending->id == 0) { @@ -461,7 +461,7 @@ TReturn tcore_queue_push(TcoreQueue *queue, TcorePending *pending) TcorePending *tcore_queue_pop(TcoreQueue *queue) { - if (!queue) + if (queue == NULL) return NULL; return g_queue_pop_head(queue->gq); @@ -472,12 +472,12 @@ TcorePending *tcore_queue_pop_by_pending(TcoreQueue *queue, TcorePending *pendin TcorePending *tmp; int i = 0; - if (!queue) + if (queue == NULL) return NULL; do { tmp = g_queue_peek_nth(queue->gq, i); - if (!tmp) + if (tmp == NULL) return NULL; if (tmp == pending) { @@ -501,7 +501,7 @@ TcorePending *tcore_queue_pop_timeout_pending(TcoreQueue *queue) do { pending = g_queue_peek_nth(queue->gq, i); - if (!pending) + if (pending == NULL) return NULL; if (cur_time - pending->timestamp >= (int)pending->timeout) { @@ -517,7 +517,7 @@ TcorePending *tcore_queue_pop_timeout_pending(TcoreQueue *queue) TcorePending *tcore_queue_ref_head(TcoreQueue *queue) { - if (!queue) + if (queue == NULL) return NULL; return g_queue_peek_head(queue->gq); @@ -525,7 +525,7 @@ TcorePending *tcore_queue_ref_head(TcoreQueue *queue) TcorePending *tcore_queue_ref_tail(TcoreQueue *queue) { - if (!queue) + if (queue == NULL) return NULL; return g_queue_peek_tail(queue->gq); @@ -539,12 +539,12 @@ static TcorePending *_tcore_queue_search_full(TcoreQueue *queue, unsigned int id int i = 0; UserRequest *ur; - if (!queue) + if (queue == NULL) return NULL; do { pending = g_queue_peek_nth(queue->gq, i); - if (!pending) + if (pending == NULL) return NULL; if ((field & 0xF0) == 0x10) { @@ -597,7 +597,7 @@ TcorePending *tcore_queue_search_by_command(TcoreQueue *queue, TcorePending *tcore_queue_pop_by_id(TcoreQueue *queue, unsigned int id) { - if (!queue) + if (queue == NULL) return NULL; return _tcore_queue_search_full(queue, id, 0, SEARCH_FIELD_ID_ALL, TRUE); @@ -605,7 +605,7 @@ TcorePending *tcore_queue_pop_by_id(TcoreQueue *queue, unsigned int id) TcorePending *tcore_queue_ref_pending_by_id(TcoreQueue *queue, unsigned int id) { - if (!queue) + if (queue == NULL) return NULL; return _tcore_queue_search_full(queue, id, 0, SEARCH_FIELD_ID_ALL, FALSE); @@ -616,12 +616,12 @@ TcorePending *tcore_queue_ref_next_pending(TcoreQueue *queue) TcorePending *pending = NULL; int i = 0; - if (!queue) + if (queue == NULL) return NULL; do { pending = g_queue_peek_nth(queue->gq, i); - if (!pending) { + if (pending == NULL) { return NULL; } @@ -649,7 +649,7 @@ TcorePending *tcore_queue_ref_next_pending(TcoreQueue *queue) unsigned int tcore_queue_get_length(TcoreQueue *queue) { - if (!queue) + if (queue == NULL) return 0; return g_queue_get_length(queue->gq); @@ -657,7 +657,7 @@ unsigned int tcore_queue_get_length(TcoreQueue *queue) TcoreHal *tcore_queue_ref_hal(TcoreQueue *queue) { - if (!queue) + if (queue == NULL) return NULL; return queue->hal; @@ -667,12 +667,12 @@ TReturn tcore_queue_cancel_pending_by_command(TcoreQueue *queue, enum tcore_requ { TcorePending *pending; - if (!queue) + if (queue == NULL) return TCORE_RETURN_EINVAL; while (1) { pending = _tcore_queue_search_full(queue, 0, command, SEARCH_FIELD_COMMAND_ALL, FALSE); - if (!pending) + if (pending == NULL) break; dbg("pending(0x%x) cancel", (unsigned int)pending); diff --git a/src/server.c b/src/server.c index e5c4161..da168df 100644 --- a/src/server.c +++ b/src/server.c @@ -27,6 +27,7 @@ #include #include +#include #include "tcore.h" #include "plugin.h" @@ -45,23 +46,35 @@ struct tcore_server_type { GSList *plugins; GSList *communicators; GSList *storages; - GSList *hals; + GSList *modems; + GSList *template_co; + GSList *hook_list_request; GSList *hook_list_notification; + TcorePlugin *default_plugin; TcoreUdev *udev; }; +struct tcore_modem_type { + char *cp_name; + TcorePlugin *modem_iface_plugin; + + TcorePlugin *modem_plugin; + + void *mapping_tbl; +}; + struct hook_request_type { enum tcore_request_command command; - TcoreServerRequestHook func; + tcore_server_request_hook func; void *user_data; }; struct hook_notification_type { enum tcore_notification_command command; - TcoreServerNotificationHook func; + tcore_server_notification_hook func; void *user_data; }; @@ -70,7 +83,7 @@ static gint _compare_priority(gconstpointer a, gconstpointer b) TcorePlugin *plugin1 = (TcorePlugin *)a; TcorePlugin *plugin2 = (TcorePlugin *)b; - if (!plugin2) + if (plugin2 == NULL) return 1; return tcore_plugin_get_description(plugin1)->priority - @@ -89,11 +102,11 @@ static TcorePlugin *_find_default_plugin(Server *s) for (list = s->plugins; list; list = list->next) { p = list->data; - if (!p) + if (p == NULL) continue; co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_MODEM); - if (!co_list) + if (co_list == NULL) continue; g_slist_free(co_list); @@ -104,16 +117,96 @@ static TcorePlugin *_find_default_plugin(Server *s) return NULL; } +static char *_server_enumerate_modem(TcorePlugin *plugin) +{ + static unsigned int cp_counter = 0; + char *cp_name; + char *filename; + char *name; + + if (plugin == NULL) + return NULL; + + /* + * Presently enumeration is based on Modem Interface Plug-in descriptor name + * followed by an incremental Positive integer 'cp_count'. + * + * For example, if Modem Interface Plug-in descriptor name is 'imcmodem' then, + * 'name' would be enumerated as "imcmode_N", where N >= 0 + */ + filename = tcore_plugin_get_filename(plugin); + if (filename == NULL) + return NULL; + + /* Stripping '.so' from 'filename' */ + name = strtok(filename, ".so"); + + cp_name = g_strdup_printf("%s_%d", name, cp_counter++); + g_free(filename); + + return cp_name; +} + +static TcoreModem *_server_find_modem(Server *s, + TcorePlugin *modem_iface_plugin, TcorePlugin *modem_plugin) +{ + GSList *list; + TcoreModem *modem; + + for (list = s->modems; list; list = list->next) { + modem = list->data; + if (modem == NULL) + continue; + + /* + * Specifically for Unregister, Add Modem Plug-in + * and Add/Remove Mapping Table - + * + * MUST match Modem Interface Plug-in + * AND + * If passed Modem Interface Plug-in is NULL, then + * Modem Interface Plug-in of 'modems' MUST be NULL + */ + if ((modem_iface_plugin == modem->modem_iface_plugin) + && ((modem_plugin == NULL) && (modem->modem_plugin == NULL))) + return modem; + + /* + * Specifically for get Mapping Table - + * + * Modem Interface Plug-in MUST be NULL + * AND + * Passed Modem Plug-in MUST match Modem Plug-of 'modems' + */ + if ((modem_iface_plugin == NULL) + && (modem_plugin == modem->modem_plugin)) + return modem; + + /* + * Specifically for get CP name - + * + * Passed Modem OR Modem Interface Plug-in MUST match + * AND + * MUST match either Modem OR Modem Interface Plug-in of 'modems' + */ + if ((modem_iface_plugin == modem_plugin) + && ((modem_iface_plugin == modem->modem_iface_plugin) + || (modem_plugin == modem->modem_plugin))) + return modem; + } + + return NULL; +} Server *tcore_server_new() { Server *s; - s = calloc(1, sizeof(struct tcore_server_type)); - if (!s) + s = g_try_new0(struct tcore_server_type, 1); + if (s == NULL) return NULL; s->mainloop = g_main_loop_new (NULL, FALSE); - if (!s->mainloop) { + if (s->mainloop == NULL) { free(s); return NULL; } @@ -121,7 +214,6 @@ Server *tcore_server_new() s->plugins = NULL; s->communicators = NULL; s->storages = NULL; - s->hals = NULL; s->hook_list_request = NULL; s->hook_list_notification = NULL; s->default_plugin = NULL; @@ -135,7 +227,7 @@ void tcore_server_free(Server *s) TcorePlugin *p = NULL; struct tcore_plugin_define_desc *desc = NULL; - if (!s) + if (s == NULL) return; if (s->mainloop) @@ -143,11 +235,11 @@ void tcore_server_free(Server *s) for (list = s->plugins; list; list = list->next) { p = list->data; - if (!p) + if (p == NULL) continue; desc = (struct tcore_plugin_define_desc *)tcore_plugin_get_description(p); - if (!desc || !desc->unload) + if ((desc == NULL) || (desc->unload == NULL)) continue; desc->unload(p); @@ -161,13 +253,16 @@ void tcore_server_free(Server *s) g_slist_free(s->plugins); s->plugins = NULL; } + + /* Freeing Server */ + g_free(s); } TReturn tcore_server_run(Server *s) { char *version; - if (!s || !s->mainloop) + if ((s == NULL)|| (s->mainloop == NULL)) return TCORE_RETURN_EINVAL; version = tcore_util_get_version(); @@ -185,7 +280,7 @@ TReturn tcore_server_run(Server *s) TReturn tcore_server_exit(Server *s) { - if (!s || !s->mainloop) + if ((s == NULL)|| (s->mainloop == NULL)) return TCORE_RETURN_EINVAL; g_main_loop_quit(s->mainloop); @@ -195,7 +290,7 @@ TReturn tcore_server_exit(Server *s) TReturn tcore_server_add_plugin(Server *s, TcorePlugin *plugin) { - if (!s || !plugin) + if ((s == NULL)|| (plugin == NULL)) return TCORE_RETURN_EINVAL; s->plugins = g_slist_insert_sorted(s->plugins, plugin, _compare_priority); @@ -216,7 +311,7 @@ TcorePlugin *tcore_server_find_plugin(Server *s, const char *name) for (list = s->plugins; list; list = list->next) { p = list->data; - if (!p) { + if (p == NULL) { continue; } @@ -230,7 +325,7 @@ TcorePlugin *tcore_server_find_plugin(Server *s, const char *name) GSList *tcore_server_ref_plugins(Server *s) { - if (!s) + if (s == NULL) return NULL; return s->plugins; @@ -238,7 +333,7 @@ GSList *tcore_server_ref_plugins(Server *s) TReturn tcore_server_add_communicator(Server *s, Communicator *comm) { - if (!s || !comm) + if ((s == NULL)|| (comm == NULL)) return TCORE_RETURN_EINVAL; s->communicators = g_slist_insert(s->communicators, comm, 0); @@ -250,7 +345,7 @@ TReturn tcore_server_add_communicator(Server *s, Communicator *comm) GSList *tcore_server_ref_communicators(Server *s) { - if (!s) + if (s == NULL) return NULL; return s->communicators; @@ -263,7 +358,7 @@ Communicator *tcore_server_find_communicator(Server *s, const char *name) for (list = s->communicators; list; list = list->next) { comm = list->data; - if (!comm) { + if (comm == NULL) { continue; } @@ -277,7 +372,7 @@ Communicator *tcore_server_find_communicator(Server *s, const char *name) TReturn tcore_server_add_storage(Server *s, Storage *strg) { - if (!s || !strg) + if ((s == NULL)|| (strg == NULL)) return TCORE_RETURN_EINVAL; s->storages = g_slist_insert(s->storages, strg, 0); @@ -289,7 +384,7 @@ TReturn tcore_server_add_storage(Server *s, Storage *strg) GSList *tcore_server_ref_storages(Server *s) { - if (!s) + if (s == NULL) return NULL; return s->storages; @@ -302,7 +397,7 @@ Storage *tcore_server_find_storage(Server *s, const char *name) for (list = s->storages; list; list = list->next) { strg = list->data; - if (!strg) { + if (strg == NULL) { continue; } @@ -314,77 +409,17 @@ Storage *tcore_server_find_storage(Server *s, const char *name) return NULL; } -TReturn tcore_server_add_hal(Server *s, TcoreHal *hal) -{ - GSList *list; - TcoreHal *temp; - - if (!s || !hal) - return TCORE_RETURN_EINVAL; - - for (list = s->hals; list; list = list->next) { - temp = list->data; - if (!temp) { - continue; - } - - if (temp == hal) - return TCORE_RETURN_EALREADY; - } - - s->hals = g_slist_insert(s->hals, hal, 0); - - tcore_server_send_notification(s, NULL, TNOTI_SERVER_ADDED_HAL, 0, NULL); - - return TCORE_RETURN_SUCCESS; -} - -GSList *tcore_server_ref_hals(Server *s) -{ - if (!s) - return NULL; - - return s->hals; -} - -TcoreHal *tcore_server_find_hal(Server *s, const char *name) -{ - GSList *list; - TcoreHal *hal; - char *buf; - - for (list = s->hals; list; list = list->next) { - hal = list->data; - if (!hal) { - continue; - } - - buf = tcore_hal_get_name(hal); - if (!buf) - continue; - - if (g_strcmp0(buf, name) == 0) { - free(buf); - return hal; - } - - free(buf); - } - - return NULL; -} - TReturn tcore_server_add_template_object(Server *s, CoreObject *template_co) { GSList *list; CoreObject *temp; - if (!s || !template_co) + if ((s == NULL)|| (template_co == NULL)) return TCORE_RETURN_EINVAL; for (list = s->template_co; list; list = list->next) { temp = list->data; - if (!temp) { + if (temp == NULL) { continue; } @@ -400,7 +435,7 @@ TReturn tcore_server_add_template_object(Server *s, CoreObject *template_co) GSList *tcore_server_ref_template_object(Server *s) { - if (!s) + if (s == NULL) return NULL; return s->template_co; @@ -413,7 +448,7 @@ CoreObject *tcore_server_find_template_object(Server *s, unsigned int type) for (list = s->template_co; list; list = list->next) { template_co = list->data; - if (!template_co) { + if (template_co == NULL) { continue; } @@ -427,7 +462,7 @@ CoreObject *tcore_server_find_template_object(Server *s, unsigned int type) TReturn tcore_server_link_udev(Server *s, TcoreUdev *udev) { - if (!s || !udev) + if ((s == NULL)|| (udev == NULL)) return TCORE_RETURN_EINVAL; s->udev = udev; @@ -437,7 +472,7 @@ TReturn tcore_server_link_udev(Server *s, TcoreUdev *udev) TcoreUdev *tcore_server_ref_udev(Server *s) { - if (!s) + if (s == NULL) return NULL; return s->udev; @@ -451,15 +486,15 @@ TReturn tcore_server_dispatch_request(Server *s, UserRequest *ur) GSList *list, *co_list=NULL; struct hook_request_type *hook; int category; - CoreObject *o; + CoreObject *co; TReturn ret = TCORE_RETURN_ENOSYS; - if (!s || !ur) + if ((s == NULL)|| (ur == NULL)) return TCORE_RETURN_EINVAL; for (list = s->hook_list_request; list; list = list->next) { hook = list->data; - if (!hook) { + if (hook == NULL) { continue; } @@ -471,11 +506,11 @@ TReturn tcore_server_dispatch_request(Server *s, UserRequest *ur) } modem = tcore_user_request_get_modem_name(ur); - if (!modem) + if (modem == NULL) return TCORE_RETURN_EINVAL; p = tcore_server_find_plugin(s, modem); - if (!p) { + if (p == NULL) { free(modem); return TCORE_RETURN_SERVER_WRONG_PLUGIN; } @@ -486,19 +521,19 @@ TReturn tcore_server_dispatch_request(Server *s, UserRequest *ur) category = CORE_OBJECT_TYPE_DEFAULT | (command & 0x0FF00000); co_list = tcore_plugin_get_core_objects_bytype(p, category); - if (!co_list) { + if (co_list == NULL) { warn("can't find 0x%x core_object", category); return TCORE_RETURN_ENOSYS; } for (list = co_list; list; list = list->next) { - o = (CoreObject *) list->data; - if (!o) { + co = (CoreObject *) list->data; + if (co == NULL) { warn("can't find 0x%x core_object", category); continue; } - if (tcore_object_dispatch_request(o, ur) == TCORE_RETURN_SUCCESS) + if (tcore_object_dispatch_request(co, ur) == TCORE_RETURN_SUCCESS) ret = TCORE_RETURN_SUCCESS; else dbg("failed..."); @@ -516,12 +551,12 @@ TReturn tcore_server_send_notification(Server *s, CoreObject *source, Communicator *comm; struct hook_notification_type *hook; - if (!s) + if (s == NULL) return TCORE_RETURN_EINVAL; for (list = s->hook_list_notification; list; list = list->next) { hook = list->data; - if (!hook) { + if (hook == NULL) { continue; } @@ -534,7 +569,7 @@ TReturn tcore_server_send_notification(Server *s, CoreObject *source, for (list = s->communicators; list; list = list->next) { comm = list->data; - if (!comm) { + if (comm == NULL) { continue; } @@ -546,15 +581,15 @@ TReturn tcore_server_send_notification(Server *s, CoreObject *source, TReturn tcore_server_add_request_hook(Server *s, enum tcore_request_command command, - TcoreServerRequestHook func, void *user_data) + tcore_server_request_hook func, void *user_data) { struct hook_request_type *hook; - if (!s || !func) + if ((s == NULL)|| (func == NULL)) return TCORE_RETURN_EINVAL; - hook = calloc(1, sizeof(struct hook_request_type)); - if (!hook) + hook = g_try_new0(struct hook_request_type, 1); + if (hook == NULL) return TCORE_RETURN_ENOMEM; hook->command = command; @@ -566,17 +601,17 @@ TReturn tcore_server_add_request_hook(Server *s, return TCORE_RETURN_SUCCESS; } -TReturn tcore_server_remove_request_hook(Server *s, TcoreServerRequestHook func) +TReturn tcore_server_remove_request_hook(Server *s, tcore_server_request_hook func) { struct hook_request_type *hook; GSList *list; - if (!s) + if (s == NULL) return TCORE_RETURN_EINVAL; for (list = s->hook_list_request; list; list = list->next) { hook = list->data; - if (!hook) { + if (hook == NULL) { continue; } @@ -592,15 +627,15 @@ TReturn tcore_server_remove_request_hook(Server *s, TcoreServerRequestHook func) TReturn tcore_server_add_notification_hook(Server *s, enum tcore_notification_command command, - TcoreServerNotificationHook func, void *user_data) + tcore_server_notification_hook func, void *user_data) { struct hook_notification_type *hook; - if (!s || !func) + if ((s == NULL)|| (func == NULL)) return TCORE_RETURN_EINVAL; - hook = calloc(1, sizeof(struct hook_notification_type)); - if (!hook) + hook = g_try_new0(struct hook_notification_type, 1); + if (hook == NULL) return TCORE_RETURN_ENOMEM; hook->command = command; @@ -613,17 +648,17 @@ TReturn tcore_server_add_notification_hook(Server *s, } TReturn tcore_server_remove_notification_hook(Server *s, - TcoreServerNotificationHook func) + tcore_server_notification_hook func) { struct hook_notification_type *hook; GSList *list; - if (!s) + if (s == NULL) return TCORE_RETURN_EINVAL; for (list = s->hook_list_notification; list; list = list->next) { hook = list->data; - if (!hook) { + if (hook == NULL) { continue; } @@ -636,3 +671,180 @@ TReturn tcore_server_remove_notification_hook(Server *s, return TCORE_RETURN_SUCCESS; } + +gboolean tcore_server_register_modem(Server *s, TcorePlugin *modem_iface_plugin) +{ + TcoreModem *modem; + + if ((s == NULL) || (modem_iface_plugin == NULL)) + return FALSE; + + modem = g_try_new0(TcoreModem, 1); + if (modem == NULL) + return FALSE; + + modem->cp_name = _server_enumerate_modem(modem_iface_plugin); + modem->modem_iface_plugin = modem_iface_plugin; + + s->modems = g_slist_append(s->modems, modem); + + return TRUE; +} + +void tcore_server_unregister_modem(Server *s, TcorePlugin *modem_iface_plugin) +{ + TcoreModem *modem; + + if ((s == NULL) || (modem_iface_plugin == NULL)) + return; + + modem = _server_find_modem(s, modem_iface_plugin, NULL); + if (modem == NULL) + return; + + s->modems = g_slist_remove(s->modems, modem); + + g_free(modem->cp_name); + g_free(modem); +} + +gboolean tcore_server_update_modem_plugin(TcorePlugin *modem_iface_plugin, + TcorePlugin *modem_plugin) +{ + Server *s; + TcoreModem *modem; + + if ((modem_iface_plugin == NULL) || (modem_plugin == NULL)) + return FALSE; + + s = tcore_plugin_ref_server(modem_iface_plugin); + if (s == NULL) + return FALSE; + + modem = _server_find_modem(s, modem_iface_plugin, NULL); + if (modem == NULL) + return FALSE; + + modem->modem_plugin = modem_plugin; + + return TRUE; +} + +char **tcore_server_get_cp_name_list(Server *s) +{ + char **cp_name_list = NULL; + GSList *list; + unsigned int list_count; + TcoreModem *modem; + + int i = 0; + + if (s == NULL) + return NULL; + + list_count = g_slist_length(s->modems); + if (list_count == 0) + return NULL; + + /* (+1) is considered for NULL string to define the last string */ + cp_name_list = g_try_new0(char *, list_count + 1); + if (cp_name_list == NULL) + return NULL; + + for (list = s->modems; list; list = list->next) { + modem = list->data; + if (modem == NULL) + continue; + + cp_name_list[i] = g_strdup(modem->cp_name); + dbg("CP Name[%d] = %s", i, cp_name_list[i]); + + i++; + } + + /* 'cp_name_list' would be freed by the calling function */ + return cp_name_list; +} + +const char *tcore_server_get_cp_name_by_plugin(TcorePlugin *plugin) +{ + Server *s; + TcoreModem *modem; + + if (plugin == NULL) + return NULL; + + s = tcore_plugin_ref_server(plugin); + if (s == NULL) + return NULL; + + modem = _server_find_modem(s, plugin, plugin); + if (modem == NULL) + return NULL; + + return (const char *)modem->cp_name; +} + +gboolean tcore_server_add_cp_mapping_tbl_entry(TcorePlugin *modem_iface_plugin, + unsigned int co_type, TcoreHal *hal) +{ + Server *s; + TcoreModem *modem; + + if (modem_iface_plugin == NULL) + return FALSE; + + s = tcore_plugin_ref_server(modem_iface_plugin); + if (s == NULL) + return FALSE; + + modem = _server_find_modem(s, modem_iface_plugin, NULL); + if (modem == NULL) + return FALSE; + + /* + * Set the Mapping Table to the Modems list + */ + return tcore_object_add_mapping_tbl_entry(modem->mapping_tbl, co_type, hal); +} + +void tcore_server_remove_cp_mapping_tbl_entry(TcorePlugin *modem_iface_plugin, + TcoreHal *hal) +{ + Server *s; + TcoreModem *modem; + + if (modem_iface_plugin == NULL) + return; + + s = tcore_plugin_ref_server(modem_iface_plugin); + if (s == NULL) + return; + + modem = _server_find_modem(s, modem_iface_plugin, NULL); + if (modem == NULL) + return; + + /* Removing the Mapping Table from the Modems list */ + tcore_object_remove_mapping_tbl_entry(modem->mapping_tbl, hal); + modem->mapping_tbl = NULL; +} + +void *tcore_server_get_cp_mapping_tbl(TcorePlugin *modem_plugin) +{ + Server *s; + TcoreModem *modem; + + if (modem_plugin == NULL) + return NULL; + + s = tcore_plugin_ref_server(modem_plugin); + if (s == NULL) + return NULL; + + modem = _server_find_modem(s, NULL, modem_plugin); + if (modem == NULL) + return NULL; + + return modem->mapping_tbl; +}