mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2025-12-10 07:44:41 +01:00
Linux Kernel Coding Style
This commit is contained in:
parent
6cf5c90a44
commit
a51a8eb4e7
44 changed files with 5566 additions and 6219 deletions
547
.clang-format
Normal file
547
.clang-format
Normal file
|
|
@ -0,0 +1,547 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
#
|
||||
# clang-format configuration file. Intended for clang-format >= 4.
|
||||
#
|
||||
# For more information, see:
|
||||
#
|
||||
# Documentation/process/clang-format.rst
|
||||
# https://clang.llvm.org/docs/ClangFormat.html
|
||||
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||
#
|
||||
---
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
#AlignEscapedNewlines: Left # Unknown to clang-format-4.0
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: true
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
#AfterExternBlock: false # Unknown to clang-format-5.0
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
#SplitEmptyFunction: true # Unknown to clang-format-4.0
|
||||
#SplitEmptyRecord: true # Unknown to clang-format-4.0
|
||||
#SplitEmptyNamespace: true # Unknown to clang-format-4.0
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Custom
|
||||
#BreakBeforeInheritanceComma: false # Unknown to clang-format-4.0
|
||||
BreakBeforeTernaryOperators: false
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
#BreakConstructorInitializers: BeforeComma # Unknown to clang-format-4.0
|
||||
#BreakAfterJavaFieldAnnotations: false
|
||||
#BreakStringLiterals: false
|
||||
ColumnLimit: 300
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
#CompactNamespaces: false # Unknown to clang-format-4.0
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 8
|
||||
ContinuationIndentWidth: 8
|
||||
Cpp11BracedListStyle: false
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
#FixNamespaceComments: false # Unknown to clang-format-4.0
|
||||
|
||||
# Taken from:
|
||||
# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ \
|
||||
# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
|
||||
# | sort | uniq
|
||||
ForEachMacros:
|
||||
- 'apei_estatus_for_each_section'
|
||||
- 'ata_for_each_dev'
|
||||
- 'ata_for_each_link'
|
||||
- '__ata_qc_for_each'
|
||||
- 'ata_qc_for_each'
|
||||
- 'ata_qc_for_each_raw'
|
||||
- 'ata_qc_for_each_with_internal'
|
||||
- 'ax25_for_each'
|
||||
- 'ax25_uid_for_each'
|
||||
- '__bio_for_each_bvec'
|
||||
- 'bio_for_each_bvec'
|
||||
- 'bio_for_each_bvec_all'
|
||||
- 'bio_for_each_integrity_vec'
|
||||
- '__bio_for_each_segment'
|
||||
- 'bio_for_each_segment'
|
||||
- 'bio_for_each_segment_all'
|
||||
- 'bio_list_for_each'
|
||||
- 'bip_for_each_vec'
|
||||
- 'bitmap_for_each_clear_region'
|
||||
- 'bitmap_for_each_set_region'
|
||||
- 'blkg_for_each_descendant_post'
|
||||
- 'blkg_for_each_descendant_pre'
|
||||
- 'blk_queue_for_each_rl'
|
||||
- 'bond_for_each_slave'
|
||||
- 'bond_for_each_slave_rcu'
|
||||
- 'bpf_for_each_spilled_reg'
|
||||
- 'btree_for_each_safe128'
|
||||
- 'btree_for_each_safe32'
|
||||
- 'btree_for_each_safe64'
|
||||
- 'btree_for_each_safel'
|
||||
- 'card_for_each_dev'
|
||||
- 'cgroup_taskset_for_each'
|
||||
- 'cgroup_taskset_for_each_leader'
|
||||
- 'cpufreq_for_each_entry'
|
||||
- 'cpufreq_for_each_entry_idx'
|
||||
- 'cpufreq_for_each_valid_entry'
|
||||
- 'cpufreq_for_each_valid_entry_idx'
|
||||
- 'css_for_each_child'
|
||||
- 'css_for_each_descendant_post'
|
||||
- 'css_for_each_descendant_pre'
|
||||
- 'device_for_each_child_node'
|
||||
- 'dma_fence_chain_for_each'
|
||||
- 'do_for_each_ftrace_op'
|
||||
- 'drm_atomic_crtc_for_each_plane'
|
||||
- 'drm_atomic_crtc_state_for_each_plane'
|
||||
- 'drm_atomic_crtc_state_for_each_plane_state'
|
||||
- 'drm_atomic_for_each_plane_damage'
|
||||
- 'drm_client_for_each_connector_iter'
|
||||
- 'drm_client_for_each_modeset'
|
||||
- 'drm_connector_for_each_possible_encoder'
|
||||
- 'drm_for_each_bridge_in_chain'
|
||||
- 'drm_for_each_connector_iter'
|
||||
- 'drm_for_each_crtc'
|
||||
- 'drm_for_each_encoder'
|
||||
- 'drm_for_each_encoder_mask'
|
||||
- 'drm_for_each_fb'
|
||||
- 'drm_for_each_legacy_plane'
|
||||
- 'drm_for_each_plane'
|
||||
- 'drm_for_each_plane_mask'
|
||||
- 'drm_for_each_privobj'
|
||||
- 'drm_mm_for_each_hole'
|
||||
- 'drm_mm_for_each_node'
|
||||
- 'drm_mm_for_each_node_in_range'
|
||||
- 'drm_mm_for_each_node_safe'
|
||||
- 'flow_action_for_each'
|
||||
- 'for_each_active_dev_scope'
|
||||
- 'for_each_active_drhd_unit'
|
||||
- 'for_each_active_iommu'
|
||||
- 'for_each_aggr_pgid'
|
||||
- 'for_each_available_child_of_node'
|
||||
- 'for_each_bio'
|
||||
- 'for_each_board_func_rsrc'
|
||||
- 'for_each_bvec'
|
||||
- 'for_each_card_auxs'
|
||||
- 'for_each_card_auxs_safe'
|
||||
- 'for_each_card_components'
|
||||
- 'for_each_card_dapms'
|
||||
- 'for_each_card_pre_auxs'
|
||||
- 'for_each_card_prelinks'
|
||||
- 'for_each_card_rtds'
|
||||
- 'for_each_card_rtds_safe'
|
||||
- 'for_each_card_widgets'
|
||||
- 'for_each_card_widgets_safe'
|
||||
- 'for_each_cgroup_storage_type'
|
||||
- 'for_each_child_of_node'
|
||||
- 'for_each_clear_bit'
|
||||
- 'for_each_clear_bit_from'
|
||||
- 'for_each_cmsghdr'
|
||||
- 'for_each_compatible_node'
|
||||
- 'for_each_component_dais'
|
||||
- 'for_each_component_dais_safe'
|
||||
- 'for_each_comp_order'
|
||||
- 'for_each_console'
|
||||
- 'for_each_cpu'
|
||||
- 'for_each_cpu_and'
|
||||
- 'for_each_cpu_not'
|
||||
- 'for_each_cpu_wrap'
|
||||
- 'for_each_dapm_widgets'
|
||||
- 'for_each_dev_addr'
|
||||
- 'for_each_dev_scope'
|
||||
- 'for_each_displayid_db'
|
||||
- 'for_each_dma_cap_mask'
|
||||
- 'for_each_dpcm_be'
|
||||
- 'for_each_dpcm_be_rollback'
|
||||
- 'for_each_dpcm_be_safe'
|
||||
- 'for_each_dpcm_fe'
|
||||
- 'for_each_drhd_unit'
|
||||
- 'for_each_dss_dev'
|
||||
- 'for_each_efi_memory_desc'
|
||||
- 'for_each_efi_memory_desc_in_map'
|
||||
- 'for_each_element'
|
||||
- 'for_each_element_extid'
|
||||
- 'for_each_element_id'
|
||||
- 'for_each_endpoint_of_node'
|
||||
- 'for_each_evictable_lru'
|
||||
- 'for_each_fib6_node_rt_rcu'
|
||||
- 'for_each_fib6_walker_rt'
|
||||
- 'for_each_free_mem_pfn_range_in_zone'
|
||||
- 'for_each_free_mem_pfn_range_in_zone_from'
|
||||
- 'for_each_free_mem_range'
|
||||
- 'for_each_free_mem_range_reverse'
|
||||
- 'for_each_func_rsrc'
|
||||
- 'for_each_hstate'
|
||||
- 'for_each_if'
|
||||
- 'for_each_iommu'
|
||||
- 'for_each_ip_tunnel_rcu'
|
||||
- 'for_each_irq_nr'
|
||||
- 'for_each_link_codecs'
|
||||
- 'for_each_link_cpus'
|
||||
- 'for_each_link_platforms'
|
||||
- 'for_each_lru'
|
||||
- 'for_each_matching_node'
|
||||
- 'for_each_matching_node_and_match'
|
||||
- 'for_each_member'
|
||||
- 'for_each_mem_region'
|
||||
- 'for_each_memblock_type'
|
||||
- 'for_each_memcg_cache_index'
|
||||
- 'for_each_mem_pfn_range'
|
||||
- '__for_each_mem_range'
|
||||
- 'for_each_mem_range'
|
||||
- '__for_each_mem_range_rev'
|
||||
- 'for_each_mem_range_rev'
|
||||
- 'for_each_migratetype_order'
|
||||
- 'for_each_msi_entry'
|
||||
- 'for_each_msi_entry_safe'
|
||||
- 'for_each_net'
|
||||
- 'for_each_net_continue_reverse'
|
||||
- 'for_each_netdev'
|
||||
- 'for_each_netdev_continue'
|
||||
- 'for_each_netdev_continue_rcu'
|
||||
- 'for_each_netdev_continue_reverse'
|
||||
- 'for_each_netdev_feature'
|
||||
- 'for_each_netdev_in_bond_rcu'
|
||||
- 'for_each_netdev_rcu'
|
||||
- 'for_each_netdev_reverse'
|
||||
- 'for_each_netdev_safe'
|
||||
- 'for_each_net_rcu'
|
||||
- 'for_each_new_connector_in_state'
|
||||
- 'for_each_new_crtc_in_state'
|
||||
- 'for_each_new_mst_mgr_in_state'
|
||||
- 'for_each_new_plane_in_state'
|
||||
- 'for_each_new_private_obj_in_state'
|
||||
- 'for_each_node'
|
||||
- 'for_each_node_by_name'
|
||||
- 'for_each_node_by_type'
|
||||
- 'for_each_node_mask'
|
||||
- 'for_each_node_state'
|
||||
- 'for_each_node_with_cpus'
|
||||
- 'for_each_node_with_property'
|
||||
- 'for_each_nonreserved_multicast_dest_pgid'
|
||||
- 'for_each_of_allnodes'
|
||||
- 'for_each_of_allnodes_from'
|
||||
- 'for_each_of_cpu_node'
|
||||
- 'for_each_of_pci_range'
|
||||
- 'for_each_old_connector_in_state'
|
||||
- 'for_each_old_crtc_in_state'
|
||||
- 'for_each_old_mst_mgr_in_state'
|
||||
- 'for_each_oldnew_connector_in_state'
|
||||
- 'for_each_oldnew_crtc_in_state'
|
||||
- 'for_each_oldnew_mst_mgr_in_state'
|
||||
- 'for_each_oldnew_plane_in_state'
|
||||
- 'for_each_oldnew_plane_in_state_reverse'
|
||||
- 'for_each_oldnew_private_obj_in_state'
|
||||
- 'for_each_old_plane_in_state'
|
||||
- 'for_each_old_private_obj_in_state'
|
||||
- 'for_each_online_cpu'
|
||||
- 'for_each_online_node'
|
||||
- 'for_each_online_pgdat'
|
||||
- 'for_each_pci_bridge'
|
||||
- 'for_each_pci_dev'
|
||||
- 'for_each_pci_msi_entry'
|
||||
- 'for_each_pcm_streams'
|
||||
- 'for_each_physmem_range'
|
||||
- 'for_each_populated_zone'
|
||||
- 'for_each_possible_cpu'
|
||||
- 'for_each_present_cpu'
|
||||
- 'for_each_prime_number'
|
||||
- 'for_each_prime_number_from'
|
||||
- 'for_each_process'
|
||||
- 'for_each_process_thread'
|
||||
- 'for_each_property_of_node'
|
||||
- 'for_each_registered_fb'
|
||||
- 'for_each_requested_gpio'
|
||||
- 'for_each_requested_gpio_in_range'
|
||||
- 'for_each_reserved_mem_range'
|
||||
- 'for_each_reserved_mem_region'
|
||||
- 'for_each_rtd_codec_dais'
|
||||
- 'for_each_rtd_codec_dais_rollback'
|
||||
- 'for_each_rtd_components'
|
||||
- 'for_each_rtd_cpu_dais'
|
||||
- 'for_each_rtd_cpu_dais_rollback'
|
||||
- 'for_each_rtd_dais'
|
||||
- 'for_each_set_bit'
|
||||
- 'for_each_set_bit_from'
|
||||
- 'for_each_set_clump8'
|
||||
- 'for_each_sg'
|
||||
- 'for_each_sg_dma_page'
|
||||
- 'for_each_sg_page'
|
||||
- 'for_each_sgtable_dma_page'
|
||||
- 'for_each_sgtable_dma_sg'
|
||||
- 'for_each_sgtable_page'
|
||||
- 'for_each_sgtable_sg'
|
||||
- 'for_each_sibling_event'
|
||||
- 'for_each_subelement'
|
||||
- 'for_each_subelement_extid'
|
||||
- 'for_each_subelement_id'
|
||||
- '__for_each_thread'
|
||||
- 'for_each_thread'
|
||||
- 'for_each_unicast_dest_pgid'
|
||||
- 'for_each_wakeup_source'
|
||||
- 'for_each_zone'
|
||||
- 'for_each_zone_zonelist'
|
||||
- 'for_each_zone_zonelist_nodemask'
|
||||
- 'fwnode_for_each_available_child_node'
|
||||
- 'fwnode_for_each_child_node'
|
||||
- 'fwnode_graph_for_each_endpoint'
|
||||
- 'gadget_for_each_ep'
|
||||
- 'genradix_for_each'
|
||||
- 'genradix_for_each_from'
|
||||
- 'hash_for_each'
|
||||
- 'hash_for_each_possible'
|
||||
- 'hash_for_each_possible_rcu'
|
||||
- 'hash_for_each_possible_rcu_notrace'
|
||||
- 'hash_for_each_possible_safe'
|
||||
- 'hash_for_each_rcu'
|
||||
- 'hash_for_each_safe'
|
||||
- 'hctx_for_each_ctx'
|
||||
- 'hlist_bl_for_each_entry'
|
||||
- 'hlist_bl_for_each_entry_rcu'
|
||||
- 'hlist_bl_for_each_entry_safe'
|
||||
- 'hlist_for_each'
|
||||
- 'hlist_for_each_entry'
|
||||
- 'hlist_for_each_entry_continue'
|
||||
- 'hlist_for_each_entry_continue_rcu'
|
||||
- 'hlist_for_each_entry_continue_rcu_bh'
|
||||
- 'hlist_for_each_entry_from'
|
||||
- 'hlist_for_each_entry_from_rcu'
|
||||
- 'hlist_for_each_entry_rcu'
|
||||
- 'hlist_for_each_entry_rcu_bh'
|
||||
- 'hlist_for_each_entry_rcu_notrace'
|
||||
- 'hlist_for_each_entry_safe'
|
||||
- '__hlist_for_each_rcu'
|
||||
- 'hlist_for_each_safe'
|
||||
- 'hlist_nulls_for_each_entry'
|
||||
- 'hlist_nulls_for_each_entry_from'
|
||||
- 'hlist_nulls_for_each_entry_rcu'
|
||||
- 'hlist_nulls_for_each_entry_safe'
|
||||
- 'i3c_bus_for_each_i2cdev'
|
||||
- 'i3c_bus_for_each_i3cdev'
|
||||
- 'ide_host_for_each_port'
|
||||
- 'ide_port_for_each_dev'
|
||||
- 'ide_port_for_each_present_dev'
|
||||
- 'idr_for_each_entry'
|
||||
- 'idr_for_each_entry_continue'
|
||||
- 'idr_for_each_entry_continue_ul'
|
||||
- 'idr_for_each_entry_ul'
|
||||
- 'in_dev_for_each_ifa_rcu'
|
||||
- 'in_dev_for_each_ifa_rtnl'
|
||||
- 'inet_bind_bucket_for_each'
|
||||
- 'inet_lhash2_for_each_icsk_rcu'
|
||||
- 'key_for_each'
|
||||
- 'key_for_each_safe'
|
||||
- 'klp_for_each_func'
|
||||
- 'klp_for_each_func_safe'
|
||||
- 'klp_for_each_func_static'
|
||||
- 'klp_for_each_object'
|
||||
- 'klp_for_each_object_safe'
|
||||
- 'klp_for_each_object_static'
|
||||
- 'kunit_suite_for_each_test_case'
|
||||
- 'kvm_for_each_memslot'
|
||||
- 'kvm_for_each_vcpu'
|
||||
- 'list_for_each'
|
||||
- 'list_for_each_codec'
|
||||
- 'list_for_each_codec_safe'
|
||||
- 'list_for_each_continue'
|
||||
- 'list_for_each_entry'
|
||||
- 'list_for_each_entry_continue'
|
||||
- 'list_for_each_entry_continue_rcu'
|
||||
- 'list_for_each_entry_continue_reverse'
|
||||
- 'list_for_each_entry_from'
|
||||
- 'list_for_each_entry_from_rcu'
|
||||
- 'list_for_each_entry_from_reverse'
|
||||
- 'list_for_each_entry_lockless'
|
||||
- 'list_for_each_entry_rcu'
|
||||
- 'list_for_each_entry_reverse'
|
||||
- 'list_for_each_entry_safe'
|
||||
- 'list_for_each_entry_safe_continue'
|
||||
- 'list_for_each_entry_safe_from'
|
||||
- 'list_for_each_entry_safe_reverse'
|
||||
- 'list_for_each_prev'
|
||||
- 'list_for_each_prev_safe'
|
||||
- 'list_for_each_safe'
|
||||
- 'llist_for_each'
|
||||
- 'llist_for_each_entry'
|
||||
- 'llist_for_each_entry_safe'
|
||||
- 'llist_for_each_safe'
|
||||
- 'mci_for_each_dimm'
|
||||
- 'media_device_for_each_entity'
|
||||
- 'media_device_for_each_intf'
|
||||
- 'media_device_for_each_link'
|
||||
- 'media_device_for_each_pad'
|
||||
- 'nanddev_io_for_each_page'
|
||||
- 'netdev_for_each_lower_dev'
|
||||
- 'netdev_for_each_lower_private'
|
||||
- 'netdev_for_each_lower_private_rcu'
|
||||
- 'netdev_for_each_mc_addr'
|
||||
- 'netdev_for_each_uc_addr'
|
||||
- 'netdev_for_each_upper_dev_rcu'
|
||||
- 'netdev_hw_addr_list_for_each'
|
||||
- 'nft_rule_for_each_expr'
|
||||
- 'nla_for_each_attr'
|
||||
- 'nla_for_each_nested'
|
||||
- 'nlmsg_for_each_attr'
|
||||
- 'nlmsg_for_each_msg'
|
||||
- 'nr_neigh_for_each'
|
||||
- 'nr_neigh_for_each_safe'
|
||||
- 'nr_node_for_each'
|
||||
- 'nr_node_for_each_safe'
|
||||
- 'of_for_each_phandle'
|
||||
- 'of_property_for_each_string'
|
||||
- 'of_property_for_each_u32'
|
||||
- 'pci_bus_for_each_resource'
|
||||
- 'pcm_for_each_format'
|
||||
- 'ping_portaddr_for_each_entry'
|
||||
- 'plist_for_each'
|
||||
- 'plist_for_each_continue'
|
||||
- 'plist_for_each_entry'
|
||||
- 'plist_for_each_entry_continue'
|
||||
- 'plist_for_each_entry_safe'
|
||||
- 'plist_for_each_safe'
|
||||
- 'pnp_for_each_card'
|
||||
- 'pnp_for_each_dev'
|
||||
- 'protocol_for_each_card'
|
||||
- 'protocol_for_each_dev'
|
||||
- 'queue_for_each_hw_ctx'
|
||||
- 'radix_tree_for_each_slot'
|
||||
- 'radix_tree_for_each_tagged'
|
||||
- 'rbtree_postorder_for_each_entry_safe'
|
||||
- 'rdma_for_each_block'
|
||||
- 'rdma_for_each_port'
|
||||
- 'rdma_umem_for_each_dma_block'
|
||||
- 'resource_list_for_each_entry'
|
||||
- 'resource_list_for_each_entry_safe'
|
||||
- 'rhl_for_each_entry_rcu'
|
||||
- 'rhl_for_each_rcu'
|
||||
- 'rht_for_each'
|
||||
- 'rht_for_each_entry'
|
||||
- 'rht_for_each_entry_from'
|
||||
- 'rht_for_each_entry_rcu'
|
||||
- 'rht_for_each_entry_rcu_from'
|
||||
- 'rht_for_each_entry_safe'
|
||||
- 'rht_for_each_from'
|
||||
- 'rht_for_each_rcu'
|
||||
- 'rht_for_each_rcu_from'
|
||||
- '__rq_for_each_bio'
|
||||
- 'rq_for_each_bvec'
|
||||
- 'rq_for_each_segment'
|
||||
- 'scsi_for_each_prot_sg'
|
||||
- 'scsi_for_each_sg'
|
||||
- 'sctp_for_each_hentry'
|
||||
- 'sctp_skb_for_each'
|
||||
- 'shdma_for_each_chan'
|
||||
- '__shost_for_each_device'
|
||||
- 'shost_for_each_device'
|
||||
- 'sk_for_each'
|
||||
- 'sk_for_each_bound'
|
||||
- 'sk_for_each_entry_offset_rcu'
|
||||
- 'sk_for_each_from'
|
||||
- 'sk_for_each_rcu'
|
||||
- 'sk_for_each_safe'
|
||||
- 'sk_nulls_for_each'
|
||||
- 'sk_nulls_for_each_from'
|
||||
- 'sk_nulls_for_each_rcu'
|
||||
- 'snd_array_for_each'
|
||||
- 'snd_pcm_group_for_each_entry'
|
||||
- 'snd_soc_dapm_widget_for_each_path'
|
||||
- 'snd_soc_dapm_widget_for_each_path_safe'
|
||||
- 'snd_soc_dapm_widget_for_each_sink_path'
|
||||
- 'snd_soc_dapm_widget_for_each_source_path'
|
||||
- 'tb_property_for_each'
|
||||
- 'tcf_exts_for_each_action'
|
||||
- 'udp_portaddr_for_each_entry'
|
||||
- 'udp_portaddr_for_each_entry_rcu'
|
||||
- 'usb_hub_for_each_child'
|
||||
- 'v4l2_device_for_each_subdev'
|
||||
- 'v4l2_m2m_for_each_dst_buf'
|
||||
- 'v4l2_m2m_for_each_dst_buf_safe'
|
||||
- 'v4l2_m2m_for_each_src_buf'
|
||||
- 'v4l2_m2m_for_each_src_buf_safe'
|
||||
- 'virtio_device_for_each_vq'
|
||||
- 'while_for_each_ftrace_op'
|
||||
- 'xa_for_each'
|
||||
- 'xa_for_each_marked'
|
||||
- 'xa_for_each_range'
|
||||
- 'xa_for_each_start'
|
||||
- 'xas_for_each'
|
||||
- 'xas_for_each_conflict'
|
||||
- 'xas_for_each_marked'
|
||||
- 'xbc_array_for_each_value'
|
||||
- 'xbc_for_each_key_value'
|
||||
- 'xbc_node_for_each_array_value'
|
||||
- 'xbc_node_for_each_child'
|
||||
- 'xbc_node_for_each_key_value'
|
||||
- 'zorro_for_each_dev'
|
||||
|
||||
#IncludeBlocks: Preserve # Unknown to clang-format-5.0
|
||||
IncludeCategories:
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
#IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: false
|
||||
#IndentPPDirectives: None # Unknown to clang-format-5.0
|
||||
IndentWidth: 8
|
||||
IndentWrappedFunctionNames: false
|
||||
#JavaScriptQuotes: Leave
|
||||
#JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
#ObjCBinPackProtocolList: Auto # Unknown to clang-format-5.0
|
||||
ObjCBlockIndentWidth: 8
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
|
||||
# Taken from git's rules
|
||||
#PenaltyBreakAssignment: 10 # Unknown to clang-format-4.0
|
||||
PenaltyBreakBeforeFirstCallParameter: 30
|
||||
PenaltyBreakComment: 10
|
||||
PenaltyBreakFirstLessLess: 0
|
||||
PenaltyBreakString: 10
|
||||
PenaltyExcessCharacter: 100
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
|
||||
PointerAlignment: Right
|
||||
ReflowComments: false
|
||||
SortIncludes: false
|
||||
#SortUsingDeclarations: false # Unknown to clang-format-4.0
|
||||
SpaceAfterCStyleCast: false
|
||||
#SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
#SpaceBeforeCtorInitializerColon: true # Unknown to clang-format-5.0
|
||||
#SpaceBeforeInheritanceColon: true # Unknown to clang-format-5.0
|
||||
SpaceBeforeParens: ControlStatements
|
||||
#SpaceBeforeRangeBasedForLoopColon: true # Unknown to clang-format-5.0
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp03
|
||||
TabWidth: 8
|
||||
UseTab: Always
|
||||
1560
backupSession.c
1560
backupSession.c
File diff suppressed because it is too large
Load diff
65
common.c
65
common.c
|
|
@ -14,25 +14,23 @@
|
|||
|
||||
char *commandKey = NULL;
|
||||
|
||||
struct option cwmp_long_options[] = {
|
||||
{"boot-event", no_argument, NULL, 'b'},
|
||||
{"get-rpc-methods", no_argument, NULL, 'g'},
|
||||
{"command-input", no_argument, NULL, 'c'},
|
||||
{"shell-cli", required_argument, NULL, 'm'},
|
||||
{"alias-based-addressing", no_argument, NULL, 'a'},
|
||||
{"instance-mode-number", no_argument, NULL, 'N'},
|
||||
{"instance-mode-alias", no_argument, NULL, 'A'},
|
||||
{"upnp", no_argument, NULL, 'U'},
|
||||
{"user-acl", required_argument, NULL, 'u'},
|
||||
{"amendment", required_argument, NULL, 'M'},
|
||||
{"time-tracking", no_argument, NULL, 't'},
|
||||
{"evaluating-test", no_argument, NULL, 'E'},
|
||||
{"file", required_argument, NULL, 'f'},
|
||||
{"wep", required_argument, NULL, 'w'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
struct option cwmp_long_options[] = { { "boot-event", no_argument, NULL, 'b' },
|
||||
{ "get-rpc-methods", no_argument, NULL, 'g' },
|
||||
{ "command-input", no_argument, NULL, 'c' },
|
||||
{ "shell-cli", required_argument, NULL, 'm' },
|
||||
{ "alias-based-addressing", no_argument, NULL, 'a' },
|
||||
{ "instance-mode-number", no_argument, NULL, 'N' },
|
||||
{ "instance-mode-alias", no_argument, NULL, 'A' },
|
||||
{ "upnp", no_argument, NULL, 'U' },
|
||||
{ "user-acl", required_argument, NULL, 'u' },
|
||||
{ "amendment", required_argument, NULL, 'M' },
|
||||
{ "time-tracking", no_argument, NULL, 't' },
|
||||
{ "evaluating-test", no_argument, NULL, 'E' },
|
||||
{ "file", required_argument, NULL, 'f' },
|
||||
{ "wep", required_argument, NULL, 'w' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'v' },
|
||||
{ NULL, 0, NULL, 0 } };
|
||||
|
||||
static void show_help(void)
|
||||
{
|
||||
|
|
@ -46,21 +44,18 @@ static void show_help(void)
|
|||
static void show_version()
|
||||
{
|
||||
#ifndef CWMP_REVISION
|
||||
fprintf(stdout, "\nVersion: %s\n\n",CWMP_VERSION);
|
||||
fprintf(stdout, "\nVersion: %s\n\n", CWMP_VERSION);
|
||||
#else
|
||||
fprintf(stdout, "\nVersion: %s revision %s\n\n",CWMP_VERSION,CWMP_REVISION);
|
||||
fprintf(stdout, "\nVersion: %s revision %s\n\n", CWMP_VERSION, CWMP_REVISION);
|
||||
#endif
|
||||
}
|
||||
|
||||
int global_env_init (int argc, char** argv, struct env *env)
|
||||
int global_env_init(int argc, char **argv, struct env *env)
|
||||
{
|
||||
|
||||
int c, option_index = 0;
|
||||
|
||||
while ((c = getopt_long(argc, argv, "bghv", cwmp_long_options, &option_index)) != -1) {
|
||||
|
||||
switch (c)
|
||||
{
|
||||
switch (c) {
|
||||
case 'b':
|
||||
env->boot = CWMP_START_BOOT;
|
||||
break;
|
||||
|
|
@ -90,8 +85,7 @@ void add_dm_parameter_tolist(struct list_head *head, char *param_name, char *par
|
|||
dm_parameter = list_entry(ilist, struct cwmp_dm_parameter, list);
|
||||
cmp = strcmp(dm_parameter->name, param_name);
|
||||
if (cmp == 0) {
|
||||
if (param_data && strcmp(dm_parameter->data, param_data) != 0)
|
||||
{
|
||||
if (param_data && strcmp(dm_parameter->data, param_data) != 0) {
|
||||
free(dm_parameter->data);
|
||||
dm_parameter->data = strdup(param_data);
|
||||
}
|
||||
|
|
@ -102,9 +96,12 @@ void add_dm_parameter_tolist(struct list_head *head, char *param_name, char *par
|
|||
}
|
||||
dm_parameter = calloc(1, sizeof(struct cwmp_dm_parameter));
|
||||
_list_add(&dm_parameter->list, ilist->prev, ilist);
|
||||
if (param_name) dm_parameter->name = strdup(param_name);
|
||||
if (param_data) dm_parameter->data = strdup(param_data);
|
||||
if (param_type) dm_parameter->type = strdup(param_type ? param_type : "xsd:string");
|
||||
if (param_name)
|
||||
dm_parameter->name = strdup(param_name);
|
||||
if (param_data)
|
||||
dm_parameter->data = strdup(param_data);
|
||||
if (param_type)
|
||||
dm_parameter->type = strdup(param_type ? param_type : "xsd:string");
|
||||
}
|
||||
|
||||
void delete_dm_parameter_fromlist(struct cwmp_dm_parameter *dm_parameter)
|
||||
|
|
@ -119,7 +116,7 @@ void delete_dm_parameter_fromlist(struct cwmp_dm_parameter *dm_parameter)
|
|||
void free_dm_parameter_all_fromlist(struct list_head *list)
|
||||
{
|
||||
struct cwmp_dm_parameter *dm_parameter;
|
||||
while (list->next!=list) {
|
||||
while (list->next != list) {
|
||||
dm_parameter = list_entry(list->next, struct cwmp_dm_parameter, list);
|
||||
delete_dm_parameter_fromlist(dm_parameter);
|
||||
}
|
||||
|
|
@ -144,7 +141,7 @@ void cwmp_del_list_fault_param(struct cwmp_param_fault *param_fault)
|
|||
free(param_fault);
|
||||
}
|
||||
|
||||
void cwmp_add_list_param_value(char *param, char* value, struct list_head *list_param_value)
|
||||
void cwmp_add_list_param_value(char *param, char *value, struct list_head *list_param_value)
|
||||
{
|
||||
struct cwmp_param_value *param_value = NULL;
|
||||
if (param == NULL)
|
||||
|
|
@ -153,7 +150,7 @@ void cwmp_add_list_param_value(char *param, char* value, struct list_head *list_
|
|||
param_value = calloc(1, sizeof(struct cwmp_param_value));
|
||||
list_add_tail(¶m_value->list, list_param_value);
|
||||
param_value->param = strdup(param);
|
||||
param_value->value = strdup(value?value:"");
|
||||
param_value->value = strdup(value ? value : "");
|
||||
}
|
||||
|
||||
void cwmp_del_list_param_value(struct cwmp_param_value *param_value)
|
||||
|
|
|
|||
732
cwmp.c
732
cwmp.c
|
|
@ -10,234 +10,211 @@
|
|||
* Author Omar Kallel <omar.kallel@pivasoftware.com>
|
||||
*/
|
||||
|
||||
|
||||
#include "cwmp.h"
|
||||
|
||||
struct cwmp cwmp_main = {0};
|
||||
struct cwmp cwmp_main = { 0 };
|
||||
|
||||
|
||||
int cwmp_session_rpc_destructor (struct rpc *rpc)
|
||||
int cwmp_session_rpc_destructor(struct rpc *rpc)
|
||||
{
|
||||
list_del(&(rpc->list));
|
||||
free (rpc);
|
||||
return CWMP_OK;
|
||||
list_del(&(rpc->list));
|
||||
free(rpc);
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int cwmp_get_retry_interval (struct cwmp *cwmp)
|
||||
int cwmp_get_retry_interval(struct cwmp *cwmp)
|
||||
{
|
||||
int retry_count = 0;
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
int m = cwmp->conf.retry_min_wait_interval;
|
||||
int k = cwmp->conf.retry_interval_multiplier;
|
||||
int exp = cwmp->retry_count_session;
|
||||
if (exp == 0) return MAX_INT32;
|
||||
if (exp > 10) exp = 10;
|
||||
min = pow(((double)k/1000), (double)(exp-1)) * m;
|
||||
max = pow(((double)k/1000), (double)exp) * m;
|
||||
srand (time(NULL));
|
||||
retry_count = rand() % ((int)max + 1 - (int)min) + (int)min;
|
||||
return (retry_count);
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
int m = cwmp->conf.retry_min_wait_interval;
|
||||
int k = cwmp->conf.retry_interval_multiplier;
|
||||
int exp = cwmp->retry_count_session;
|
||||
if (exp == 0)
|
||||
return MAX_INT32;
|
||||
if (exp > 10)
|
||||
exp = 10;
|
||||
min = pow(((double)k / 1000), (double)(exp - 1)) * m;
|
||||
max = pow(((double)k / 1000), (double)exp) * m;
|
||||
srand(time(NULL));
|
||||
retry_count = rand() % ((int)max + 1 - (int)min) + (int)min;
|
||||
return (retry_count);
|
||||
}
|
||||
|
||||
static void cwmp_prepare_value_change (struct cwmp *cwmp)
|
||||
static void cwmp_prepare_value_change(struct cwmp *cwmp)
|
||||
{
|
||||
struct event_container *event_container;
|
||||
if (list_value_change.next == &(list_value_change))
|
||||
return;
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_queue));
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_4VALUE_CHANGE, "");
|
||||
if (!event_container) goto end;
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, "");
|
||||
if (!event_container)
|
||||
goto end;
|
||||
pthread_mutex_lock(&(mutex_value_change));
|
||||
list_splice_init(&(list_value_change), &(event_container->head_dm_parameter));
|
||||
pthread_mutex_unlock(&(mutex_value_change));
|
||||
cwmp_save_event_container (event_container);
|
||||
cwmp_save_event_container(event_container);
|
||||
|
||||
end:
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
}
|
||||
|
||||
int cwmp_session_destructor (struct session *session)
|
||||
int cwmp_session_destructor(struct session *session)
|
||||
{
|
||||
struct rpc *rpc;
|
||||
|
||||
while (session->head_rpc_acs.next != &(session->head_rpc_acs)) {
|
||||
rpc = list_entry(session->head_rpc_acs.next, struct rpc, list);
|
||||
while (session->head_rpc_acs.next != &(session->head_rpc_acs)) {
|
||||
rpc = list_entry(session->head_rpc_acs.next, struct rpc, list);
|
||||
if (rpc_acs_methods[rpc->type].extra_clean != NULL)
|
||||
rpc_acs_methods[rpc->type].extra_clean(session,rpc);
|
||||
cwmp_session_rpc_destructor(rpc);
|
||||
}
|
||||
rpc_acs_methods[rpc->type].extra_clean(session, rpc);
|
||||
cwmp_session_rpc_destructor(rpc);
|
||||
}
|
||||
|
||||
while (session->head_rpc_cpe.next != &(session->head_rpc_cpe)) {
|
||||
rpc = list_entry(session->head_rpc_cpe.next, struct rpc, list);
|
||||
cwmp_session_rpc_destructor(rpc);
|
||||
}
|
||||
while (session->head_rpc_cpe.next != &(session->head_rpc_cpe)) {
|
||||
rpc = list_entry(session->head_rpc_cpe.next, struct rpc, list);
|
||||
cwmp_session_rpc_destructor(rpc);
|
||||
}
|
||||
|
||||
if (session->list.next != NULL && session->list.prev != NULL)
|
||||
list_del (&(session->list));
|
||||
if (session->list.next != NULL && session->list.prev != NULL)
|
||||
list_del(&(session->list));
|
||||
|
||||
free (session);
|
||||
free(session);
|
||||
|
||||
return CWMP_OK;
|
||||
return CWMP_OK;
|
||||
}
|
||||
int cwmp_move_session_to_session_queue (struct cwmp *cwmp, struct session *session)
|
||||
int cwmp_move_session_to_session_queue(struct cwmp *cwmp, struct session *session)
|
||||
{
|
||||
struct list_head *ilist, *jlist;
|
||||
struct rpc *rpc_acs, *queue_rpc_acs, *rpc_cpe;
|
||||
struct event_container *event_container_old, *event_container_new;
|
||||
struct session *session_queue;
|
||||
bool dup;
|
||||
struct list_head *ilist, *jlist;
|
||||
struct rpc *rpc_acs, *queue_rpc_acs, *rpc_cpe;
|
||||
struct event_container *event_container_old, *event_container_new;
|
||||
struct session *session_queue;
|
||||
bool dup;
|
||||
|
||||
pthread_mutex_lock (&(cwmp->mutex_session_queue));
|
||||
cwmp->retry_count_session ++;
|
||||
cwmp->session_send = NULL;
|
||||
if (cwmp->head_session_queue.next == &(cwmp->head_session_queue))
|
||||
{
|
||||
list_add_tail (&(session->list), &(cwmp->head_session_queue));
|
||||
session->hold_request = 0;
|
||||
session->digest_auth = 0;
|
||||
cwmp->head_event_container = &(session->head_event_container);
|
||||
if (session->head_rpc_acs.next != &(session->head_rpc_acs))
|
||||
{
|
||||
rpc_acs = list_entry(session->head_rpc_acs.next, struct rpc, list);
|
||||
if (rpc_acs->type != RPC_ACS_INFORM)
|
||||
{
|
||||
if ((rpc_acs = cwmp_add_session_rpc_acs_head(session, RPC_ACS_INFORM)) == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((rpc_acs = cwmp_add_session_rpc_acs_head(session, RPC_ACS_INFORM)) == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_queue));
|
||||
cwmp->retry_count_session++;
|
||||
cwmp->session_send = NULL;
|
||||
if (cwmp->head_session_queue.next == &(cwmp->head_session_queue)) {
|
||||
list_add_tail(&(session->list), &(cwmp->head_session_queue));
|
||||
session->hold_request = 0;
|
||||
session->digest_auth = 0;
|
||||
cwmp->head_event_container = &(session->head_event_container);
|
||||
if (session->head_rpc_acs.next != &(session->head_rpc_acs)) {
|
||||
rpc_acs = list_entry(session->head_rpc_acs.next, struct rpc, list);
|
||||
if (rpc_acs->type != RPC_ACS_INFORM) {
|
||||
if ((rpc_acs = cwmp_add_session_rpc_acs_head(session, RPC_ACS_INFORM)) == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((rpc_acs = cwmp_add_session_rpc_acs_head(session, RPC_ACS_INFORM)) == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
}
|
||||
while (session->head_rpc_cpe.next != &(session->head_rpc_cpe))
|
||||
{
|
||||
rpc_cpe = list_entry(session->head_rpc_cpe.next, struct rpc, list);
|
||||
}
|
||||
while (session->head_rpc_cpe.next != &(session->head_rpc_cpe)) {
|
||||
rpc_cpe = list_entry(session->head_rpc_cpe.next, struct rpc, list);
|
||||
cwmp_session_rpc_destructor(rpc_cpe);
|
||||
}
|
||||
bkp_session_move_inform_to_inform_queue ();
|
||||
bkp_session_save();
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_OK;
|
||||
}
|
||||
list_for_each(ilist, &(session->head_event_container))
|
||||
{
|
||||
event_container_old = list_entry (ilist, struct event_container, list);
|
||||
event_container_new = cwmp_add_event_container (cwmp, event_container_old->code, event_container_old->command_key);
|
||||
if (event_container_new == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
list_splice_init(&(event_container_old->head_dm_parameter),
|
||||
&(event_container_new->head_dm_parameter));
|
||||
cwmp_save_event_container (event_container_new);
|
||||
}
|
||||
session_queue = list_entry(cwmp->head_event_container,struct session, head_event_container);
|
||||
list_for_each(ilist, &(session->head_rpc_acs))
|
||||
{
|
||||
rpc_acs = list_entry(ilist, struct rpc, list);
|
||||
dup = false;
|
||||
list_for_each(jlist, &(session_queue->head_rpc_acs))
|
||||
{
|
||||
queue_rpc_acs = list_entry(jlist, struct rpc, list);
|
||||
if (queue_rpc_acs->type == rpc_acs->type &&
|
||||
(rpc_acs->type == RPC_ACS_INFORM ||
|
||||
rpc_acs->type == RPC_ACS_GET_RPC_METHODS))
|
||||
{
|
||||
dup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dup)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ilist = ilist->prev;
|
||||
list_del(&(rpc_acs->list));
|
||||
list_add_tail (&(rpc_acs->list), &(session_queue->head_rpc_acs));
|
||||
}
|
||||
cwmp_session_destructor (session);
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_OK;
|
||||
bkp_session_move_inform_to_inform_queue();
|
||||
bkp_session_save();
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_OK;
|
||||
}
|
||||
list_for_each (ilist, &(session->head_event_container)) {
|
||||
event_container_old = list_entry(ilist, struct event_container, list);
|
||||
event_container_new = cwmp_add_event_container(cwmp, event_container_old->code, event_container_old->command_key);
|
||||
if (event_container_new == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
list_splice_init(&(event_container_old->head_dm_parameter), &(event_container_new->head_dm_parameter));
|
||||
cwmp_save_event_container(event_container_new);
|
||||
}
|
||||
session_queue = list_entry(cwmp->head_event_container, struct session, head_event_container);
|
||||
list_for_each (ilist, &(session->head_rpc_acs)) {
|
||||
rpc_acs = list_entry(ilist, struct rpc, list);
|
||||
dup = false;
|
||||
list_for_each (jlist, &(session_queue->head_rpc_acs)) {
|
||||
queue_rpc_acs = list_entry(jlist, struct rpc, list);
|
||||
if (queue_rpc_acs->type == rpc_acs->type && (rpc_acs->type == RPC_ACS_INFORM || rpc_acs->type == RPC_ACS_GET_RPC_METHODS)) {
|
||||
dup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dup) {
|
||||
continue;
|
||||
}
|
||||
ilist = ilist->prev;
|
||||
list_del(&(rpc_acs->list));
|
||||
list_add_tail(&(rpc_acs->list), &(session_queue->head_rpc_acs));
|
||||
}
|
||||
cwmp_session_destructor(session);
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int cwmp_schedule_rpc (struct cwmp *cwmp, struct session *session)
|
||||
int cwmp_schedule_rpc(struct cwmp *cwmp, struct session *session)
|
||||
{
|
||||
struct list_head *ilist;
|
||||
struct rpc *rpc_acs, *rpc_cpe;
|
||||
struct list_head *ilist;
|
||||
struct rpc *rpc_acs, *rpc_cpe;
|
||||
|
||||
if (http_client_init(cwmp)) {
|
||||
if (http_client_init(cwmp)) {
|
||||
CWMP_LOG(INFO, "Initializing http client failed");
|
||||
goto retry;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
list_for_each(ilist, &(session->head_rpc_acs)) {
|
||||
rpc_acs = list_entry (ilist, struct rpc, list);
|
||||
if (!rpc_acs->type)
|
||||
goto retry;
|
||||
while (1) {
|
||||
list_for_each (ilist, &(session->head_rpc_acs)) {
|
||||
rpc_acs = list_entry(ilist, struct rpc, list);
|
||||
if (!rpc_acs->type)
|
||||
goto retry;
|
||||
|
||||
CWMP_LOG (INFO,"Preparing the %s RPC message to send to the ACS",
|
||||
rpc_acs_methods[rpc_acs->type].name);
|
||||
if (rpc_acs_methods[rpc_acs->type].prepare_message(cwmp, session, rpc_acs))
|
||||
goto retry;
|
||||
CWMP_LOG(INFO, "Preparing the %s RPC message to send to the ACS", rpc_acs_methods[rpc_acs->type].name);
|
||||
if (rpc_acs_methods[rpc_acs->type].prepare_message(cwmp, session, rpc_acs))
|
||||
goto retry;
|
||||
|
||||
if (xml_set_cwmp_id(session))
|
||||
goto retry;
|
||||
if (xml_set_cwmp_id(session))
|
||||
goto retry;
|
||||
|
||||
CWMP_LOG (INFO,"Send the %s RPC message to the ACS",
|
||||
rpc_acs_methods[rpc_acs->type].name);
|
||||
if (xml_send_message(cwmp, session, rpc_acs))
|
||||
goto retry;
|
||||
CWMP_LOG(INFO, "Send the %s RPC message to the ACS", rpc_acs_methods[rpc_acs->type].name);
|
||||
if (xml_send_message(cwmp, session, rpc_acs))
|
||||
goto retry;
|
||||
|
||||
CWMP_LOG (INFO,"Get the %sResponse message from the ACS",
|
||||
rpc_acs_methods[rpc_acs->type].name);
|
||||
if (rpc_acs_methods[rpc_acs->type].parse_response)
|
||||
if (rpc_acs_methods[rpc_acs->type].parse_response(cwmp, session, rpc_acs))
|
||||
goto retry;
|
||||
CWMP_LOG(INFO, "Get the %sResponse message from the ACS", rpc_acs_methods[rpc_acs->type].name);
|
||||
if (rpc_acs_methods[rpc_acs->type].parse_response)
|
||||
if (rpc_acs_methods[rpc_acs->type].parse_response(cwmp, session, rpc_acs))
|
||||
goto retry;
|
||||
|
||||
ilist = ilist->prev;
|
||||
if (rpc_acs_methods[rpc_acs->type].extra_clean != NULL)
|
||||
rpc_acs_methods[rpc_acs->type].extra_clean(session,rpc_acs);
|
||||
cwmp_session_rpc_destructor(rpc_acs);
|
||||
MXML_DELETE(session->tree_in);
|
||||
MXML_DELETE(session->tree_out);
|
||||
if (session->hold_request)
|
||||
break;
|
||||
}
|
||||
CWMP_LOG (INFO,"Send empty message to the ACS");
|
||||
if (xml_send_message(cwmp, session, NULL))
|
||||
ilist = ilist->prev;
|
||||
if (rpc_acs_methods[rpc_acs->type].extra_clean != NULL)
|
||||
rpc_acs_methods[rpc_acs->type].extra_clean(session, rpc_acs);
|
||||
cwmp_session_rpc_destructor(rpc_acs);
|
||||
MXML_DELETE(session->tree_in);
|
||||
MXML_DELETE(session->tree_out);
|
||||
if (session->hold_request)
|
||||
break;
|
||||
}
|
||||
CWMP_LOG(INFO, "Send empty message to the ACS");
|
||||
if (xml_send_message(cwmp, session, NULL))
|
||||
goto retry;
|
||||
if (!session->tree_in)
|
||||
goto next;
|
||||
|
||||
CWMP_LOG (INFO,"Receive request from the ACS");
|
||||
CWMP_LOG(INFO, "Receive request from the ACS");
|
||||
if (xml_handle_message(session))
|
||||
goto retry;
|
||||
|
||||
while (session->head_rpc_cpe.next != &(session->head_rpc_cpe)) {
|
||||
rpc_cpe = list_entry (session->head_rpc_cpe.next, struct rpc, list);
|
||||
rpc_cpe = list_entry(session->head_rpc_cpe.next, struct rpc, list);
|
||||
if (!rpc_cpe->type)
|
||||
goto retry;
|
||||
|
||||
CWMP_LOG (INFO,"Preparing the %s%s message",
|
||||
rpc_cpe_methods[rpc_cpe->type].name,
|
||||
(rpc_cpe->type != RPC_CPE_FAULT) ? "Response" : "");
|
||||
CWMP_LOG(INFO, "Preparing the %s%s message", rpc_cpe_methods[rpc_cpe->type].name, (rpc_cpe->type != RPC_CPE_FAULT) ? "Response" : "");
|
||||
if (cwmp_rpc_cpe_handle_message(session, rpc_cpe))
|
||||
goto retry;
|
||||
MXML_DELETE(session->tree_in);
|
||||
|
||||
CWMP_LOG (INFO,"Send the %s%s message to the ACS",
|
||||
rpc_cpe_methods[rpc_cpe->type].name,
|
||||
(rpc_cpe->type != RPC_CPE_FAULT) ? "Response" : "");
|
||||
CWMP_LOG(INFO, "Send the %s%s message to the ACS", rpc_cpe_methods[rpc_cpe->type].name, (rpc_cpe->type != RPC_CPE_FAULT) ? "Response" : "");
|
||||
if (xml_send_message(cwmp, session, rpc_cpe))
|
||||
goto retry;
|
||||
MXML_DELETE(session->tree_out);
|
||||
|
|
@ -246,23 +223,23 @@ int cwmp_schedule_rpc (struct cwmp *cwmp, struct session *session)
|
|||
if (!session->tree_in)
|
||||
break;
|
||||
|
||||
CWMP_LOG (INFO,"Receive request from the ACS");
|
||||
CWMP_LOG(INFO, "Receive request from the ACS");
|
||||
if (xml_handle_message(session))
|
||||
goto retry;
|
||||
}
|
||||
|
||||
next:
|
||||
if (session->head_rpc_acs.next==&(session->head_rpc_acs))
|
||||
break;
|
||||
MXML_DELETE(session->tree_in);
|
||||
MXML_DELETE(session->tree_out);
|
||||
}
|
||||
next:
|
||||
if (session->head_rpc_acs.next == &(session->head_rpc_acs))
|
||||
break;
|
||||
MXML_DELETE(session->tree_in);
|
||||
MXML_DELETE(session->tree_out);
|
||||
}
|
||||
|
||||
session->error = CWMP_OK;
|
||||
goto end;
|
||||
|
||||
retry:
|
||||
CWMP_LOG (INFO,"Failed");
|
||||
CWMP_LOG(INFO, "Failed");
|
||||
session->error = CWMP_RETRY_SESSION;
|
||||
event_remove_noretry_event_container(session, cwmp);
|
||||
|
||||
|
|
@ -271,26 +248,25 @@ end:
|
|||
MXML_DELETE(session->tree_out);
|
||||
http_client_exit();
|
||||
xml_exit();
|
||||
return session->error;
|
||||
return session->error;
|
||||
}
|
||||
|
||||
int run_session_end_func ()
|
||||
int run_session_end_func()
|
||||
{
|
||||
|
||||
if (end_session_flag & END_SESSION_EXTERNAL_ACTION) {
|
||||
CWMP_LOG (INFO,"Executing external commands: end session request");
|
||||
CWMP_LOG(INFO, "Executing external commands: end session request");
|
||||
external_init();
|
||||
external_simple("end_session", NULL, 0);
|
||||
external_exit();
|
||||
}
|
||||
|
||||
if (end_session_flag & END_SESSION_RELOAD) {
|
||||
CWMP_LOG (INFO,"Config reload: end session request");
|
||||
CWMP_LOG(INFO, "Config reload: end session request");
|
||||
cwmp_apply_acs_changes();
|
||||
}
|
||||
|
||||
if (end_session_flag & END_SESSION_SET_NOTIFICATION_UPDATE) {
|
||||
CWMP_LOG (INFO,"SetParameterAttributes end session: update enabled notify file");
|
||||
CWMP_LOG(INFO, "SetParameterAttributes end session: update enabled notify file");
|
||||
cwmp_update_enabled_notify_file();
|
||||
}
|
||||
if (end_session_flag & END_SESSION_TRANSACTION_COMMIT) {
|
||||
|
|
@ -299,42 +275,42 @@ int run_session_end_func ()
|
|||
}
|
||||
|
||||
if (end_session_flag & END_SESSION_NSLOOKUP_DIAGNOSTIC) {
|
||||
CWMP_LOG (INFO,"Executing nslookupdiagnostic: end session request");
|
||||
CWMP_LOG(INFO, "Executing nslookupdiagnostic: end session request");
|
||||
cwmp_nslookup_diagnostics();
|
||||
}
|
||||
|
||||
if (end_session_flag & END_SESSION_TRACEROUTE_DIAGNOSTIC) {
|
||||
CWMP_LOG (INFO,"Executing traceroutediagnostic: end session request");
|
||||
CWMP_LOG(INFO, "Executing traceroutediagnostic: end session request");
|
||||
cwmp_traceroute_diagnostics();
|
||||
}
|
||||
|
||||
if (end_session_flag & END_SESSION_UDPECHO_DIAGNOSTIC) {
|
||||
CWMP_LOG (INFO,"Executing udpechodiagnostic: end session request");
|
||||
CWMP_LOG(INFO, "Executing udpechodiagnostic: end session request");
|
||||
cwmp_udp_echo_diagnostics();
|
||||
}
|
||||
|
||||
if (end_session_flag & END_SESSION_SERVERSELECTION_DIAGNOSTIC) {
|
||||
CWMP_LOG (INFO,"Executing serverselectiondiagnostic: end session request");
|
||||
CWMP_LOG(INFO, "Executing serverselectiondiagnostic: end session request");
|
||||
cwmp_serverselection_diagnostics();
|
||||
}
|
||||
|
||||
if (end_session_flag & END_SESSION_IPPING_DIAGNOSTIC) {
|
||||
CWMP_LOG (INFO,"Executing ippingdiagnostic: end session request");
|
||||
CWMP_LOG(INFO, "Executing ippingdiagnostic: end session request");
|
||||
cwmp_ip_ping_diagnostics();
|
||||
}
|
||||
|
||||
if (end_session_flag & END_SESSION_DOWNLOAD_DIAGNOSTIC) {
|
||||
CWMP_LOG (INFO,"Executing download diagnostic: end session request");
|
||||
CWMP_LOG(INFO, "Executing download diagnostic: end session request");
|
||||
cwmp_download_diagnostics();
|
||||
}
|
||||
|
||||
if (end_session_flag & END_SESSION_UPLOAD_DIAGNOSTIC) {
|
||||
CWMP_LOG (INFO,"Executing upload diagnostic: end session request");
|
||||
CWMP_LOG(INFO, "Executing upload diagnostic: end session request");
|
||||
cwmp_upload_diagnostics();
|
||||
}
|
||||
|
||||
if (end_session_flag & END_SESSION_REBOOT) {
|
||||
CWMP_LOG (INFO,"Executing Reboot: end session request");
|
||||
CWMP_LOG(INFO, "Executing Reboot: end session request");
|
||||
external_init();
|
||||
external_simple("reboot", commandKey, 0);
|
||||
FREE(commandKey);
|
||||
|
|
@ -343,7 +319,7 @@ int run_session_end_func ()
|
|||
}
|
||||
|
||||
if (end_session_flag & END_SESSION_X_FACTORY_RESET_SOFT) {
|
||||
CWMP_LOG (INFO,"Executing factory reset soft: end session request");
|
||||
CWMP_LOG(INFO, "Executing factory reset soft: end session request");
|
||||
external_init();
|
||||
external_simple("factory_reset_soft", NULL, 0);
|
||||
external_exit();
|
||||
|
|
@ -351,7 +327,7 @@ int run_session_end_func ()
|
|||
}
|
||||
|
||||
if (end_session_flag & END_SESSION_FACTORY_RESET) {
|
||||
CWMP_LOG (INFO,"Executing factory reset: end session request");
|
||||
CWMP_LOG(INFO, "Executing factory reset: end session request");
|
||||
external_init();
|
||||
external_simple("factory_reset", NULL, 0);
|
||||
external_exit();
|
||||
|
|
@ -362,87 +338,84 @@ int run_session_end_func ()
|
|||
return CWMP_OK;
|
||||
}
|
||||
|
||||
void cwmp_schedule_session (struct cwmp *cwmp)
|
||||
void cwmp_schedule_session(struct cwmp *cwmp)
|
||||
{
|
||||
struct list_head *ilist;
|
||||
struct session *session;
|
||||
int t,error = CWMP_OK;
|
||||
static struct timespec time_to_wait = {0, 0};
|
||||
bool retry = false;
|
||||
char *exec_download= NULL;
|
||||
int is_notify = 0;
|
||||
struct list_head *ilist;
|
||||
struct session *session;
|
||||
int t, error = CWMP_OK;
|
||||
static struct timespec time_to_wait = { 0, 0 };
|
||||
bool retry = false;
|
||||
char *exec_download = NULL;
|
||||
int is_notify = 0;
|
||||
|
||||
cwmp->cwmp_cr_event = 0;
|
||||
while (1)
|
||||
{
|
||||
pthread_mutex_lock (&(cwmp->mutex_session_send));
|
||||
ilist = (&(cwmp->head_session_queue))->next;
|
||||
while ((ilist == &(cwmp->head_session_queue)) || retry)
|
||||
{
|
||||
t = cwmp_get_retry_interval(cwmp);
|
||||
time_to_wait.tv_sec = time(NULL) + t;
|
||||
CWMP_LOG(INFO,"Waiting the next session");
|
||||
pthread_cond_timedwait(&(cwmp->threshold_session_send), &(cwmp->mutex_session_send), &time_to_wait);
|
||||
ilist = (&(cwmp->head_session_queue))->next;
|
||||
retry = false;
|
||||
}
|
||||
session = list_entry(ilist, struct session, list);
|
||||
if( access( DM_ENABLED_NOTIFY, F_OK ) != -1 ) {
|
||||
if(!event_exist_in_list(cwmp, EVENT_IDX_4VALUE_CHANGE))
|
||||
is_notify = check_value_change();
|
||||
}
|
||||
if(is_notify>0 || access(DM_ENABLED_NOTIFY, F_OK ) < 0)
|
||||
cwmp_update_enabled_notify_file();
|
||||
cwmp_prepare_value_change(cwmp);
|
||||
free_dm_parameter_all_fromlist(&list_value_change);
|
||||
if ((error = cwmp_move_session_to_session_send (cwmp, session))) {
|
||||
CWMP_LOG(EMERG,"FATAL error in the mutex process in the session scheduler!");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
cwmp->cwmp_cr_event = 0;
|
||||
while (1) {
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_send));
|
||||
ilist = (&(cwmp->head_session_queue))->next;
|
||||
while ((ilist == &(cwmp->head_session_queue)) || retry) {
|
||||
t = cwmp_get_retry_interval(cwmp);
|
||||
time_to_wait.tv_sec = time(NULL) + t;
|
||||
CWMP_LOG(INFO, "Waiting the next session");
|
||||
pthread_cond_timedwait(&(cwmp->threshold_session_send), &(cwmp->mutex_session_send), &time_to_wait);
|
||||
ilist = (&(cwmp->head_session_queue))->next;
|
||||
retry = false;
|
||||
}
|
||||
session = list_entry(ilist, struct session, list);
|
||||
if (access(DM_ENABLED_NOTIFY, F_OK) != -1) {
|
||||
if (!event_exist_in_list(cwmp, EVENT_IDX_4VALUE_CHANGE))
|
||||
is_notify = check_value_change();
|
||||
}
|
||||
if (is_notify > 0 || access(DM_ENABLED_NOTIFY, F_OK) < 0)
|
||||
cwmp_update_enabled_notify_file();
|
||||
cwmp_prepare_value_change(cwmp);
|
||||
free_dm_parameter_all_fromlist(&list_value_change);
|
||||
if ((error = cwmp_move_session_to_session_send(cwmp, session))) {
|
||||
CWMP_LOG(EMERG, "FATAL error in the mutex process in the session scheduler!");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
cwmp->session_status.last_end_time = 0;
|
||||
cwmp->session_status.last_start_time = time(NULL);
|
||||
cwmp->session_status.last_status = SESSION_RUNNING;
|
||||
cwmp->session_status.next_retry = 0;
|
||||
cwmp->session_status.last_end_time = 0;
|
||||
cwmp->session_status.last_start_time = time(NULL);
|
||||
cwmp->session_status.last_status = SESSION_RUNNING;
|
||||
cwmp->session_status.next_retry = 0;
|
||||
|
||||
if (access(fc_cookies, F_OK) != -1)
|
||||
remove(fc_cookies);
|
||||
CWMP_LOG (INFO,"Start session");
|
||||
if (access(fc_cookies, F_OK) != -1)
|
||||
remove(fc_cookies);
|
||||
CWMP_LOG(INFO, "Start session");
|
||||
|
||||
uci_get_value(UCI_CPE_EXEC_DOWNLOAD, &exec_download);
|
||||
if (strcmp(exec_download, "1") == 0) {
|
||||
CWMP_LOG(INFO, "Firmware downloaded and applied successfully");
|
||||
uci_set_value("cwmp.cpe.exec_download=0");
|
||||
}
|
||||
error = cwmp_schedule_rpc (cwmp,session);
|
||||
CWMP_LOG (INFO,"End session");
|
||||
if (session->error == CWMP_RETRY_SESSION && (!list_empty(&(session->head_event_container)) || (list_empty(&(session->head_event_container)) && cwmp->cwmp_cr_event == 0)) )
|
||||
{
|
||||
run_session_end_func();
|
||||
error = cwmp_move_session_to_session_queue (cwmp, session);
|
||||
CWMP_LOG(INFO,"Retry session, retry count = %d, retry in %ds",cwmp->retry_count_session,cwmp_get_retry_interval(cwmp));
|
||||
retry = true;
|
||||
cwmp->session_status.last_end_time = time(NULL);
|
||||
cwmp->session_status.last_status = SESSION_FAILURE;
|
||||
cwmp->session_status.next_retry = time(NULL) + cwmp_get_retry_interval(cwmp);
|
||||
cwmp->session_status.failure_session++;
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_send));
|
||||
continue;
|
||||
}
|
||||
event_remove_all_event_container(session,RPC_SEND);
|
||||
run_session_end_func();
|
||||
cwmp_session_destructor (session);
|
||||
cwmp->session_send = NULL;
|
||||
cwmp->retry_count_session = 0;
|
||||
cwmp->session_status.last_end_time = time(NULL);
|
||||
cwmp->session_status.last_status = SESSION_SUCCESS;
|
||||
cwmp->session_status.next_retry = 0;
|
||||
cwmp->session_status.success_session++;
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_send));
|
||||
}
|
||||
uci_get_value(UCI_CPE_EXEC_DOWNLOAD, &exec_download);
|
||||
if (strcmp(exec_download, "1") == 0) {
|
||||
CWMP_LOG(INFO, "Firmware downloaded and applied successfully");
|
||||
uci_set_value("cwmp.cpe.exec_download=0");
|
||||
}
|
||||
error = cwmp_schedule_rpc(cwmp, session);
|
||||
CWMP_LOG(INFO, "End session");
|
||||
if (session->error == CWMP_RETRY_SESSION && (!list_empty(&(session->head_event_container)) || (list_empty(&(session->head_event_container)) && cwmp->cwmp_cr_event == 0))) {
|
||||
run_session_end_func();
|
||||
error = cwmp_move_session_to_session_queue(cwmp, session);
|
||||
CWMP_LOG(INFO, "Retry session, retry count = %d, retry in %ds", cwmp->retry_count_session, cwmp_get_retry_interval(cwmp));
|
||||
retry = true;
|
||||
cwmp->session_status.last_end_time = time(NULL);
|
||||
cwmp->session_status.last_status = SESSION_FAILURE;
|
||||
cwmp->session_status.next_retry = time(NULL) + cwmp_get_retry_interval(cwmp);
|
||||
cwmp->session_status.failure_session++;
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_send));
|
||||
continue;
|
||||
}
|
||||
event_remove_all_event_container(session, RPC_SEND);
|
||||
run_session_end_func();
|
||||
cwmp_session_destructor(session);
|
||||
cwmp->session_send = NULL;
|
||||
cwmp->retry_count_session = 0;
|
||||
cwmp->session_status.last_end_time = time(NULL);
|
||||
cwmp->session_status.last_status = SESSION_SUCCESS;
|
||||
cwmp->session_status.next_retry = 0;
|
||||
cwmp->session_status.success_session++;
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_send));
|
||||
}
|
||||
}
|
||||
|
||||
int cwmp_rpc_cpe_handle_message (struct session *session, struct rpc *rpc_cpe)
|
||||
int cwmp_rpc_cpe_handle_message(struct session *session, struct rpc *rpc_cpe)
|
||||
{
|
||||
if (xml_prepare_msg_out(session))
|
||||
return -1;
|
||||
|
|
@ -456,173 +429,172 @@ int cwmp_rpc_cpe_handle_message (struct session *session, struct rpc *rpc_cpe)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void *thread_uloop_run (void *v __attribute__((unused)))
|
||||
void *thread_uloop_run(void *v __attribute__((unused)))
|
||||
{
|
||||
ubus_init(&cwmp_main);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *thread_http_cr_server_listen (void *v __attribute__((unused)))
|
||||
void *thread_http_cr_server_listen(void *v __attribute__((unused)))
|
||||
{
|
||||
http_server_listen();
|
||||
return NULL;
|
||||
http_server_listen();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void signal_handler(int signal_num __attribute__((unused)))
|
||||
{
|
||||
close(cwmp_main.cr_socket_desc);
|
||||
_exit(EXIT_SUCCESS);
|
||||
close(cwmp_main.cr_socket_desc);
|
||||
_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int cwmp_init(int argc, char** argv,struct cwmp *cwmp)
|
||||
int cwmp_init(int argc, char **argv, struct cwmp *cwmp)
|
||||
{
|
||||
int error;
|
||||
struct env env;
|
||||
int error;
|
||||
struct env env;
|
||||
|
||||
memset(&env,0,sizeof(struct env));
|
||||
if ((error = global_env_init (argc, argv, &env)))
|
||||
return error;
|
||||
memset(&env, 0, sizeof(struct env));
|
||||
if ((error = global_env_init(argc, argv, &env)))
|
||||
return error;
|
||||
|
||||
/* Only One instance should run*/
|
||||
cwmp->pid_file = open("/var/run/icwmpd.pid", O_CREAT | O_RDWR, 0666);
|
||||
fcntl(cwmp->pid_file, F_SETFD, fcntl(cwmp->pid_file, F_GETFD) | FD_CLOEXEC);
|
||||
int rc = flock(cwmp->pid_file, LOCK_EX | LOCK_NB);
|
||||
if(rc) {
|
||||
if(EWOULDBLOCK != errno)
|
||||
{
|
||||
char *piderr = "PID file creation failed: Quit the daemon!";
|
||||
fprintf(stderr, "%s\n", piderr);
|
||||
CWMP_LOG(ERROR, "%s",piderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else exit(EXIT_SUCCESS);
|
||||
}
|
||||
/* Only One instance should run*/
|
||||
cwmp->pid_file = open("/var/run/icwmpd.pid", O_CREAT | O_RDWR, 0666);
|
||||
fcntl(cwmp->pid_file, F_SETFD, fcntl(cwmp->pid_file, F_GETFD) | FD_CLOEXEC);
|
||||
int rc = flock(cwmp->pid_file, LOCK_EX | LOCK_NB);
|
||||
if (rc) {
|
||||
if (EWOULDBLOCK != errno) {
|
||||
char *piderr = "PID file creation failed: Quit the daemon!";
|
||||
fprintf(stderr, "%s\n", piderr);
|
||||
CWMP_LOG(ERROR, "%s", piderr);
|
||||
exit(EXIT_FAILURE);
|
||||
} else
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
pthread_mutex_init(&cwmp->mutex_periodic, NULL);
|
||||
pthread_mutex_init(&cwmp->mutex_session_queue, NULL);
|
||||
pthread_mutex_init(&cwmp->mutex_session_send, NULL);
|
||||
memcpy(&(cwmp->env),&env,sizeof(struct env));
|
||||
INIT_LIST_HEAD(&(cwmp->head_session_queue));
|
||||
pthread_mutex_init(&cwmp->mutex_periodic, NULL);
|
||||
pthread_mutex_init(&cwmp->mutex_session_queue, NULL);
|
||||
pthread_mutex_init(&cwmp->mutex_session_send, NULL);
|
||||
memcpy(&(cwmp->env), &env, sizeof(struct env));
|
||||
INIT_LIST_HEAD(&(cwmp->head_session_queue));
|
||||
|
||||
if ((error = global_conf_init(&(cwmp->conf))))
|
||||
return error;
|
||||
if ((error = global_conf_init(&(cwmp->conf))))
|
||||
return error;
|
||||
|
||||
cwmp_get_deviceid(cwmp);
|
||||
return CWMP_OK;
|
||||
cwmp_get_deviceid(cwmp);
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int cwmp_exit(void)
|
||||
{
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
|
||||
FREE(cwmp->deviceid.manufacturer);
|
||||
FREE(cwmp->deviceid.serialnumber);
|
||||
FREE(cwmp->deviceid.productclass);
|
||||
FREE(cwmp->deviceid.oui);
|
||||
FREE(cwmp->deviceid.softwareversion);
|
||||
FREE(cwmp->conf.lw_notification_hostname);
|
||||
FREE(cwmp->conf.ip);
|
||||
FREE(cwmp->conf.ipv6);
|
||||
FREE(cwmp->conf.acsurl);
|
||||
FREE(cwmp->conf.acs_userid);
|
||||
FREE(cwmp->conf.acs_passwd);
|
||||
FREE(cwmp->conf.interface);
|
||||
FREE(cwmp->conf.cpe_userid);
|
||||
FREE(cwmp->conf.cpe_passwd);
|
||||
FREE(cwmp->conf.ubus_socket);
|
||||
bkp_tree_clean();
|
||||
ubus_exit();
|
||||
uloop_done();
|
||||
return 0;
|
||||
FREE(cwmp->deviceid.manufacturer);
|
||||
FREE(cwmp->deviceid.serialnumber);
|
||||
FREE(cwmp->deviceid.productclass);
|
||||
FREE(cwmp->deviceid.oui);
|
||||
FREE(cwmp->deviceid.softwareversion);
|
||||
FREE(cwmp->conf.lw_notification_hostname);
|
||||
FREE(cwmp->conf.ip);
|
||||
FREE(cwmp->conf.ipv6);
|
||||
FREE(cwmp->conf.acsurl);
|
||||
FREE(cwmp->conf.acs_userid);
|
||||
FREE(cwmp->conf.acs_passwd);
|
||||
FREE(cwmp->conf.interface);
|
||||
FREE(cwmp->conf.cpe_userid);
|
||||
FREE(cwmp->conf.cpe_passwd);
|
||||
FREE(cwmp->conf.ubus_socket);
|
||||
bkp_tree_clean();
|
||||
ubus_exit();
|
||||
uloop_done();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
int error;
|
||||
pthread_t periodic_event_thread;
|
||||
pthread_t scheduleInform_thread;
|
||||
pthread_t change_du_state_thread;
|
||||
pthread_t download_thread;
|
||||
pthread_t schedule_download_thread;
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
int error;
|
||||
pthread_t periodic_event_thread;
|
||||
pthread_t scheduleInform_thread;
|
||||
pthread_t change_du_state_thread;
|
||||
pthread_t download_thread;
|
||||
pthread_t schedule_download_thread;
|
||||
pthread_t apply_schedule_download_thread;
|
||||
pthread_t upload_thread;
|
||||
pthread_t ubus_thread;
|
||||
pthread_t http_cr_server_thread;
|
||||
pthread_t periodic_check_notify;
|
||||
pthread_t upload_thread;
|
||||
pthread_t ubus_thread;
|
||||
pthread_t http_cr_server_thread;
|
||||
pthread_t periodic_check_notify;
|
||||
|
||||
struct sigaction act = {0};
|
||||
struct sigaction act = { 0 };
|
||||
|
||||
if ((error = cwmp_init(argc, argv, cwmp)))
|
||||
return error;
|
||||
if ((error = cwmp_init(argc, argv, cwmp)))
|
||||
return error;
|
||||
|
||||
CWMP_LOG(INFO,"STARTING ICWMP with PID :%d", getpid());
|
||||
cwmp->start_time = time(NULL);
|
||||
CWMP_LOG(INFO, "STARTING ICWMP with PID :%d", getpid());
|
||||
cwmp->start_time = time(NULL);
|
||||
|
||||
if ((error = cwmp_init_backup_session(cwmp, NULL, ALL)))
|
||||
return error;
|
||||
if ((error = cwmp_init_backup_session(cwmp, NULL, ALL)))
|
||||
return error;
|
||||
|
||||
if ((error = cwmp_root_cause_events(cwmp)))
|
||||
return error;
|
||||
if ((error = cwmp_root_cause_events(cwmp)))
|
||||
return error;
|
||||
|
||||
http_server_init();
|
||||
http_server_init();
|
||||
|
||||
act.sa_handler = signal_handler;
|
||||
sigaction(SIGINT, &act, 0);
|
||||
sigaction(SIGTERM, &act, 0);
|
||||
|
||||
error = pthread_create(&http_cr_server_thread, NULL, &thread_http_cr_server_listen, NULL);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR,"Error when creating the http connection request server thread!");
|
||||
act.sa_handler = signal_handler;
|
||||
sigaction(SIGINT, &act, 0);
|
||||
sigaction(SIGTERM, &act, 0);
|
||||
|
||||
error = pthread_create(&ubus_thread, NULL, &thread_uloop_run, NULL);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR,"Error when creating the ubus thread!");
|
||||
error = pthread_create(&http_cr_server_thread, NULL, &thread_http_cr_server_listen, NULL);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR, "Error when creating the http connection request server thread!");
|
||||
|
||||
error = pthread_create(&periodic_event_thread, NULL, &thread_event_periodic, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR,"Error when creating the periodic event thread!");
|
||||
error = pthread_create(&ubus_thread, NULL, &thread_uloop_run, NULL);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR, "Error when creating the ubus thread!");
|
||||
|
||||
error = pthread_create(&periodic_check_notify, NULL, &thread_periodic_check_notify, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR,"Error when creating the download thread!");
|
||||
error = pthread_create(&scheduleInform_thread, NULL, &thread_cwmp_rpc_cpe_scheduleInform, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR,"Error when creating the scheduled inform thread!");
|
||||
error = pthread_create(&periodic_event_thread, NULL, &thread_event_periodic, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR, "Error when creating the periodic event thread!");
|
||||
|
||||
error = pthread_create(&download_thread, NULL, &thread_cwmp_rpc_cpe_download, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR,"Error when creating the download thread!");
|
||||
error = pthread_create(&periodic_check_notify, NULL, &thread_periodic_check_notify, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR, "Error when creating the download thread!");
|
||||
error = pthread_create(&scheduleInform_thread, NULL, &thread_cwmp_rpc_cpe_scheduleInform, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR, "Error when creating the scheduled inform thread!");
|
||||
|
||||
error = pthread_create(&change_du_state_thread, NULL, &thread_cwmp_rpc_cpe_change_du_state, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR,"Error when creating the state change thread!");
|
||||
error = pthread_create(&download_thread, NULL, &thread_cwmp_rpc_cpe_download, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR, "Error when creating the download thread!");
|
||||
|
||||
error = pthread_create(&change_du_state_thread, NULL, &thread_cwmp_rpc_cpe_change_du_state, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR, "Error when creating the state change thread!");
|
||||
|
||||
error = pthread_create(&schedule_download_thread, NULL, &thread_cwmp_rpc_cpe_schedule_download, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR,"Error when creating the schedule download thread!");
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR, "Error when creating the schedule download thread!");
|
||||
|
||||
error = pthread_create(&apply_schedule_download_thread, NULL, &thread_cwmp_rpc_cpe_apply_schedule_download, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR,"Error when creating the schedule download thread!");
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR, "Error when creating the schedule download thread!");
|
||||
|
||||
error = pthread_create(&upload_thread, NULL, &thread_cwmp_rpc_cpe_upload, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR,"Error when creating the download thread!");
|
||||
error = pthread_create(&upload_thread, NULL, &thread_cwmp_rpc_cpe_upload, (void *)cwmp);
|
||||
if (error < 0)
|
||||
CWMP_LOG(ERROR, "Error when creating the download thread!");
|
||||
|
||||
cwmp_schedule_session(cwmp);
|
||||
cwmp_schedule_session(cwmp);
|
||||
|
||||
pthread_join(ubus_thread, NULL);
|
||||
pthread_join(periodic_event_thread, NULL);
|
||||
pthread_join(scheduleInform_thread, NULL);
|
||||
pthread_join(download_thread, NULL);
|
||||
pthread_join(upload_thread, NULL);
|
||||
pthread_join(schedule_download_thread, NULL);
|
||||
pthread_join(ubus_thread, NULL);
|
||||
pthread_join(periodic_event_thread, NULL);
|
||||
pthread_join(scheduleInform_thread, NULL);
|
||||
pthread_join(download_thread, NULL);
|
||||
pthread_join(upload_thread, NULL);
|
||||
pthread_join(schedule_download_thread, NULL);
|
||||
pthread_join(apply_schedule_download_thread, NULL);
|
||||
pthread_join(change_du_state_thread, NULL);
|
||||
pthread_join(http_cr_server_thread, NULL);
|
||||
pthread_join(change_du_state_thread, NULL);
|
||||
pthread_join(http_cr_server_thread, NULL);
|
||||
|
||||
CWMP_LOG(INFO,"EXIT ICWMP");
|
||||
cwmp_exit();
|
||||
return CWMP_OK;
|
||||
CWMP_LOG(INFO, "EXIT ICWMP");
|
||||
cwmp_exit();
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
|
|
|||
71
cwmp_json.c
71
cwmp_json.c
|
|
@ -27,13 +27,11 @@ static int cwmp_json_message_parse(char **policy, int size, char **tb, char *msg
|
|||
json_object *obj;
|
||||
|
||||
jshn_obj = json_tokener_parse(msg);
|
||||
if (jshn_obj == NULL || json_object_get_type(jshn_obj) != json_type_object)
|
||||
{
|
||||
if (jshn_obj == NULL || json_object_get_type(jshn_obj) != json_type_object) {
|
||||
jshn_obj = NULL;
|
||||
return -1;
|
||||
}
|
||||
for (i=0; i<size; i++)
|
||||
{
|
||||
for (i = 0; i < size; i++) {
|
||||
json_object_object_get_ex(jshn_obj, policy[i], &obj);
|
||||
if (obj == NULL || json_object_get_type(obj) != json_type_string)
|
||||
continue;
|
||||
|
|
@ -44,31 +42,29 @@ static int cwmp_json_message_parse(char **policy, int size, char **tb, char *msg
|
|||
|
||||
static inline void cwmp_json_message_delete()
|
||||
{
|
||||
if(jshn_obj != NULL)
|
||||
if (jshn_obj != NULL)
|
||||
json_object_put(jshn_obj);
|
||||
}
|
||||
enum download_fault {
|
||||
enum download_fault
|
||||
{
|
||||
DOWNLOAD_FAULT,
|
||||
__DOWNLOAD_MAX
|
||||
};
|
||||
|
||||
char *download_fault_policy[] = {
|
||||
[DOWNLOAD_FAULT] = "fault_code"
|
||||
};
|
||||
char *download_fault_policy[] = {[DOWNLOAD_FAULT] = "fault_code" };
|
||||
|
||||
int
|
||||
cwmp_handle_downloadFault(char *msg)
|
||||
int cwmp_handle_downloadFault(char *msg)
|
||||
{
|
||||
char *tb[__DOWNLOAD_MAX] = {0};
|
||||
char *tb[__DOWNLOAD_MAX] = { 0 };
|
||||
|
||||
cwmp_json_message_parse(download_fault_policy, ARRAYSIZEOF(download_fault_policy), tb, msg);
|
||||
|
||||
if (!tb[DOWNLOAD_FAULT])
|
||||
goto error;
|
||||
|
||||
DD(INFO,"triggered handle download fault %s", tb[DOWNLOAD_FAULT]);
|
||||
DD(INFO, "triggered handle download fault %s", tb[DOWNLOAD_FAULT]);
|
||||
|
||||
external_downloadFaultResp (tb[DOWNLOAD_FAULT]);
|
||||
external_downloadFaultResp(tb[DOWNLOAD_FAULT]);
|
||||
|
||||
cwmp_json_message_delete();
|
||||
return 0;
|
||||
|
|
@ -78,27 +74,26 @@ error:
|
|||
return -1;
|
||||
}
|
||||
|
||||
enum upload_fault {
|
||||
enum upload_fault
|
||||
{
|
||||
UPLOAD_FAULT,
|
||||
__UPLOAD_MAX
|
||||
};
|
||||
|
||||
char *upload_fault_policy[] = {
|
||||
[UPLOAD_FAULT] = "fault_code"
|
||||
};
|
||||
char *upload_fault_policy[] = {[UPLOAD_FAULT] = "fault_code" };
|
||||
|
||||
int cwmp_handle_uploadFault(char *msg)
|
||||
{
|
||||
char *tb[__UPLOAD_MAX] = {0};
|
||||
char *tb[__UPLOAD_MAX] = { 0 };
|
||||
|
||||
cwmp_json_message_parse(upload_fault_policy, ARRAYSIZEOF(upload_fault_policy), tb, msg);
|
||||
|
||||
if (!tb[UPLOAD_FAULT])
|
||||
goto error;
|
||||
|
||||
DD(INFO,"triggered handle upload fault %s", tb[UPLOAD_FAULT]);
|
||||
DD(INFO, "triggered handle upload fault %s", tb[UPLOAD_FAULT]);
|
||||
|
||||
external_uploadFaultResp (tb[UPLOAD_FAULT]);
|
||||
external_uploadFaultResp(tb[UPLOAD_FAULT]);
|
||||
|
||||
cwmp_json_message_delete();
|
||||
return 0;
|
||||
|
|
@ -108,7 +103,8 @@ error:
|
|||
return -1;
|
||||
}
|
||||
|
||||
enum dustatechange_fault {
|
||||
enum dustatechange_fault
|
||||
{
|
||||
DUState_Change_FAULT,
|
||||
DUState_Change_VERSION,
|
||||
DUState_Change_NAME,
|
||||
|
|
@ -117,26 +113,20 @@ enum dustatechange_fault {
|
|||
__DUSTATE_MAX
|
||||
};
|
||||
|
||||
char *dustatechange_fault_policy[] = {
|
||||
[DUState_Change_FAULT] = "fault_code",
|
||||
[DUState_Change_VERSION] = "package_version",
|
||||
[DUState_Change_NAME] = "package_name",
|
||||
[DUState_Change_UUID] = "package_uuid",
|
||||
[DUState_Change_ENV] = "package_env"
|
||||
};
|
||||
char *dustatechange_fault_policy[] = {[DUState_Change_FAULT] = "fault_code", [DUState_Change_VERSION] = "package_version", [DUState_Change_NAME] = "package_name", [DUState_Change_UUID] = "package_uuid", [DUState_Change_ENV] = "package_env" };
|
||||
|
||||
int cwmp_handle_dustate_changeFault(char *msg)
|
||||
{
|
||||
char *tb[__DUSTATE_MAX] = {0};
|
||||
char *tb[__DUSTATE_MAX] = { 0 };
|
||||
|
||||
cwmp_json_message_parse(dustatechange_fault_policy, ARRAYSIZEOF(dustatechange_fault_policy), tb, msg);
|
||||
|
||||
if (!tb[DUState_Change_FAULT])
|
||||
goto error;
|
||||
|
||||
DD(INFO,"triggered handle dustate_change fault:%s version:%s name:%s", tb[DUState_Change_FAULT], tb[DUState_Change_VERSION], tb[DUState_Change_NAME], tb[DUState_Change_UUID], tb[DUState_Change_ENV]);
|
||||
DD(INFO, "triggered handle dustate_change fault:%s version:%s name:%s", tb[DUState_Change_FAULT], tb[DUState_Change_VERSION], tb[DUState_Change_NAME], tb[DUState_Change_UUID], tb[DUState_Change_ENV]);
|
||||
|
||||
external_du_change_stateFaultResp (tb[DUState_Change_FAULT], tb[DUState_Change_VERSION], tb[DUState_Change_NAME], tb[DUState_Change_UUID], tb[DUState_Change_ENV]);
|
||||
external_du_change_stateFaultResp(tb[DUState_Change_FAULT], tb[DUState_Change_VERSION], tb[DUState_Change_NAME], tb[DUState_Change_UUID], tb[DUState_Change_ENV]);
|
||||
|
||||
cwmp_json_message_delete();
|
||||
return 0;
|
||||
|
|
@ -146,27 +136,26 @@ error:
|
|||
return -1;
|
||||
}
|
||||
|
||||
enum uninstall_fault {
|
||||
enum uninstall_fault
|
||||
{
|
||||
UNINSTALL_FAULT,
|
||||
__UNINSTALL_MAX
|
||||
};
|
||||
|
||||
char *uninstall_fault_policy[] = {
|
||||
[UNINSTALL_FAULT] = "fault_code"
|
||||
};
|
||||
char *uninstall_fault_policy[] = {[UNINSTALL_FAULT] = "fault_code" };
|
||||
|
||||
int cwmp_handle_uninstallFault(char *msg)
|
||||
{
|
||||
char *tb[__UNINSTALL_MAX] = {0};
|
||||
char *tb[__UNINSTALL_MAX] = { 0 };
|
||||
|
||||
cwmp_json_message_parse(uninstall_fault_policy, ARRAYSIZEOF(uninstall_fault_policy), tb, msg);
|
||||
|
||||
if (!tb[UNINSTALL_FAULT])
|
||||
goto error;
|
||||
|
||||
DD(INFO,"triggered handle upload fault %s", tb[UNINSTALL_FAULT]);
|
||||
DD(INFO, "triggered handle upload fault %s", tb[UNINSTALL_FAULT]);
|
||||
|
||||
external_uninstallFaultResp (tb[UNINSTALL_FAULT]);
|
||||
external_uninstallFaultResp(tb[UNINSTALL_FAULT]);
|
||||
|
||||
cwmp_json_message_delete();
|
||||
return 0;
|
||||
|
|
@ -219,11 +208,11 @@ void cwmp_json_fprintf(FILE *fp, int argc, struct cwmp_json_arg cwmp_arg[])
|
|||
json_object_put(json_obj_out);
|
||||
}
|
||||
|
||||
void cwmp_json_get_string(json_object *obj, char* key, char** value)
|
||||
void cwmp_json_get_string(json_object *obj, char *key, char **value)
|
||||
{
|
||||
json_object *key_obj = NULL;
|
||||
json_object_object_get_ex(obj, key, &key_obj);
|
||||
*value = strdup(key_obj?(char*)json_object_get_string(key_obj):"");
|
||||
*value = strdup(key_obj ? (char *)json_object_get_string(key_obj) : "");
|
||||
if (key_obj) {
|
||||
json_object_put(key_obj);
|
||||
key_obj = NULL;
|
||||
|
|
|
|||
18
cwmp_time.c
18
cwmp_time.c
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
#include <time.h>
|
||||
|
||||
char local_time[32] = {0};
|
||||
char local_time[32] = { 0 };
|
||||
|
||||
char * mix_get_time_of(time_t t_time)
|
||||
char *mix_get_time_of(time_t t_time)
|
||||
{
|
||||
struct tm *t_tm;
|
||||
|
||||
|
|
@ -19,9 +19,9 @@ char * mix_get_time_of(time_t t_time)
|
|||
if (t_tm == NULL)
|
||||
return NULL;
|
||||
|
||||
if(strftime(local_time, sizeof(local_time), "%FT%T%z", t_tm) == 0)
|
||||
if (strftime(local_time, sizeof(local_time), "%FT%T%z", t_tm) == 0)
|
||||
return NULL;
|
||||
|
||||
|
||||
local_time[25] = local_time[24];
|
||||
local_time[24] = local_time[23];
|
||||
local_time[22] = ':';
|
||||
|
|
@ -30,10 +30,10 @@ char * mix_get_time_of(time_t t_time)
|
|||
return local_time;
|
||||
}
|
||||
|
||||
char * mix_get_time(void)
|
||||
char *mix_get_time(void)
|
||||
{
|
||||
time_t t_time;
|
||||
t_time = time(NULL);
|
||||
mix_get_time_of(t_time);
|
||||
return local_time;
|
||||
time_t t_time;
|
||||
t_time = time(NULL);
|
||||
mix_get_time_of(t_time);
|
||||
return local_time;
|
||||
}
|
||||
|
|
|
|||
523
cwmp_uci.c
523
cwmp_uci.c
|
|
@ -13,11 +13,11 @@
|
|||
#include "cwmp_uci.h"
|
||||
|
||||
struct uci_paths uci_save_conf_paths[] = {
|
||||
[UCI_STANDARD_CONFIG] ={"/etc/config","/tmp/.uci"},
|
||||
[UCI_DB_CONFIG] = {"/lib/db/config", NULL},
|
||||
[UCI_BOARD_DB_CONFIG] = {"/etc/board-db/config", NULL},
|
||||
[UCI_VARSTATE_CONFIG] = {NULL, "/var/state"},
|
||||
[UCI_BBFDM_CONFIG] = {"/etc/bbfdm", "/tmp/.bbfdm"}
|
||||
[UCI_STANDARD_CONFIG] = { "/etc/config", "/tmp/.uci" },
|
||||
[UCI_DB_CONFIG] = { "/lib/db/config", NULL },
|
||||
[UCI_BOARD_DB_CONFIG] = { "/etc/board-db/config", NULL },
|
||||
[UCI_VARSTATE_CONFIG] = { NULL, "/var/state" },
|
||||
[UCI_BBFDM_CONFIG] = { "/etc/bbfdm", "/tmp/.bbfdm" }
|
||||
};
|
||||
|
||||
struct uci_context *cwmp_uci_ctx = ((void *)0);
|
||||
|
|
@ -77,7 +77,7 @@ int cwmp_uci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *pack
|
|||
goto lookup;
|
||||
}
|
||||
ptr->section = section;
|
||||
if (ptr->section && !cwmp_check_section_name(ptr->section , true))
|
||||
if (ptr->section && !cwmp_check_section_name(ptr->section, true))
|
||||
ptr->flags |= UCI_LOOKUP_EXTENDED;
|
||||
|
||||
/*option*/
|
||||
|
|
@ -98,11 +98,12 @@ lookup:
|
|||
char *cwmp_uci_list_to_string(struct uci_list *list, char *delimitor)
|
||||
{
|
||||
struct uci_element *e = NULL;
|
||||
char val[512] = {0};
|
||||
char val[512] = { 0 };
|
||||
int del_len = strlen(delimitor);
|
||||
|
||||
if (list) {
|
||||
uci_foreach_element(list, e) {
|
||||
uci_foreach_element(list, e)
|
||||
{
|
||||
int len = strlen(val);
|
||||
if (len != 0) {
|
||||
memcpy(val + len, delimitor, del_len);
|
||||
|
|
@ -118,10 +119,9 @@ char *cwmp_uci_list_to_string(struct uci_list *list, char *delimitor)
|
|||
|
||||
int cwmp_uci_get_option_value_string(char *package, char *section, char *option, int uci_type, char **value)
|
||||
{
|
||||
struct uci_ptr ptr = {0};
|
||||
struct uci_ptr ptr = { 0 };
|
||||
cwmp_uci_init(uci_type);
|
||||
|
||||
|
||||
if (cwmp_uci_lookup_ptr(cwmp_uci_ctx, &ptr, package, section, option, NULL) != UCI_OK) {
|
||||
*value = "";
|
||||
cwmp_uci_ctx = NULL;
|
||||
|
|
@ -140,14 +140,13 @@ int cwmp_uci_get_option_value_string(char *package, char *section, char *option,
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
char* cwmp_db_get_value_string(char *package, char *section, char *option)
|
||||
char *cwmp_db_get_value_string(char *package, char *section, char *option)
|
||||
{
|
||||
cwmp_uci_ctx = uci_alloc_context();
|
||||
|
||||
struct uci_option *o = NULL;
|
||||
struct uci_element *e;
|
||||
struct uci_ptr ptr = {0};
|
||||
struct uci_ptr ptr = { 0 };
|
||||
|
||||
cwmp_uci_ctx->confdir = LIB_DB_CONFIG;
|
||||
|
||||
|
|
@ -155,15 +154,14 @@ char* cwmp_db_get_value_string(char *package, char *section, char *option)
|
|||
return "";
|
||||
|
||||
e = ptr.last;
|
||||
switch(e->type) {
|
||||
case UCI_TYPE_OPTION:
|
||||
o = ptr.o;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (e->type) {
|
||||
case UCI_TYPE_OPTION:
|
||||
o = ptr.o;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (o)
|
||||
return o->v.string ? o->v.string : "";
|
||||
else {
|
||||
|
|
@ -174,9 +172,9 @@ char* cwmp_db_get_value_string(char *package, char *section, char *option)
|
|||
int cwmp_uci_get_option_value_list(char *package, char *section, char *option, struct list_head *list)
|
||||
{
|
||||
struct uci_element *e;
|
||||
struct uci_ptr ptr = {0};
|
||||
struct uci_ptr ptr = { 0 };
|
||||
cwmp_uci_ctx = uci_alloc_context();
|
||||
struct config_uci_list *uci_list_elem;
|
||||
struct config_uci_list *uci_list_elem;
|
||||
int size = 0;
|
||||
//*value = NULL;
|
||||
|
||||
|
|
@ -190,234 +188,210 @@ int cwmp_uci_get_option_value_list(char *package, char *section, char *option, s
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (ptr.o->type == UCI_TYPE_LIST) {
|
||||
uci_foreach_element(&ptr.o->v.list, e)
|
||||
{
|
||||
if((e != NULL)&&(e->name))
|
||||
{
|
||||
uci_list_elem = calloc(1,sizeof(struct config_uci_list));
|
||||
if(uci_list_elem == NULL)
|
||||
{
|
||||
uci_free_context(cwmp_uci_ctx);
|
||||
return -1;
|
||||
}
|
||||
uci_list_elem->value = strdup(e->name);
|
||||
list_add_tail (&(uci_list_elem->list), list);
|
||||
size++;
|
||||
}
|
||||
else
|
||||
{
|
||||
uci_free_context(cwmp_uci_ctx);
|
||||
return size;
|
||||
}
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_LIST) {
|
||||
uci_foreach_element(&ptr.o->v.list, e)
|
||||
{
|
||||
if ((e != NULL) && (e->name)) {
|
||||
uci_list_elem = calloc(1, sizeof(struct config_uci_list));
|
||||
if (uci_list_elem == NULL) {
|
||||
uci_free_context(cwmp_uci_ctx);
|
||||
return -1;
|
||||
}
|
||||
uci_list_elem->value = strdup(e->name);
|
||||
list_add_tail(&(uci_list_elem->list), list);
|
||||
size++;
|
||||
} else {
|
||||
uci_free_context(cwmp_uci_ctx);
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uci_free_context(cwmp_uci_ctx);
|
||||
uci_free_context(cwmp_uci_ctx);
|
||||
return size;
|
||||
}
|
||||
|
||||
int uci_get_list_value(char *cmd, struct list_head *list)
|
||||
{
|
||||
struct uci_ptr ptr;
|
||||
struct uci_context *c = uci_alloc_context();
|
||||
struct uci_element *e;
|
||||
struct config_uci_list *uci_list_elem;
|
||||
char *s,*t;
|
||||
int size = 0;
|
||||
struct uci_ptr ptr;
|
||||
struct uci_context *c = uci_alloc_context();
|
||||
struct uci_element *e;
|
||||
struct config_uci_list *uci_list_elem;
|
||||
char *s, *t;
|
||||
int size = 0;
|
||||
|
||||
if (!c)
|
||||
{
|
||||
CWMP_LOG(ERROR, "Out of memory");
|
||||
return size;
|
||||
}
|
||||
if (!c) {
|
||||
CWMP_LOG(ERROR, "Out of memory");
|
||||
return size;
|
||||
}
|
||||
|
||||
s = strdup(cmd);
|
||||
t = s;
|
||||
if (uci_lookup_ptr(c, &ptr, s, true) != UCI_OK)
|
||||
{
|
||||
CWMP_LOG(ERROR, "Invalid uci command path: %s",cmd);
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return size;
|
||||
}
|
||||
s = strdup(cmd);
|
||||
t = s;
|
||||
if (uci_lookup_ptr(c, &ptr, s, true) != UCI_OK) {
|
||||
CWMP_LOG(ERROR, "Invalid uci command path: %s", cmd);
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return size;
|
||||
}
|
||||
|
||||
if(ptr.o == NULL)
|
||||
{
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return size;
|
||||
}
|
||||
if (ptr.o == NULL) {
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return size;
|
||||
}
|
||||
|
||||
if(ptr.o->type == UCI_TYPE_LIST)
|
||||
{
|
||||
uci_foreach_element(&ptr.o->v.list, e)
|
||||
{
|
||||
if((e != NULL)&&(e->name))
|
||||
{
|
||||
uci_list_elem = calloc(1,sizeof(struct config_uci_list));
|
||||
if(uci_list_elem == NULL)
|
||||
{
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return CWMP_GEN_ERR;
|
||||
}
|
||||
uci_list_elem->value = strdup(e->name);
|
||||
list_add_tail (&(uci_list_elem->list), list);
|
||||
size++;
|
||||
}
|
||||
else
|
||||
{
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return size;
|
||||
if (ptr.o->type == UCI_TYPE_LIST) {
|
||||
uci_foreach_element(&ptr.o->v.list, e)
|
||||
{
|
||||
if ((e != NULL) && (e->name)) {
|
||||
uci_list_elem = calloc(1, sizeof(struct config_uci_list));
|
||||
if (uci_list_elem == NULL) {
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return CWMP_GEN_ERR;
|
||||
}
|
||||
uci_list_elem->value = strdup(e->name);
|
||||
list_add_tail(&(uci_list_elem->list), list);
|
||||
size++;
|
||||
} else {
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return size;
|
||||
}
|
||||
|
||||
int uci_get_value_common(char *cmd,char **value,bool state)
|
||||
int uci_get_value_common(char *cmd, char **value, bool state)
|
||||
{
|
||||
struct uci_ptr ptr;
|
||||
struct uci_context *c = uci_alloc_context();
|
||||
char *s,*t;
|
||||
char state_path[32];
|
||||
struct uci_ptr ptr;
|
||||
struct uci_context *c = uci_alloc_context();
|
||||
char *s, *t;
|
||||
char state_path[32];
|
||||
|
||||
*value = NULL;
|
||||
if (!c)
|
||||
{
|
||||
CWMP_LOG(ERROR, "Out of memory");
|
||||
return CWMP_GEN_ERR;
|
||||
}
|
||||
if (state)
|
||||
{
|
||||
strcpy(state_path,VARSTATE_CONFIG);
|
||||
uci_add_delta_path(c, c->savedir);
|
||||
uci_set_savedir(c, state_path);
|
||||
}
|
||||
s = strdup(cmd);
|
||||
t = s;
|
||||
if (uci_lookup_ptr(c, &ptr, s, true) != UCI_OK)
|
||||
{
|
||||
CWMP_LOG(ERROR, "Error occurred in uci %s get %s",state?"state":"config",cmd);
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return CWMP_GEN_ERR;
|
||||
}
|
||||
free(t);
|
||||
if(ptr.flags & UCI_LOOKUP_COMPLETE)
|
||||
{
|
||||
if (ptr.o==NULL || ptr.o->v.string==NULL)
|
||||
{
|
||||
CWMP_LOG(INFO, "%s not found or empty value",cmd);
|
||||
uci_free_context(c);
|
||||
return CWMP_OK;
|
||||
}
|
||||
*value = strdup(ptr.o->v.string);
|
||||
}
|
||||
uci_free_context(c);
|
||||
return CWMP_OK;
|
||||
*value = NULL;
|
||||
if (!c) {
|
||||
CWMP_LOG(ERROR, "Out of memory");
|
||||
return CWMP_GEN_ERR;
|
||||
}
|
||||
if (state) {
|
||||
strcpy(state_path, VARSTATE_CONFIG);
|
||||
uci_add_delta_path(c, c->savedir);
|
||||
uci_set_savedir(c, state_path);
|
||||
}
|
||||
s = strdup(cmd);
|
||||
t = s;
|
||||
if (uci_lookup_ptr(c, &ptr, s, true) != UCI_OK) {
|
||||
CWMP_LOG(ERROR, "Error occurred in uci %s get %s", state ? "state" : "config", cmd);
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return CWMP_GEN_ERR;
|
||||
}
|
||||
free(t);
|
||||
if (ptr.flags & UCI_LOOKUP_COMPLETE) {
|
||||
if (ptr.o == NULL || ptr.o->v.string == NULL) {
|
||||
CWMP_LOG(INFO, "%s not found or empty value", cmd);
|
||||
uci_free_context(c);
|
||||
return CWMP_OK;
|
||||
}
|
||||
*value = strdup(ptr.o->v.string);
|
||||
}
|
||||
uci_free_context(c);
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int uci_get_state_value(char *cmd,char **value)
|
||||
int uci_get_state_value(char *cmd, char **value)
|
||||
{
|
||||
int error;
|
||||
error = uci_get_value_common (cmd,value,true);
|
||||
return error;
|
||||
int error;
|
||||
error = uci_get_value_common(cmd, value, true);
|
||||
return error;
|
||||
}
|
||||
|
||||
int uci_get_value(char *cmd,char **value)
|
||||
int uci_get_value(char *cmd, char **value)
|
||||
{
|
||||
int error;
|
||||
error = uci_get_value_common (cmd,value,false);
|
||||
return error;
|
||||
int error;
|
||||
error = uci_get_value_common(cmd, value, false);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int uci_action_value_common(char *cmd, uci_config_action action)
|
||||
{
|
||||
int ret = UCI_OK;
|
||||
char *s,*t;
|
||||
struct uci_context *c = uci_alloc_context();
|
||||
struct uci_ptr ptr;
|
||||
char state_path[32];
|
||||
int ret = UCI_OK;
|
||||
char *s, *t;
|
||||
struct uci_context *c = uci_alloc_context();
|
||||
struct uci_ptr ptr;
|
||||
char state_path[32];
|
||||
|
||||
if (!c)
|
||||
{
|
||||
CWMP_LOG(ERROR, "Out of memory");
|
||||
return CWMP_GEN_ERR;
|
||||
}
|
||||
if (!c) {
|
||||
CWMP_LOG(ERROR, "Out of memory");
|
||||
return CWMP_GEN_ERR;
|
||||
}
|
||||
|
||||
if (action == CWMP_CMD_SET_STATE)
|
||||
{
|
||||
strcpy(state_path,VARSTATE_CONFIG);
|
||||
uci_add_delta_path(c, c->savedir);
|
||||
uci_set_savedir(c, state_path);
|
||||
}
|
||||
if (action == CWMP_CMD_SET_STATE) {
|
||||
strcpy(state_path, VARSTATE_CONFIG);
|
||||
uci_add_delta_path(c, c->savedir);
|
||||
uci_set_savedir(c, state_path);
|
||||
}
|
||||
|
||||
s = strdup(cmd);
|
||||
t = s;
|
||||
s = strdup(cmd);
|
||||
t = s;
|
||||
|
||||
if (uci_lookup_ptr(c, &ptr, s, true) != UCI_OK)
|
||||
{
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return CWMP_GEN_ERR;
|
||||
}
|
||||
switch (action)
|
||||
{
|
||||
case CWMP_CMD_SET:
|
||||
case CWMP_CMD_SET_STATE:
|
||||
ret = uci_set(c, &ptr);
|
||||
break;
|
||||
case CWMP_CMD_DEL:
|
||||
ret = uci_delete(c, &ptr);
|
||||
break;
|
||||
case CWMP_CMD_ADD_LIST:
|
||||
ret = uci_add_list(c, &ptr);
|
||||
break;
|
||||
}
|
||||
if (ret == UCI_OK)
|
||||
{
|
||||
ret = uci_save(c, ptr.p);
|
||||
}
|
||||
else
|
||||
{
|
||||
CWMP_LOG(ERROR, "UCI %s %s not succeed %s",action==CWMP_CMD_SET_STATE?"state":"config",action==CWMP_CMD_DEL?"delete":"set",cmd);
|
||||
}
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return CWMP_OK;
|
||||
if (uci_lookup_ptr(c, &ptr, s, true) != UCI_OK) {
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return CWMP_GEN_ERR;
|
||||
}
|
||||
switch (action) {
|
||||
case CWMP_CMD_SET:
|
||||
case CWMP_CMD_SET_STATE:
|
||||
ret = uci_set(c, &ptr);
|
||||
break;
|
||||
case CWMP_CMD_DEL:
|
||||
ret = uci_delete(c, &ptr);
|
||||
break;
|
||||
case CWMP_CMD_ADD_LIST:
|
||||
ret = uci_add_list(c, &ptr);
|
||||
break;
|
||||
}
|
||||
if (ret == UCI_OK) {
|
||||
ret = uci_save(c, ptr.p);
|
||||
} else {
|
||||
CWMP_LOG(ERROR, "UCI %s %s not succeed %s", action == CWMP_CMD_SET_STATE ? "state" : "config", action == CWMP_CMD_DEL ? "delete" : "set", cmd);
|
||||
}
|
||||
free(t);
|
||||
uci_free_context(c);
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int uci_delete_value(char *cmd)
|
||||
{
|
||||
int error;
|
||||
error = uci_action_value_common (cmd,CWMP_CMD_DEL);
|
||||
return error;
|
||||
int error;
|
||||
error = uci_action_value_common(cmd, CWMP_CMD_DEL);
|
||||
return error;
|
||||
}
|
||||
|
||||
int uci_set_value(char *cmd)
|
||||
{
|
||||
int error;
|
||||
error = uci_action_value_common (cmd,CWMP_CMD_SET);
|
||||
return error;
|
||||
int error;
|
||||
error = uci_action_value_common(cmd, CWMP_CMD_SET);
|
||||
return error;
|
||||
}
|
||||
|
||||
int uci_set_state_value(char *cmd)
|
||||
{
|
||||
int error;
|
||||
error = uci_action_value_common (cmd,CWMP_CMD_SET_STATE);
|
||||
return error;
|
||||
int error;
|
||||
error = uci_action_value_common(cmd, CWMP_CMD_SET_STATE);
|
||||
return error;
|
||||
}
|
||||
|
||||
int uci_add_list_value(char *cmd)
|
||||
{
|
||||
int error;
|
||||
error = uci_action_value_common (cmd,CWMP_CMD_ADD_LIST);
|
||||
return error;
|
||||
int error;
|
||||
error = uci_action_value_common(cmd, CWMP_CMD_ADD_LIST);
|
||||
return error;
|
||||
}
|
||||
|
||||
static inline void cwmp_uci_list_insert(struct uci_list *list, struct uci_list *ptr)
|
||||
|
|
@ -428,11 +402,7 @@ static inline void cwmp_uci_list_insert(struct uci_list *list, struct uci_list *
|
|||
list->next = ptr;
|
||||
}
|
||||
|
||||
static inline void cwmp_uci_list_add(struct uci_list *head, struct uci_list *ptr)
|
||||
{
|
||||
cwmp_uci_list_insert(head->prev, ptr);
|
||||
}
|
||||
|
||||
static inline void cwmp_uci_list_add(struct uci_list *head, struct uci_list *ptr) { cwmp_uci_list_insert(head->prev, ptr); }
|
||||
int cwmp_uci_get_value_by_section_string(struct uci_section *s, char *option, char **value)
|
||||
{
|
||||
struct uci_element *e;
|
||||
|
|
@ -441,7 +411,8 @@ int cwmp_uci_get_value_by_section_string(struct uci_section *s, char *option, ch
|
|||
if (s == NULL || option == NULL)
|
||||
goto not_found;
|
||||
|
||||
uci_foreach_element(&s->options, e) {
|
||||
uci_foreach_element(&s->options, e)
|
||||
{
|
||||
o = (uci_to_option(e));
|
||||
if (!strcmp(o->e.name, option)) {
|
||||
if (o->type == UCI_TYPE_LIST) {
|
||||
|
|
@ -453,9 +424,9 @@ int cwmp_uci_get_value_by_section_string(struct uci_section *s, char *option, ch
|
|||
}
|
||||
}
|
||||
|
||||
not_found:
|
||||
*value = "";
|
||||
return -1;
|
||||
not_found:
|
||||
*value = "";
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline void cwmp_uci_list_init(struct uci_list *ptr)
|
||||
|
|
@ -476,42 +447,43 @@ int cwmp_uci_get_value_by_section_list(struct uci_section *s, char *option, stru
|
|||
if (s == NULL || option == NULL)
|
||||
return -1;
|
||||
|
||||
uci_foreach_element(&s->options, e) {
|
||||
uci_foreach_element(&s->options, e)
|
||||
{
|
||||
o = (uci_to_option(e));
|
||||
if (strcmp(o->e.name, option) == 0) {
|
||||
switch(o->type) {
|
||||
case UCI_TYPE_LIST:
|
||||
*value = &o->v.list;
|
||||
switch (o->type) {
|
||||
case UCI_TYPE_LIST:
|
||||
*value = &o->v.list;
|
||||
return 0;
|
||||
case UCI_TYPE_STRING:
|
||||
if (!o->v.string || (o->v.string)[0] == '\0')
|
||||
return 0;
|
||||
case UCI_TYPE_STRING:
|
||||
if (!o->v.string || (o->v.string)[0] == '\0')
|
||||
return 0;
|
||||
list = calloc(1, sizeof(struct uci_list));
|
||||
cwmp_uci_list_init(list);
|
||||
dup = strdup(o->v.string);
|
||||
pch = strtok_r(dup, " ", &spch);
|
||||
while (pch != NULL) {
|
||||
e = calloc(1, sizeof(struct uci_element));
|
||||
e->name = pch;
|
||||
cwmp_uci_list_add(list, &e->list);
|
||||
pch = strtok_r(NULL, " ", &spch);
|
||||
}
|
||||
*value = list;
|
||||
return 0;
|
||||
default:
|
||||
return -1;
|
||||
list = calloc(1, sizeof(struct uci_list));
|
||||
cwmp_uci_list_init(list);
|
||||
dup = strdup(o->v.string);
|
||||
pch = strtok_r(dup, " ", &spch);
|
||||
while (pch != NULL) {
|
||||
e = calloc(1, sizeof(struct uci_element));
|
||||
e->name = pch;
|
||||
cwmp_uci_list_add(list, &e->list);
|
||||
pch = strtok_r(NULL, " ", &spch);
|
||||
}
|
||||
*value = list;
|
||||
return 0;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
struct uci_section *cwmp_uci_walk_section (char *package, char *stype, void *arg1, void *arg2, int cmp , int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk)
|
||||
struct uci_section *cwmp_uci_walk_section(char *package, char *stype, void *arg1, void *arg2, int cmp, int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk)
|
||||
{
|
||||
struct uci_section *s = NULL;
|
||||
struct uci_element *e, *m;
|
||||
char *value, *dup, *pch, *spch;
|
||||
struct uci_list *list_value, *list_section;
|
||||
struct uci_ptr ptr = {0};
|
||||
struct uci_ptr ptr = { 0 };
|
||||
|
||||
if (walk == CWMP_GET_FIRST_SECTION) {
|
||||
if (cwmp_uci_lookup_ptr(cwmp_uci_ctx, &ptr, package, NULL, NULL, NULL) != UCI_OK)
|
||||
|
|
@ -524,50 +496,51 @@ struct uci_section *cwmp_uci_walk_section (char *package, char *stype, void *arg
|
|||
e = list_to_element(prev_section->e.list.next);
|
||||
}
|
||||
|
||||
while(&e->list != list_section) {
|
||||
while (&e->list != list_section) {
|
||||
s = uci_to_section(e);
|
||||
if (strcmp(s->type, stype) == 0) {
|
||||
switch(cmp) {
|
||||
case CWMP_CMP_SECTION:
|
||||
switch (cmp) {
|
||||
case CWMP_CMP_SECTION:
|
||||
goto end;
|
||||
case CWMP_CMP_OPTION_EQUAL:
|
||||
cwmp_uci_get_value_by_section_string(s, (char *)arg1, &value);
|
||||
if (strcmp(value, (char *)arg2) == 0)
|
||||
goto end;
|
||||
case CWMP_CMP_OPTION_EQUAL:
|
||||
cwmp_uci_get_value_by_section_string(s, (char *)arg1, &value);
|
||||
if (strcmp(value, (char *)arg2) == 0)
|
||||
break;
|
||||
case CWMP_CMP_OPTION_CONTAINING:
|
||||
cwmp_uci_get_value_by_section_string(s, (char *)arg1, &value);
|
||||
if (strstr(value, (char *)arg2))
|
||||
goto end;
|
||||
break;
|
||||
case CWMP_CMP_OPTION_CONT_WORD:
|
||||
cwmp_uci_get_value_by_section_string(s, (char *)arg1, &value);
|
||||
dup = strdup(value);
|
||||
pch = strtok_r(dup, " ", &spch);
|
||||
while (pch != NULL) {
|
||||
if (strcmp((char *)arg2, pch) == 0) {
|
||||
FREE(dup);
|
||||
goto end;
|
||||
break;
|
||||
case CWMP_CMP_OPTION_CONTAINING:
|
||||
cwmp_uci_get_value_by_section_string(s, (char *)arg1, &value);
|
||||
if (strstr(value, (char *)arg2))
|
||||
goto end;
|
||||
break;
|
||||
case CWMP_CMP_OPTION_CONT_WORD:
|
||||
cwmp_uci_get_value_by_section_string(s, (char *)arg1, &value);
|
||||
dup = strdup(value);
|
||||
pch = strtok_r(dup, " ", &spch);
|
||||
while (pch != NULL) {
|
||||
if (strcmp((char *)arg2, pch) == 0) {
|
||||
FREE(dup);
|
||||
}
|
||||
pch = strtok_r(NULL, " ", &spch);
|
||||
}
|
||||
FREE(dup);
|
||||
break;
|
||||
case CWMP_CMP_LIST_CONTAINING:
|
||||
cwmp_uci_get_value_by_section_list(s, (char *)arg1, &list_value);
|
||||
if (list_value != NULL) {
|
||||
uci_foreach_element(list_value, m)
|
||||
{
|
||||
if (strcmp(m->name, (char *)arg2) == 0)
|
||||
goto end;
|
||||
}
|
||||
pch = strtok_r(NULL, " ", &spch);
|
||||
}
|
||||
FREE(dup);
|
||||
break;
|
||||
case CWMP_CMP_LIST_CONTAINING:
|
||||
cwmp_uci_get_value_by_section_list(s, (char *)arg1, &list_value);
|
||||
if (list_value != NULL) {
|
||||
uci_foreach_element(list_value, m) {
|
||||
if (strcmp(m->name, (char *)arg2) == 0)
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CWMP_CMP_FILTER_FUNC:
|
||||
if (filter(s, arg1) == 0)
|
||||
goto end;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CWMP_CMP_FILTER_FUNC:
|
||||
if (filter(s, arg1) == 0)
|
||||
goto end;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
e = list_to_element(e->list.next);
|
||||
|
|
|
|||
108
cwmp_zlib.c
108
cwmp_zlib.c
|
|
@ -22,31 +22,29 @@
|
|||
#define windowBits 15
|
||||
#define GZIP_ENCODING 16
|
||||
|
||||
static int strm_init (z_stream * strm, int type)
|
||||
static int strm_init(z_stream *strm, int type)
|
||||
{
|
||||
int error = 0;
|
||||
strm->zalloc = Z_NULL;
|
||||
strm->zfree = Z_NULL;
|
||||
strm->opaque = Z_NULL;
|
||||
switch (type) {
|
||||
case COMP_GZIP:
|
||||
error = deflateInit2(strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
|
||||
windowBits | GZIP_ENCODING, 8,
|
||||
Z_DEFAULT_STRATEGY);
|
||||
break;
|
||||
case COMP_DEFLATE:
|
||||
error = deflateInit(strm, Z_DEFAULT_COMPRESSION);
|
||||
break;
|
||||
}
|
||||
if (error < 0) {
|
||||
CWMP_LOG(ERROR, "error in zlib compress in deflateInit2");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
int error = 0;
|
||||
strm->zalloc = Z_NULL;
|
||||
strm->zfree = Z_NULL;
|
||||
strm->opaque = Z_NULL;
|
||||
switch (type) {
|
||||
case COMP_GZIP:
|
||||
error = deflateInit2(strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, windowBits | GZIP_ENCODING, 8, Z_DEFAULT_STRATEGY);
|
||||
break;
|
||||
case COMP_DEFLATE:
|
||||
error = deflateInit(strm, Z_DEFAULT_COMPRESSION);
|
||||
break;
|
||||
}
|
||||
if (error < 0) {
|
||||
CWMP_LOG(ERROR, "error in zlib compress in deflateInit2");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Example text to print out. */
|
||||
int zlib_compress (char *message, unsigned char **zmsg, int *zlen, int type)
|
||||
int zlib_compress(char *message, unsigned char **zmsg, int *zlen, int type)
|
||||
{
|
||||
#if 0 /*test*/
|
||||
static int testi = 1;
|
||||
|
|
@ -54,45 +52,43 @@ int zlib_compress (char *message, unsigned char **zmsg, int *zlen, int type)
|
|||
sprintf(tests, "/tmp/test%d", testi++);
|
||||
FILE *fp = fopen (tests, "wb");
|
||||
#endif /*test*/
|
||||
unsigned char out[CHUNK];
|
||||
z_stream strm={0};
|
||||
unsigned char *rzmsg = NULL;
|
||||
*zmsg = NULL;
|
||||
*zlen=0;
|
||||
if (strm_init(&strm, type))
|
||||
return -1;
|
||||
strm.next_in = (unsigned char *) message;
|
||||
strm.avail_in = strlen(message);
|
||||
do {
|
||||
int have;
|
||||
strm.avail_out = CHUNK;
|
||||
strm.next_out = out;
|
||||
int error = deflate(&strm, Z_FINISH);
|
||||
if (error < 0) {
|
||||
CWMP_LOG(ERROR, "error in zlib compress in deflate");
|
||||
return -1;
|
||||
}
|
||||
unsigned char out[CHUNK];
|
||||
z_stream strm = { 0 };
|
||||
unsigned char *rzmsg = NULL;
|
||||
*zmsg = NULL;
|
||||
*zlen = 0;
|
||||
if (strm_init(&strm, type))
|
||||
return -1;
|
||||
strm.next_in = (unsigned char *)message;
|
||||
strm.avail_in = strlen(message);
|
||||
do {
|
||||
int have;
|
||||
strm.avail_out = CHUNK;
|
||||
strm.next_out = out;
|
||||
int error = deflate(&strm, Z_FINISH);
|
||||
if (error < 0) {
|
||||
CWMP_LOG(ERROR, "error in zlib compress in deflate");
|
||||
return -1;
|
||||
}
|
||||
|
||||
have = CHUNK - strm.avail_out;
|
||||
int ozlen = *zlen;
|
||||
*zlen += have;
|
||||
rzmsg = realloc(*zmsg, *zlen * sizeof(unsigned char));
|
||||
if (rzmsg!=NULL) {
|
||||
*zmsg = rzmsg;
|
||||
}
|
||||
else {
|
||||
free(*zmsg);
|
||||
CWMP_LOG(ERROR, "Error (re)allocating memory");
|
||||
return -1;
|
||||
}
|
||||
memcpy(*zmsg + ozlen, out, have);
|
||||
}
|
||||
while (strm.avail_out == 0);
|
||||
deflateEnd(&strm);
|
||||
have = CHUNK - strm.avail_out;
|
||||
int ozlen = *zlen;
|
||||
*zlen += have;
|
||||
rzmsg = realloc(*zmsg, *zlen * sizeof(unsigned char));
|
||||
if (rzmsg != NULL) {
|
||||
*zmsg = rzmsg;
|
||||
} else {
|
||||
free(*zmsg);
|
||||
CWMP_LOG(ERROR, "Error (re)allocating memory");
|
||||
return -1;
|
||||
}
|
||||
memcpy(*zmsg + ozlen, out, have);
|
||||
} while (strm.avail_out == 0);
|
||||
deflateEnd(&strm);
|
||||
#if 0 /*test*/
|
||||
fwrite(*zmsg, sizeof (char), *zlen, fp);
|
||||
fclose(fp);
|
||||
#endif /*test*/
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,21 +25,21 @@ json_object *actual_list_notify = NULL;
|
|||
*/
|
||||
int cwmp_transaction_start(char *app)
|
||||
{
|
||||
CWMP_LOG (INFO,"Starting transaction ...");
|
||||
CWMP_LOG(INFO, "Starting transaction ...");
|
||||
json_object *transaction_ret = NULL, *status_obj = NULL, *transaction_id_obj = NULL;
|
||||
int e = cwmp_ubus_call("usp.raw", "transaction_start", CWMP_UBUS_ARGS{{"app", {.str_val=app}, UBUS_String}}, 1, &transaction_ret);
|
||||
if (e!=0) {
|
||||
CWMP_LOG (INFO,"Transaction start failed: Ubus err code: %d", e);
|
||||
int e = cwmp_ubus_call("usp.raw", "transaction_start", CWMP_UBUS_ARGS{ { "app", {.str_val = app }, UBUS_String } }, 1, &transaction_ret);
|
||||
if (e != 0) {
|
||||
CWMP_LOG(INFO, "Transaction start failed: Ubus err code: %d", e);
|
||||
return 0;
|
||||
}
|
||||
json_object_object_get_ex(transaction_ret, "status", &status_obj);
|
||||
if (strcmp((char*)json_object_get_string(status_obj), "true") != 0) {
|
||||
if (strcmp((char *)json_object_get_string(status_obj), "true") != 0) {
|
||||
json_object *error = NULL;
|
||||
json_object_object_get_ex(transaction_ret, "error", &error);
|
||||
FREE_JSON(status_obj)
|
||||
FREE_JSON(error)
|
||||
FREE_JSON(transaction_ret)
|
||||
CWMP_LOG (INFO,"Transaction start failed: %s\n",(char*)json_object_get_string(error));
|
||||
CWMP_LOG(INFO, "Transaction start failed: %s\n", (char *)json_object_get_string(error));
|
||||
return 0;
|
||||
}
|
||||
FREE_JSON(status_obj)
|
||||
|
|
@ -48,7 +48,7 @@ int cwmp_transaction_start(char *app)
|
|||
FREE_JSON(transaction_ret)
|
||||
return 0;
|
||||
}
|
||||
transaction_id = atoi((char*)json_object_get_string(transaction_id_obj));
|
||||
transaction_id = atoi((char *)json_object_get_string(transaction_id_obj));
|
||||
FREE_JSON(transaction_id_obj)
|
||||
FREE_JSON(transaction_ret)
|
||||
return 1;
|
||||
|
|
@ -56,18 +56,18 @@ int cwmp_transaction_start(char *app)
|
|||
|
||||
int cwmp_transaction_commit()
|
||||
{
|
||||
CWMP_LOG (INFO,"Transaction Commit ...");
|
||||
CWMP_LOG(INFO, "Transaction Commit ...");
|
||||
json_object *transaction_ret = NULL, *status_obj = NULL;
|
||||
int e = cwmp_ubus_call("usp.raw", "transaction_commit", CWMP_UBUS_ARGS{{"transaction_id", {.int_val=transaction_id}, UBUS_Integer}}, 1, &transaction_ret);
|
||||
if (e!=0) {
|
||||
CWMP_LOG (INFO,"Transaction commit failed: Ubus err code: %d", e)
|
||||
int e = cwmp_ubus_call("usp.raw", "transaction_commit", CWMP_UBUS_ARGS{ { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 1, &transaction_ret);
|
||||
if (e != 0) {
|
||||
CWMP_LOG(INFO, "Transaction commit failed: Ubus err code: %d", e)
|
||||
return 0;
|
||||
}
|
||||
json_object_object_get_ex(transaction_ret, "status", &status_obj);
|
||||
if (strcmp((char*)json_object_get_string(status_obj), "true") != 0) {
|
||||
if (strcmp((char *)json_object_get_string(status_obj), "true") != 0) {
|
||||
json_object *error = NULL;
|
||||
json_object_object_get_ex(transaction_ret, "error", &error);
|
||||
CWMP_LOG (INFO,"Transaction commit failed: %s\n",(char*)json_object_get_string(error));
|
||||
CWMP_LOG(INFO, "Transaction commit failed: %s\n", (char *)json_object_get_string(error));
|
||||
transaction_id = 0;
|
||||
FREE_JSON(status_obj)
|
||||
FREE_JSON(error)
|
||||
|
|
@ -82,18 +82,18 @@ int cwmp_transaction_commit()
|
|||
|
||||
int cwmp_transaction_abort()
|
||||
{
|
||||
CWMP_LOG (INFO,"Transaction Abort ...");
|
||||
CWMP_LOG(INFO, "Transaction Abort ...");
|
||||
json_object *transaction_ret = NULL, *status_obj = NULL;
|
||||
int e = cwmp_ubus_call("usp.raw", "transaction_abort", CWMP_UBUS_ARGS{{"transaction_id", {.int_val=transaction_id}, UBUS_Integer}}, 1, &transaction_ret);
|
||||
if (e!=0) {
|
||||
CWMP_LOG (INFO,"Transaction abort failed: Ubus err code: %d", e);
|
||||
int e = cwmp_ubus_call("usp.raw", "transaction_abort", CWMP_UBUS_ARGS{ { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 1, &transaction_ret);
|
||||
if (e != 0) {
|
||||
CWMP_LOG(INFO, "Transaction abort failed: Ubus err code: %d", e);
|
||||
return 0;
|
||||
}
|
||||
json_object_object_get_ex(transaction_ret, "status", &status_obj);
|
||||
if (strcmp((char*)json_object_get_string(status_obj), "true") != 0) {
|
||||
if (strcmp((char *)json_object_get_string(status_obj), "true") != 0) {
|
||||
json_object *error = NULL;
|
||||
json_object_object_get_ex(transaction_ret, "error", &error);
|
||||
CWMP_LOG (INFO,"Transaction abort failed: %s\n",(char*)json_object_get_string(error));
|
||||
CWMP_LOG(INFO, "Transaction abort failed: %s\n", (char *)json_object_get_string(error));
|
||||
FREE_JSON(status_obj)
|
||||
FREE_JSON(error)
|
||||
FREE_JSON(transaction_ret)
|
||||
|
|
@ -107,14 +107,14 @@ int cwmp_transaction_abort()
|
|||
int cwmp_transaction_status()
|
||||
{
|
||||
json_object *status_obj = NULL, *transaction_ret = NULL;
|
||||
int e = cwmp_ubus_call("usp.raw", "transaction_status", CWMP_UBUS_ARGS{{"transaction_id", {.int_val=transaction_id}, UBUS_Integer}}, 1, &transaction_ret);
|
||||
if (e!=0) {
|
||||
CWMP_LOG (INFO,"Transaction status failed: Ubus err code: %d", e);
|
||||
int e = cwmp_ubus_call("usp.raw", "transaction_status", CWMP_UBUS_ARGS{ { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 1, &transaction_ret);
|
||||
if (e != 0) {
|
||||
CWMP_LOG(INFO, "Transaction status failed: Ubus err code: %d", e);
|
||||
return 0;
|
||||
}
|
||||
json_object_object_get_ex(transaction_ret, "status", &status_obj);
|
||||
if (!status_obj || strcmp((char*)json_object_get_string(status_obj), "on-going") != 0) {
|
||||
CWMP_LOG (INFO,"Transaction with id: %d is not available anymore\n",transaction_id);
|
||||
if (!status_obj || strcmp((char *)json_object_get_string(status_obj), "on-going") != 0) {
|
||||
CWMP_LOG(INFO, "Transaction with id: %d is not available anymore\n", transaction_id);
|
||||
FREE_JSON(status_obj)
|
||||
FREE_JSON(transaction_ret)
|
||||
return 0;
|
||||
|
|
@ -126,11 +126,11 @@ int cwmp_transaction_status()
|
|||
/*
|
||||
* RPC Methods Functions
|
||||
*/
|
||||
char* cwmp_get_parameter_values(char *parameter_name, json_object **parameters)
|
||||
char *cwmp_get_parameter_values(char *parameter_name, json_object **parameters)
|
||||
{
|
||||
json_object *params_obj = NULL;
|
||||
char *fault = NULL;
|
||||
int e = cwmp_ubus_call("usp.raw", "get", CWMP_UBUS_ARGS{{"path", {.str_val=!parameter_name||parameter_name[0]=='\0'?DM_ROOT_OBJ:parameter_name}, UBUS_String}}, 1, ¶ms_obj);
|
||||
int e = cwmp_ubus_call("usp.raw", "get", CWMP_UBUS_ARGS{ { "path", {.str_val = !parameter_name || parameter_name[0] == '\0' ? DM_ROOT_OBJ : parameter_name }, UBUS_String } }, 1, ¶ms_obj);
|
||||
if (e < 0 || params_obj == NULL) {
|
||||
*parameters = NULL;
|
||||
return "9002";
|
||||
|
|
@ -139,7 +139,7 @@ char* cwmp_get_parameter_values(char *parameter_name, json_object **parameters)
|
|||
json_object_object_get_ex(params_obj, "fault", &fault_code);
|
||||
if (fault_code != NULL) {
|
||||
*parameters = NULL;
|
||||
fault = strdup((char*)json_object_get_string(fault_code));
|
||||
fault = strdup((char *)json_object_get_string(fault_code));
|
||||
FREE_JSON(fault_code)
|
||||
FREE_JSON(params_obj)
|
||||
return fault;
|
||||
|
|
@ -148,11 +148,12 @@ char* cwmp_get_parameter_values(char *parameter_name, json_object **parameters)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char* cwmp_set_parameter_value(char* parameter_name, char* value, char* parameter_key, int* flag)
|
||||
char *cwmp_set_parameter_value(char *parameter_name, char *value, char *parameter_key, int *flag)
|
||||
{
|
||||
json_object *set_res;
|
||||
char *fault = NULL;
|
||||
int e = cwmp_ubus_call("usp.raw", "set", CWMP_UBUS_ARGS{{"path", {.str_val=parameter_name}, UBUS_String},{"value", {.str_val=value}, UBUS_String}, {"key", {.str_val=parameter_key}, UBUS_String},{"transaction_id", {.int_val=transaction_id}, UBUS_Integer}}, 3, &set_res);
|
||||
int e = cwmp_ubus_call("usp.raw", "set", CWMP_UBUS_ARGS{ { "path", {.str_val = parameter_name }, UBUS_String }, { "value", {.str_val = value }, UBUS_String }, { "key", {.str_val = parameter_key }, UBUS_String }, { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 3,
|
||||
&set_res);
|
||||
|
||||
if (e < 0 || set_res == NULL)
|
||||
return "9002";
|
||||
|
|
@ -160,7 +161,7 @@ char* cwmp_set_parameter_value(char* parameter_name, char* value, char* paramete
|
|||
json_object *fault_code = NULL;
|
||||
json_object_object_get_ex(set_res, "fault", &fault_code);
|
||||
if (fault_code != NULL) {
|
||||
fault = strdup((char*)json_object_get_string(fault_code));
|
||||
fault = strdup((char *)json_object_get_string(fault_code));
|
||||
FREE_JSON(fault_code)
|
||||
FREE_JSON(set_res)
|
||||
return fault;
|
||||
|
|
@ -169,11 +170,11 @@ char* cwmp_set_parameter_value(char* parameter_name, char* value, char* paramete
|
|||
json_object_object_get_ex(set_res, "status", &status);
|
||||
char *status_str = NULL;
|
||||
if (status) {
|
||||
status_str = (char*)json_object_get_string(status);
|
||||
if (status_str && strcmp(status_str,"true") == 0) {
|
||||
status_str = (char *)json_object_get_string(status);
|
||||
if (status_str && strcmp(status_str, "true") == 0) {
|
||||
json_object *flag_obj = NULL;
|
||||
json_object_object_get_ex(set_res, "flag", &flag_obj);
|
||||
*flag = flag_obj?atoi((char*)json_object_get_string(flag_obj)):0;
|
||||
*flag = flag_obj ? atoi((char *)json_object_get_string(flag_obj)) : 0;
|
||||
FREE_JSON(flag_obj)
|
||||
FREE_JSON(status)
|
||||
FREE_JSON(set_res)
|
||||
|
|
@ -188,19 +189,19 @@ char* cwmp_set_parameter_value(char* parameter_name, char* value, char* paramete
|
|||
json_object *param_obj = json_object_array_get_idx(parameters, 0);
|
||||
|
||||
json_object_object_get_ex(param_obj, "status", &status);
|
||||
status_str = (char*)json_object_get_string(status);
|
||||
if (status_str && strcmp(status_str,"false") == 0) {
|
||||
status_str = (char *)json_object_get_string(status);
|
||||
if (status_str && strcmp(status_str, "false") == 0) {
|
||||
json_object *fault = NULL;
|
||||
json_object_object_get_ex(param_obj, "fault", &fault);
|
||||
return (char*)json_object_get_string(fault);
|
||||
return (char *)json_object_get_string(fault);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* cwmp_set_multiple_parameters_values(struct list_head parameters_values_list, char* parameter_key, int* flag, json_object **faults_array)
|
||||
char *cwmp_set_multiple_parameters_values(struct list_head parameters_values_list, char *parameter_key, int *flag, json_object **faults_array)
|
||||
{
|
||||
json_object *set_res;
|
||||
int e = cwmp_ubus_call("usp.raw", "setm_values", CWMP_UBUS_ARGS{{"pv_tuple", {.param_value_list=¶meters_values_list}, UBUS_List_Param}, {"key", {.str_val=parameter_key}, UBUS_String},{"transaction_id", {.int_val=transaction_id}, UBUS_Integer}}, 3, &set_res);
|
||||
int e = cwmp_ubus_call("usp.raw", "setm_values", CWMP_UBUS_ARGS{ { "pv_tuple", {.param_value_list = ¶meters_values_list }, UBUS_List_Param }, { "key", {.str_val = parameter_key }, UBUS_String }, { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 3, &set_res);
|
||||
if (e < 0 || set_res == NULL)
|
||||
return "9002";
|
||||
|
||||
|
|
@ -208,16 +209,16 @@ char* cwmp_set_multiple_parameters_values(struct list_head parameters_values_lis
|
|||
json_object_object_get_ex(set_res, "status", &status);
|
||||
char *status_str = NULL;
|
||||
if (status) {
|
||||
status_str = (char*)json_object_get_string(status);
|
||||
if (status_str && strcmp(status_str,"true") == 0) {
|
||||
status_str = (char *)json_object_get_string(status);
|
||||
if (status_str && strcmp(status_str, "true") == 0) {
|
||||
json_object *flag_obj = NULL;
|
||||
json_object_object_get_ex(set_res, "flag", &flag_obj);
|
||||
*flag = flag_obj?atoi((char*)json_object_get_string(flag_obj)):0;
|
||||
*flag = flag_obj ? atoi((char *)json_object_get_string(flag_obj)) : 0;
|
||||
free(status_str);
|
||||
status_str = NULL;
|
||||
return NULL;
|
||||
}
|
||||
if(status_str) {
|
||||
if (status_str) {
|
||||
free(status_str);
|
||||
status_str = NULL;
|
||||
}
|
||||
|
|
@ -226,18 +227,18 @@ char* cwmp_set_multiple_parameters_values(struct list_head parameters_values_lis
|
|||
return "Fault";
|
||||
}
|
||||
|
||||
char* cwmp_add_object(char* object_name, char* key, char **instance)
|
||||
char *cwmp_add_object(char *object_name, char *key, char **instance)
|
||||
{
|
||||
json_object *add_res;
|
||||
char *err = NULL;
|
||||
|
||||
int e = cwmp_ubus_call("usp.raw", "add_object", CWMP_UBUS_ARGS{{"path", {.str_val=object_name}, UBUS_String},{"key", {.str_val=key}, UBUS_String},{"transaction_id", {.int_val=transaction_id}, UBUS_Integer}}, 3, &add_res);
|
||||
int e = cwmp_ubus_call("usp.raw", "add_object", CWMP_UBUS_ARGS{ { "path", {.str_val = object_name }, UBUS_String }, { "key", {.str_val = key }, UBUS_String }, { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 3, &add_res);
|
||||
if (e < 0 || add_res == NULL)
|
||||
return "9002";
|
||||
json_object *fault_code = NULL;
|
||||
json_object_object_get_ex(add_res, "fault", &fault_code);
|
||||
if (fault_code != NULL) {
|
||||
err = strdup((char*)json_object_get_string(fault_code));
|
||||
err = strdup((char *)json_object_get_string(fault_code));
|
||||
FREE_JSON(fault_code)
|
||||
FREE_JSON(add_res)
|
||||
return err;
|
||||
|
|
@ -253,7 +254,7 @@ char* cwmp_add_object(char* object_name, char* key, char **instance)
|
|||
json_object *fault = NULL;
|
||||
json_object_object_get_ex(param_obj, "fault", &fault);
|
||||
if (fault) {
|
||||
err = strdup((char*)json_object_get_string(fault));
|
||||
err = strdup((char *)json_object_get_string(fault));
|
||||
FREE_JSON(parameters)
|
||||
FREE_JSON(fault)
|
||||
FREE_JSON(add_res)
|
||||
|
|
@ -267,18 +268,18 @@ char* cwmp_add_object(char* object_name, char* key, char **instance)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char* cwmp_delete_object(char* object_name, char* key)
|
||||
char *cwmp_delete_object(char *object_name, char *key)
|
||||
{
|
||||
json_object *del_res;
|
||||
char *err = NULL;
|
||||
|
||||
int e = cwmp_ubus_call("usp.raw", "del_object", CWMP_UBUS_ARGS{{"path", {.str_val=object_name}, UBUS_String},{"key", {.str_val=key}, UBUS_String},{"transaction_id", {.int_val=transaction_id}, UBUS_Integer}}, 3, &del_res);
|
||||
int e = cwmp_ubus_call("usp.raw", "del_object", CWMP_UBUS_ARGS{ { "path", {.str_val = object_name }, UBUS_String }, { "key", {.str_val = key }, UBUS_String }, { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 3, &del_res);
|
||||
if (e < 0 || del_res == NULL)
|
||||
return "9002";
|
||||
json_object *fault_code = NULL;
|
||||
json_object_object_get_ex(del_res, "fault", &fault_code);
|
||||
if (fault_code != NULL) {
|
||||
err = strdup((char*)json_object_get_string(fault_code));
|
||||
err = strdup((char *)json_object_get_string(fault_code));
|
||||
FREE_JSON(fault_code)
|
||||
FREE_JSON(del_res)
|
||||
return err;
|
||||
|
|
@ -288,11 +289,11 @@ char* cwmp_delete_object(char* object_name, char* key)
|
|||
json_object *param_obj = json_object_array_get_idx(parameters, 0);
|
||||
json_object *status = NULL;
|
||||
json_object_object_get_ex(param_obj, "status", &status);
|
||||
char *status_str = (char*)json_object_get_string(status);
|
||||
if (status_str && strcmp(status_str,"false") == 0) {
|
||||
char *status_str = (char *)json_object_get_string(status);
|
||||
if (status_str && strcmp(status_str, "false") == 0) {
|
||||
json_object *fault = NULL;
|
||||
json_object_object_get_ex(param_obj, "fault", &fault);
|
||||
err = strdup((char*)json_object_get_string(fault));
|
||||
err = strdup((char *)json_object_get_string(fault));
|
||||
FREE_JSON(fault)
|
||||
FREE_JSON(status)
|
||||
FREE_JSON(del_res)
|
||||
|
|
@ -303,19 +304,19 @@ char* cwmp_delete_object(char* object_name, char* key)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char* cwmp_get_parameter_names(char* object_name, bool next_level, json_object **parameters)
|
||||
char *cwmp_get_parameter_names(char *object_name, bool next_level, json_object **parameters)
|
||||
{
|
||||
json_object *get_name_res;
|
||||
char *err = NULL;
|
||||
|
||||
int e = cwmp_ubus_call("usp.raw", "object_names", CWMP_UBUS_ARGS{{"path", {.str_val=object_name}, UBUS_String},{"next-level", {.bool_val=next_level}, UBUS_Bool}}, 2, &get_name_res);
|
||||
int e = cwmp_ubus_call("usp.raw", "object_names", CWMP_UBUS_ARGS{ { "path", {.str_val = object_name }, UBUS_String }, { "next-level", {.bool_val = next_level }, UBUS_Bool } }, 2, &get_name_res);
|
||||
if (e < 0 || get_name_res == NULL)
|
||||
return "9002";
|
||||
json_object *fault_code = NULL;
|
||||
json_object_object_get_ex(get_name_res, "fault", &fault_code);
|
||||
if (fault_code != NULL) {
|
||||
*parameters = NULL;
|
||||
err = strdup((char*)json_object_get_string(fault_code));
|
||||
err = strdup((char *)json_object_get_string(fault_code));
|
||||
FREE_JSON(fault_code)
|
||||
FREE_JSON(get_name_res)
|
||||
return err;
|
||||
|
|
@ -324,29 +325,30 @@ char* cwmp_get_parameter_names(char* object_name, bool next_level, json_object *
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char* cwmp_get_parameter_attributes(char* parameter_name, json_object **parameters)
|
||||
char *cwmp_get_parameter_attributes(char *parameter_name, json_object **parameters)
|
||||
{
|
||||
json_object *get_attributes_res = NULL;
|
||||
char *err = NULL;
|
||||
|
||||
int e = cwmp_ubus_call("usp.raw", "getm_attributes", CWMP_UBUS_ARGS{{"paths", {.array_value={{.str_value=!parameter_name||parameter_name[0]=='\0'?DM_ROOT_OBJ:parameter_name}}}, UBUS_Array_Str}}, 1, &get_attributes_res);
|
||||
if ( e < 0 || get_attributes_res == NULL)
|
||||
int e = cwmp_ubus_call("usp.raw", "getm_attributes", CWMP_UBUS_ARGS{ { "paths", {.array_value = { {.str_value = !parameter_name || parameter_name[0] == '\0' ? DM_ROOT_OBJ : parameter_name } } }, UBUS_Array_Str } }, 1, &get_attributes_res);
|
||||
if (e < 0 || get_attributes_res == NULL)
|
||||
return "9002";
|
||||
json_object *fault_code = NULL;
|
||||
json_object_object_get_ex(get_attributes_res, "fault", &fault_code);
|
||||
if (fault_code != NULL) {
|
||||
*parameters = NULL;
|
||||
err = strdup((char*)json_object_get_string(fault_code));
|
||||
err = strdup((char *)json_object_get_string(fault_code));
|
||||
FREE_JSON(fault_code)
|
||||
FREE_JSON(get_attributes_res)
|
||||
return err;
|
||||
}
|
||||
json_object_object_get_ex(get_attributes_res, "parameters", parameters);
|
||||
json_object *fault = NULL, *param_obj = NULL;
|
||||
foreach_jsonobj_in_array(param_obj, *parameters) {
|
||||
foreach_jsonobj_in_array(param_obj, *parameters)
|
||||
{
|
||||
json_object_object_get_ex(param_obj, "fault", &fault);
|
||||
if (fault) {
|
||||
err = strdup((char*)json_object_get_string(fault));
|
||||
err = strdup((char *)json_object_get_string(fault));
|
||||
FREE_JSON(fault)
|
||||
FREE_JSON(*parameters)
|
||||
break;
|
||||
|
|
@ -356,11 +358,13 @@ char* cwmp_get_parameter_attributes(char* parameter_name, json_object **paramete
|
|||
return err;
|
||||
}
|
||||
|
||||
char* cwmp_set_parameter_attributes(char* parameter_name, char* notification)
|
||||
char *cwmp_set_parameter_attributes(char *parameter_name, char *notification)
|
||||
{
|
||||
json_object *set_attribute_res;
|
||||
char *err = NULL;
|
||||
int e = cwmp_ubus_call("usp.raw", "setm_attributes", CWMP_UBUS_ARGS{{"paths", {.array_value={{.param_value={"path",parameter_name}},{.param_value={"notify-type",notification}},{.param_value={"notify","1"}}}}, UBUS_Array_Obj},{"transaction_id", {.int_val=transaction_id}, UBUS_Integer}}, 2, &set_attribute_res);
|
||||
int e = cwmp_ubus_call("usp.raw", "setm_attributes",
|
||||
CWMP_UBUS_ARGS{ { "paths", {.array_value = { {.param_value = { "path", parameter_name } }, {.param_value = { "notify-type", notification } }, {.param_value = { "notify", "1" } } } }, UBUS_Array_Obj }, { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } },
|
||||
2, &set_attribute_res);
|
||||
if (e < 0 || set_attribute_res == NULL)
|
||||
return "9002";
|
||||
json_object *parameters = NULL;
|
||||
|
|
@ -369,7 +373,7 @@ char* cwmp_set_parameter_attributes(char* parameter_name, char* notification)
|
|||
json_object *fault_code = NULL;
|
||||
json_object_object_get_ex(param_obj, "fault", &fault_code);
|
||||
if (fault_code != NULL) {
|
||||
err = strdup((char*)json_object_get_string(fault_code));
|
||||
err = strdup((char *)json_object_get_string(fault_code));
|
||||
FREE_JSON(fault_code)
|
||||
}
|
||||
FREE_JSON(param_obj)
|
||||
|
|
@ -384,28 +388,27 @@ char* cwmp_set_parameter_attributes(char* parameter_name, char* notification)
|
|||
int cwmp_update_enabled_list_notify(int instance_mode, int notify_type)
|
||||
{
|
||||
int e;
|
||||
CWMP_LOG (INFO,"Get List Notify for %s paramters values", notify_type == OLD_LIST_NOTIFY ? "old": "actual");
|
||||
CWMP_LOG(INFO, "Get List Notify for %s paramters values", notify_type == OLD_LIST_NOTIFY ? "old" : "actual");
|
||||
if (notify_type == OLD_LIST_NOTIFY) {
|
||||
CWMP_LOG (INFO,"%s line %d", __FILE__, __LINE__);
|
||||
CWMP_LOG(INFO, "%s line %d", __FILE__, __LINE__);
|
||||
FREE_JSON(old_list_notify)
|
||||
FREE_JSON(old_global_json_obj)
|
||||
CWMP_LOG (INFO,"%s:%s line %d", __FILE__, __FUNCTION__, __LINE__);
|
||||
e = cwmp_ubus_call("usp.raw", "list_notify", CWMP_UBUS_ARGS{{"instance_mode", {.int_val=instance_mode}, UBUS_Integer}}, 1, &old_global_json_obj);
|
||||
CWMP_LOG(INFO, "%s:%s line %d", __FILE__, __FUNCTION__, __LINE__);
|
||||
e = cwmp_ubus_call("usp.raw", "list_notify", CWMP_UBUS_ARGS{ { "instance_mode", {.int_val = instance_mode }, UBUS_Integer } }, 1, &old_global_json_obj);
|
||||
if (e)
|
||||
return e;
|
||||
json_object_object_get_ex(old_global_json_obj, "parameters", &old_list_notify);
|
||||
CWMP_LOG (INFO,"%s line %d", __FILE__, __LINE__);
|
||||
}
|
||||
else {
|
||||
CWMP_LOG (INFO,"%s line %d", __FILE__, __LINE__);
|
||||
CWMP_LOG(INFO, "%s line %d", __FILE__, __LINE__);
|
||||
} else {
|
||||
CWMP_LOG(INFO, "%s line %d", __FILE__, __LINE__);
|
||||
FREE_JSON(actual_list_notify)
|
||||
FREE_JSON(actual_global_json_obj)
|
||||
CWMP_LOG (INFO,"%s line %d", __FILE__, __FUNCTION__, __LINE__);
|
||||
e = cwmp_ubus_call("usp.raw", "list_notify", CWMP_UBUS_ARGS{{"instance_mode", {.int_val=instance_mode}, UBUS_Integer}}, 1, &actual_global_json_obj);
|
||||
CWMP_LOG(INFO, "%s line %d", __FILE__, __FUNCTION__, __LINE__);
|
||||
e = cwmp_ubus_call("usp.raw", "list_notify", CWMP_UBUS_ARGS{ { "instance_mode", {.int_val = instance_mode }, UBUS_Integer } }, 1, &actual_global_json_obj);
|
||||
if (e)
|
||||
return e;
|
||||
json_object_object_get_ex(actual_global_json_obj, "parameters", &actual_list_notify);
|
||||
CWMP_LOG (INFO,"%s line %d", __FILE__, __FUNCTION__, __LINE__);
|
||||
CWMP_LOG(INFO, "%s line %d", __FILE__, __FUNCTION__, __LINE__);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
168
diagnostic.c
168
diagnostic.c
|
|
@ -19,8 +19,7 @@
|
|||
#include "ubus.h"
|
||||
#include "cwmp_uci.h"
|
||||
|
||||
struct diagnostic_input
|
||||
{
|
||||
struct diagnostic_input {
|
||||
char *input_name;
|
||||
char *parameter_name;
|
||||
char *value;
|
||||
|
|
@ -45,89 +44,88 @@ struct diagnostic_input
|
|||
#define UDPEcho_DIAG_ACT_NAME "UDPEchoDiagnostics"
|
||||
#define NSLookup_DIAG_ACT_NAME "NSLookupDiagnostics"
|
||||
|
||||
struct diagnostic_input download_diagnostics_array[DOWNLOAD_NUMBER_INPUTS]={
|
||||
{"Interface","Device.IP.Diagnostics.DownloadDiagnostics.Interface",NULL},
|
||||
{"DownloadURL","Device.IP.Diagnostics.DownloadDiagnostics.DownloadURL",NULL},
|
||||
{"DSCP","Device.IP.Diagnostics.DownloadDiagnostics.DSCP",NULL},
|
||||
{"EthernetPriority","Device.IP.Diagnostics.DownloadDiagnostics.EthernetPriority",NULL},
|
||||
{"ProtocolVersion","Device.IP.Diagnostics.DownloadDiagnostics.ProtocolVersion",NULL},
|
||||
{"NumberOfConnections","Device.IP.Diagnostics.DownloadDiagnostics.NumberOfConnections",NULL},
|
||||
{"EnablePerConnectionResults","Device.IP.Diagnostics.DownloadDiagnostics.EnablePerConnection",NULL},
|
||||
//{"TimeBasedTestDuration","Device.IP.Diagnostics.DownloadDiagnostics.TimeBasedTestDuration",NULL},
|
||||
//{"TimeBasedTestMeasurementInterval","Device.IP.Diagnostics.DownloadDiagnostics.TimeBasedTestMeasurementInterval",NULL},
|
||||
//{"TimeBasedTestMeasurementOffset","Device.IP.Diagnostics.DownloadDiagnostics.TimeBasedTestMeasurementOffset",NULL}
|
||||
struct diagnostic_input download_diagnostics_array[DOWNLOAD_NUMBER_INPUTS] = {
|
||||
{ "Interface", "Device.IP.Diagnostics.DownloadDiagnostics.Interface", NULL },
|
||||
{ "DownloadURL", "Device.IP.Diagnostics.DownloadDiagnostics.DownloadURL", NULL },
|
||||
{ "DSCP", "Device.IP.Diagnostics.DownloadDiagnostics.DSCP", NULL },
|
||||
{ "EthernetPriority", "Device.IP.Diagnostics.DownloadDiagnostics.EthernetPriority", NULL },
|
||||
{ "ProtocolVersion", "Device.IP.Diagnostics.DownloadDiagnostics.ProtocolVersion", NULL },
|
||||
{ "NumberOfConnections", "Device.IP.Diagnostics.DownloadDiagnostics.NumberOfConnections", NULL },
|
||||
{ "EnablePerConnectionResults", "Device.IP.Diagnostics.DownloadDiagnostics.EnablePerConnection", NULL },
|
||||
//{"TimeBasedTestDuration","Device.IP.Diagnostics.DownloadDiagnostics.TimeBasedTestDuration",NULL},
|
||||
//{"TimeBasedTestMeasurementInterval","Device.IP.Diagnostics.DownloadDiagnostics.TimeBasedTestMeasurementInterval",NULL},
|
||||
//{"TimeBasedTestMeasurementOffset","Device.IP.Diagnostics.DownloadDiagnostics.TimeBasedTestMeasurementOffset",NULL}
|
||||
};
|
||||
|
||||
struct diagnostic_input upload_diagnostics_array[UPLOAD_NUMBER_INPUTS]={
|
||||
{"Interface","Device.IP.Diagnostics.UploadDiagnostics.Interface",NULL},
|
||||
{"UploadURL","Device.IP.Diagnostics.UploadDiagnostics.UploadURL",NULL},
|
||||
{"TestFileLength","Device.IP.Diagnostics.UploadDiagnostics.TestFileLength",NULL},
|
||||
{"DSCP","Device.IP.Diagnostics.UploadDiagnostics.DSCP",NULL},
|
||||
{"EthernetPriority","Device.IP.Diagnostics.UploadDiagnostics.EthernetPriority",NULL},
|
||||
{"ProtocolVersion","Device.IP.Diagnostics.UploadDiagnostics.ProtocolVersion",NULL},
|
||||
{"NumberOfConnections","Device.IP.Diagnostics.UploadDiagnostics.NumberOfConnections",NULL},
|
||||
{"EnablePerConnectionResults","Device.IP.Diagnostics.UploadDiagnostics.EnablePerConnection",NULL},
|
||||
//{"TimeBasedTestDuration","Device.IP.Diagnostics.UploadDiagnostics.TimeBasedTestDuration",NULL},
|
||||
//{"TimeBasedTestMeasurementInterval","Device.IP.Diagnostics.UploadDiagnostics.TimeBasedTestMeasurementInterval",NULL},
|
||||
//{"TimeBasedTestMeasurementOffset","Device.IP.Diagnostics.UploadDiagnostics.TimeBasedTestMeasurementOffset",NULL}
|
||||
struct diagnostic_input upload_diagnostics_array[UPLOAD_NUMBER_INPUTS] = {
|
||||
{ "Interface", "Device.IP.Diagnostics.UploadDiagnostics.Interface", NULL },
|
||||
{ "UploadURL", "Device.IP.Diagnostics.UploadDiagnostics.UploadURL", NULL },
|
||||
{ "TestFileLength", "Device.IP.Diagnostics.UploadDiagnostics.TestFileLength", NULL },
|
||||
{ "DSCP", "Device.IP.Diagnostics.UploadDiagnostics.DSCP", NULL },
|
||||
{ "EthernetPriority", "Device.IP.Diagnostics.UploadDiagnostics.EthernetPriority", NULL },
|
||||
{ "ProtocolVersion", "Device.IP.Diagnostics.UploadDiagnostics.ProtocolVersion", NULL },
|
||||
{ "NumberOfConnections", "Device.IP.Diagnostics.UploadDiagnostics.NumberOfConnections", NULL },
|
||||
{ "EnablePerConnectionResults", "Device.IP.Diagnostics.UploadDiagnostics.EnablePerConnection", NULL },
|
||||
//{"TimeBasedTestDuration","Device.IP.Diagnostics.UploadDiagnostics.TimeBasedTestDuration",NULL},
|
||||
//{"TimeBasedTestMeasurementInterval","Device.IP.Diagnostics.UploadDiagnostics.TimeBasedTestMeasurementInterval",NULL},
|
||||
//{"TimeBasedTestMeasurementOffset","Device.IP.Diagnostics.UploadDiagnostics.TimeBasedTestMeasurementOffset",NULL}
|
||||
};
|
||||
|
||||
struct diagnostic_input ipping_diagnostics_array[IPPING_NUMBER_INPUTS]={
|
||||
{"Host","Device.IP.Diagnostics.IPPing.Host",NULL},
|
||||
{"NumberOfRepetitions","Device.IP.Diagnostics.IPPing.NumberOfRepetitions",NULL},
|
||||
{"Timeout","Device.IP.Diagnostics.IPPing.Timeout",NULL},
|
||||
{"Interface","Device.IP.Diagnostics.IPPing.Interface",NULL},
|
||||
{"ProtocolVersion","Device.IP.Diagnostics.IPPing.ProtocolVersion",NULL},
|
||||
{"DSCP","Device.IP.Diagnostics.IPPing.DSCP",NULL},
|
||||
{"DataBlockSize","Device.IP.Diagnostics.IPPing.DataBlockSize",NULL}
|
||||
struct diagnostic_input ipping_diagnostics_array[IPPING_NUMBER_INPUTS] = {
|
||||
{ "Host", "Device.IP.Diagnostics.IPPing.Host", NULL },
|
||||
{ "NumberOfRepetitions", "Device.IP.Diagnostics.IPPing.NumberOfRepetitions", NULL },
|
||||
{ "Timeout", "Device.IP.Diagnostics.IPPing.Timeout", NULL },
|
||||
{ "Interface", "Device.IP.Diagnostics.IPPing.Interface", NULL },
|
||||
{ "ProtocolVersion", "Device.IP.Diagnostics.IPPing.ProtocolVersion", NULL },
|
||||
{ "DSCP", "Device.IP.Diagnostics.IPPing.DSCP", NULL },
|
||||
{ "DataBlockSize", "Device.IP.Diagnostics.IPPing.DataBlockSize", NULL }
|
||||
};
|
||||
struct diagnostic_input seserverselection_diagnostics_array[SESERVERSELECT_NUMBER_INPUTS]={
|
||||
{"Interface","Device.IP.Diagnostics.ServerSelectionDiagnostics.Interface",NULL},
|
||||
{"Protocol","Device.IP.Diagnostics.ServerSelectionDiagnostics.Protocol",NULL},
|
||||
{"HostList","Device.IP.Diagnostics.ServerSelectionDiagnostics.HostList",NULL},
|
||||
{"ProtocolVersion","Device.IP.Diagnostics.ServerSelectionDiagnostics.ProtocolVersion",NULL},
|
||||
{"NumberOfRepetitions","Device.IP.Diagnostics.ServerSelectionDiagnostics.NumberOfRepetitions",NULL},
|
||||
{"Timeout","Device.IP.Diagnostics.ServerSelectionDiagnostics.Timeout",NULL}
|
||||
struct diagnostic_input seserverselection_diagnostics_array[SESERVERSELECT_NUMBER_INPUTS] = {
|
||||
{ "Interface", "Device.IP.Diagnostics.ServerSelectionDiagnostics.Interface", NULL },
|
||||
{ "Protocol", "Device.IP.Diagnostics.ServerSelectionDiagnostics.Protocol", NULL },
|
||||
{ "HostList", "Device.IP.Diagnostics.ServerSelectionDiagnostics.HostList", NULL },
|
||||
{ "ProtocolVersion", "Device.IP.Diagnostics.ServerSelectionDiagnostics.ProtocolVersion", NULL },
|
||||
{ "NumberOfRepetitions", "Device.IP.Diagnostics.ServerSelectionDiagnostics.NumberOfRepetitions", NULL },
|
||||
{ "Timeout", "Device.IP.Diagnostics.ServerSelectionDiagnostics.Timeout", NULL }
|
||||
};
|
||||
|
||||
struct diagnostic_input traceroute_diagnostics_array[TRACEROUTE_NUMBER_INPUTS]={
|
||||
{"Interface","Device.IP.Diagnostics.TraceRoute.Interface",NULL},
|
||||
{"Host","Device.IP.Diagnostics.TraceRoute.Host",NULL},
|
||||
{"NumberOfTries","Device.IP.Diagnostics.TraceRoute.NumberOfTries",NULL},
|
||||
{"ProtocolVersion","Device.IP.Diagnostics.TraceRoute.ProtocolVersion",NULL},
|
||||
{"Timeout","Device.IP.Diagnostics.TraceRoute.Timeout",NULL},
|
||||
{"DataBlockSize","Device.IP.Diagnostics.TraceRoute.DataBlockSize",NULL},
|
||||
{"DSCP","Device.IP.Diagnostics.TraceRoute.DSCP",NULL},
|
||||
{"MaxHopCount","Device.IP.Diagnostics.TraceRoute.MaxHopCount",NULL}
|
||||
struct diagnostic_input traceroute_diagnostics_array[TRACEROUTE_NUMBER_INPUTS] = {
|
||||
{ "Interface", "Device.IP.Diagnostics.TraceRoute.Interface", NULL },
|
||||
{ "Host", "Device.IP.Diagnostics.TraceRoute.Host", NULL },
|
||||
{ "NumberOfTries", "Device.IP.Diagnostics.TraceRoute.NumberOfTries", NULL },
|
||||
{ "ProtocolVersion", "Device.IP.Diagnostics.TraceRoute.ProtocolVersion", NULL },
|
||||
{ "Timeout", "Device.IP.Diagnostics.TraceRoute.Timeout", NULL },
|
||||
{ "DataBlockSize", "Device.IP.Diagnostics.TraceRoute.DataBlockSize", NULL },
|
||||
{ "DSCP", "Device.IP.Diagnostics.TraceRoute.DSCP", NULL },
|
||||
{ "MaxHopCount", "Device.IP.Diagnostics.TraceRoute.MaxHopCount", NULL }
|
||||
};
|
||||
|
||||
struct diagnostic_input udpecho_diagnostics_array[UDPECHO_NUMBER_INPUTS]={
|
||||
{"Interface","Device.IP.Diagnostics.UDPEchoDiagnostics.Interface",NULL},
|
||||
{"Host","Device.IP.Diagnostics.UDPEchoDiagnostics.Host",NULL},
|
||||
{"Port","Device.IP.Diagnostics.UDPEchoDiagnostics.Port",NULL},
|
||||
{"NumberOfRepetitions","Device.IP.Diagnostics.UDPEchoDiagnostics.NumberOfRepetitions",NULL},
|
||||
{"Timeout","Device.IP.Diagnostics.UDPEchoDiagnostics.Timeout",NULL},
|
||||
{"DataBlockSize","Device.IP.Diagnostics.UDPEchoDiagnostics.DataBlockSize",NULL},
|
||||
{"DSCP","Device.IP.Diagnostics.UDPEchoDiagnostics.DSCP",NULL},
|
||||
{"InterTransmissionTime","Device.IP.Diagnostics.UDPEchoDiagnostics.InterTransmissionTime",NULL},
|
||||
{"ProtocolVersion","Device.IP.Diagnostics.UDPEchoDiagnostics.ProtocolVersion",NULL},
|
||||
//{"EnableIndividualPacketResults","Device.IP.Diagnostics.UDPEchoDiagnostics.EnableIndividualPacketResults",NULL}
|
||||
struct diagnostic_input udpecho_diagnostics_array[UDPECHO_NUMBER_INPUTS] = {
|
||||
{ "Interface", "Device.IP.Diagnostics.UDPEchoDiagnostics.Interface", NULL },
|
||||
{ "Host", "Device.IP.Diagnostics.UDPEchoDiagnostics.Host", NULL },
|
||||
{ "Port", "Device.IP.Diagnostics.UDPEchoDiagnostics.Port", NULL },
|
||||
{ "NumberOfRepetitions", "Device.IP.Diagnostics.UDPEchoDiagnostics.NumberOfRepetitions", NULL },
|
||||
{ "Timeout", "Device.IP.Diagnostics.UDPEchoDiagnostics.Timeout", NULL },
|
||||
{ "DataBlockSize", "Device.IP.Diagnostics.UDPEchoDiagnostics.DataBlockSize", NULL },
|
||||
{ "DSCP", "Device.IP.Diagnostics.UDPEchoDiagnostics.DSCP", NULL },
|
||||
{ "InterTransmissionTime", "Device.IP.Diagnostics.UDPEchoDiagnostics.InterTransmissionTime", NULL },
|
||||
{ "ProtocolVersion", "Device.IP.Diagnostics.UDPEchoDiagnostics.ProtocolVersion", NULL },
|
||||
//{"EnableIndividualPacketResults","Device.IP.Diagnostics.UDPEchoDiagnostics.EnableIndividualPacketResults",NULL}
|
||||
};
|
||||
|
||||
struct diagnostic_input nslookup_diagnostics_array[NSLKUP_NUMBER_INPUTS]={
|
||||
{"Interface","Device.DNS.Diagnostics.NSLookupDiagnostics.Interface",NULL},
|
||||
{"HostName","Device.DNS.Diagnostics.NSLookupDiagnostics.HostName",NULL},
|
||||
{"DNSServer","Device.DNS.Diagnostics.NSLookupDiagnostics.DNSServer",NULL},
|
||||
{"NumberOfRepetitions","Device.DNS.Diagnostics.NSLookupDiagnostics.NumberOfRepetitions",NULL},
|
||||
{"Timeout","Device.DNS.Diagnostics.NSLookupDiagnostics.Timeout",NULL}
|
||||
struct diagnostic_input nslookup_diagnostics_array[NSLKUP_NUMBER_INPUTS] = {
|
||||
{ "Interface", "Device.DNS.Diagnostics.NSLookupDiagnostics.Interface", NULL },
|
||||
{ "HostName", "Device.DNS.Diagnostics.NSLookupDiagnostics.HostName", NULL },
|
||||
{ "DNSServer", "Device.DNS.Diagnostics.NSLookupDiagnostics.DNSServer", NULL },
|
||||
{ "NumberOfRepetitions", "Device.DNS.Diagnostics.NSLookupDiagnostics.NumberOfRepetitions", NULL },
|
||||
{ "Timeout", "Device.DNS.Diagnostics.NSLookupDiagnostics.Timeout", NULL }
|
||||
};
|
||||
|
||||
static bool set_specific_diagnostic_object_parameter_structure_value(struct diagnostic_input (*diagnostics_array)[], int number_inputs, char* parameter, char *value)
|
||||
static bool set_specific_diagnostic_object_parameter_structure_value(struct diagnostic_input (*diagnostics_array)[], int number_inputs, char *parameter, char *value)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<number_inputs; i++)
|
||||
{
|
||||
if(strcmp((*diagnostics_array)[i].parameter_name,parameter) == 0){
|
||||
for (i = 0; i < number_inputs; i++) {
|
||||
if (strcmp((*diagnostics_array)[i].parameter_name, parameter) == 0) {
|
||||
FREE((*diagnostics_array)[i].value);
|
||||
(*diagnostics_array)[i].value = strdup(value);
|
||||
return true;
|
||||
|
|
@ -136,16 +134,12 @@ static bool set_specific_diagnostic_object_parameter_structure_value(struct diag
|
|||
return false;
|
||||
}
|
||||
|
||||
bool set_diagnostic_parameter_structure_value(char *parameter_name, char* value) //returns false in case the parameter is not among diagnostics parameters
|
||||
bool set_diagnostic_parameter_structure_value(char *parameter_name, char *value) //returns false in case the parameter is not among diagnostics parameters
|
||||
{
|
||||
|
||||
return set_specific_diagnostic_object_parameter_structure_value(&download_diagnostics_array, DOWNLOAD_NUMBER_INPUTS, parameter_name, value)
|
||||
|| set_specific_diagnostic_object_parameter_structure_value(&upload_diagnostics_array, UPLOAD_NUMBER_INPUTS, parameter_name, value)
|
||||
|| set_specific_diagnostic_object_parameter_structure_value(&ipping_diagnostics_array, IPPING_NUMBER_INPUTS, parameter_name, value)
|
||||
|| set_specific_diagnostic_object_parameter_structure_value(&nslookup_diagnostics_array, NSLKUP_NUMBER_INPUTS, parameter_name, value)
|
||||
|| set_specific_diagnostic_object_parameter_structure_value(&traceroute_diagnostics_array, TRACEROUTE_NUMBER_INPUTS, parameter_name, value)
|
||||
|| set_specific_diagnostic_object_parameter_structure_value(&udpecho_diagnostics_array, UDPECHO_NUMBER_INPUTS, parameter_name, value)
|
||||
|| set_specific_diagnostic_object_parameter_structure_value(&seserverselection_diagnostics_array, SESERVERSELECT_NUMBER_INPUTS, parameter_name, value);
|
||||
return set_specific_diagnostic_object_parameter_structure_value(&download_diagnostics_array, DOWNLOAD_NUMBER_INPUTS, parameter_name, value) || set_specific_diagnostic_object_parameter_structure_value(&upload_diagnostics_array, UPLOAD_NUMBER_INPUTS, parameter_name, value) ||
|
||||
set_specific_diagnostic_object_parameter_structure_value(&ipping_diagnostics_array, IPPING_NUMBER_INPUTS, parameter_name, value) || set_specific_diagnostic_object_parameter_structure_value(&nslookup_diagnostics_array, NSLKUP_NUMBER_INPUTS, parameter_name, value) ||
|
||||
set_specific_diagnostic_object_parameter_structure_value(&traceroute_diagnostics_array, TRACEROUTE_NUMBER_INPUTS, parameter_name, value) || set_specific_diagnostic_object_parameter_structure_value(&udpecho_diagnostics_array, UDPECHO_NUMBER_INPUTS, parameter_name, value) ||
|
||||
set_specific_diagnostic_object_parameter_structure_value(&seserverselection_diagnostics_array, SESERVERSELECT_NUMBER_INPUTS, parameter_name, value);
|
||||
}
|
||||
|
||||
static int cwmp_diagnostics_operate(char *diagnostics_object, char *action_name, struct diagnostic_input diagnostics_array[], int number_inputs)
|
||||
|
|
@ -153,14 +147,14 @@ static int cwmp_diagnostics_operate(char *diagnostics_object, char *action_name,
|
|||
int e, i;
|
||||
|
||||
LIST_HEAD(diagnostics_param_value_list);
|
||||
for (i=0; i<number_inputs; i++) {
|
||||
for (i = 0; i < number_inputs; i++) {
|
||||
if (diagnostics_array[i].value == NULL || diagnostics_array[i].value[0] == '\0')
|
||||
continue;
|
||||
cwmp_add_list_param_value(diagnostics_array[i].input_name, diagnostics_array[i].value, &diagnostics_param_value_list);
|
||||
}
|
||||
|
||||
e = cwmp_ubus_call("usp.raw", "operate", CWMP_UBUS_ARGS{{"path", {.str_val=diagnostics_object}, UBUS_String},{"action", {.str_val=action_name}, UBUS_String},{"input", {.param_value_list=&diagnostics_param_value_list}, UBUS_Obj_Obj}}, 3, &old_global_json_obj);
|
||||
if(e)
|
||||
e = cwmp_ubus_call("usp.raw", "operate", CWMP_UBUS_ARGS{ { "path", {.str_val = diagnostics_object }, UBUS_String }, { "action", {.str_val = action_name }, UBUS_String }, { "input", {.param_value_list = &diagnostics_param_value_list }, UBUS_Obj_Obj } }, 3, &old_global_json_obj);
|
||||
if (e)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -186,7 +180,7 @@ int cwmp_ip_ping_diagnostics()
|
|||
if (cwmp_diagnostics_operate(IP_DIAGNOSTICS_OBJECT, IPPING_DIAG_ACT_NAME, ipping_diagnostics_array, IPPING_NUMBER_INPUTS) == -1)
|
||||
return -1;
|
||||
cwmp_root_cause_event_ipdiagnostic();
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cwmp_nslookup_diagnostics()
|
||||
|
|
@ -194,7 +188,7 @@ int cwmp_nslookup_diagnostics()
|
|||
if (cwmp_diagnostics_operate(DNS_DIAGNOSTICS_OBJECT, NSLookup_DIAG_ACT_NAME, nslookup_diagnostics_array, NSLKUP_NUMBER_INPUTS) == -1)
|
||||
return -1;
|
||||
cwmp_root_cause_event_ipdiagnostic();
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cwmp_traceroute_diagnostics()
|
||||
|
|
@ -202,7 +196,7 @@ int cwmp_traceroute_diagnostics()
|
|||
if (cwmp_diagnostics_operate(IP_DIAGNOSTICS_OBJECT, TraceRoute_DIAG_ACT_NAME, traceroute_diagnostics_array, TRACEROUTE_NUMBER_INPUTS) == -1)
|
||||
return -1;
|
||||
cwmp_root_cause_event_ipdiagnostic();
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cwmp_udp_echo_diagnostics()
|
||||
|
|
@ -210,7 +204,7 @@ int cwmp_udp_echo_diagnostics()
|
|||
if (cwmp_diagnostics_operate(IP_DIAGNOSTICS_OBJECT, UDPEcho_DIAG_ACT_NAME, udpecho_diagnostics_array, UDPECHO_NUMBER_INPUTS) == -1)
|
||||
return -1;
|
||||
cwmp_root_cause_event_ipdiagnostic();
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cwmp_serverselection_diagnostics()
|
||||
|
|
@ -218,5 +212,5 @@ int cwmp_serverselection_diagnostics()
|
|||
if (cwmp_diagnostics_operate(IP_DIAGNOSTICS_OBJECT, ServerSelection_DIAG_ACT_NAME, seserverselection_diagnostics_array, SESERVERSELECT_NUMBER_INPUTS) == -1)
|
||||
return -1;
|
||||
cwmp_root_cause_event_ipdiagnostic();
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
90
digestauth.c
90
digestauth.c
|
|
@ -43,7 +43,7 @@ static time_t MHD_monotonic_time(void)
|
|||
struct timespec ts;
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
|
||||
return ts.tv_sec;
|
||||
return time(NULL );
|
||||
return time(NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -58,8 +58,7 @@ static void cvthex(const unsigned char *bin, size_t len, char *hex)
|
|||
size_t i;
|
||||
unsigned int j;
|
||||
|
||||
for (i = 0; i < len; ++i)
|
||||
{
|
||||
for (i = 0; i < len; ++i) {
|
||||
j = (bin[i] >> 4) & 0x0f;
|
||||
hex[i * 2] = j <= 9 ? (j + '0') : (j + 'a' - 10);
|
||||
j = bin[i] & 0x0f;
|
||||
|
|
@ -81,9 +80,7 @@ static void cvthex(const unsigned char *bin, size_t len, char *hex)
|
|||
* @param realm A string of characters that describes the realm of auth.
|
||||
* @param nonce A pointer to a character array for the nonce to put in
|
||||
*/
|
||||
static void calculate_nonce(uint32_t nonce_time, const char *method,
|
||||
const char *rnd, unsigned int rnd_size, const char *uri,
|
||||
const char *realm, char *nonce)
|
||||
static void calculate_nonce(uint32_t nonce_time, const char *method, const char *rnd, unsigned int rnd_size, const char *uri, const char *realm, char *nonce)
|
||||
{
|
||||
struct MD5Context md5;
|
||||
unsigned char timestamp[4];
|
||||
|
|
@ -125,8 +122,7 @@ static void calculate_nonce(uint32_t nonce_time, const char *method,
|
|||
* @param key key to look up in data
|
||||
* @return size of the located value, 0 if otherwise
|
||||
*/
|
||||
static int lookup_sub_value(char *dest, size_t size, const char *data,
|
||||
const char *key)
|
||||
static int lookup_sub_value(char *dest, size_t size, const char *data, const char *key)
|
||||
{
|
||||
size_t keylen;
|
||||
size_t len;
|
||||
|
|
@ -141,30 +137,24 @@ static int lookup_sub_value(char *dest, size_t size, const char *data,
|
|||
return 0;
|
||||
keylen = strlen(key);
|
||||
ptr = data;
|
||||
while ('\0' != *ptr)
|
||||
{
|
||||
while ('\0' != *ptr) {
|
||||
if (NULL == (eq = strchr(ptr, '=')))
|
||||
return 0;
|
||||
q1 = eq + 1;
|
||||
while (' ' == *q1)
|
||||
q1++;
|
||||
if ('\"' != *q1)
|
||||
{
|
||||
if ('\"' != *q1) {
|
||||
q2 = strchr(q1, ',');
|
||||
qn = q2;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
q1++;
|
||||
q2 = strchr(q1, '\"');
|
||||
if (NULL == q2)
|
||||
return 0; /* end quote not found */
|
||||
qn = q2 + 1;
|
||||
}
|
||||
if ((0 == strncasecmp(ptr, key, keylen)) && (eq == &ptr[keylen]))
|
||||
{
|
||||
if (NULL == q2)
|
||||
{
|
||||
if ((0 == strncasecmp(ptr, key, keylen)) && (eq == &ptr[keylen])) {
|
||||
if (NULL == q2) {
|
||||
len = strlen(q1) + 1;
|
||||
if (size > len)
|
||||
size = len;
|
||||
|
|
@ -172,9 +162,7 @@ static int lookup_sub_value(char *dest, size_t size, const char *data,
|
|||
strncpy(dest, q1, size);
|
||||
dest[size] = '\0';
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
diff = (q2 - q1) + 1;
|
||||
if (size > diff)
|
||||
size = diff;
|
||||
|
|
@ -208,9 +196,7 @@ static int lookup_sub_value(char *dest, size_t size, const char *data,
|
|||
* @param cnonce A `char *' pointer to the cnonce value
|
||||
* @param sessionkey pointer to buffer of HASH_MD5_HEX_LEN+1 bytes
|
||||
*/
|
||||
static void digest_calc_ha1(const char *alg, const char *username,
|
||||
const char *realm, const char *password, const char *nonce,
|
||||
const char *cnonce, char *sessionkey)
|
||||
static void digest_calc_ha1(const char *alg, const char *username, const char *realm, const char *password, const char *nonce, const char *cnonce, char *sessionkey)
|
||||
{
|
||||
struct MD5Context md5;
|
||||
unsigned char ha1[MD5_DIGEST_SIZE];
|
||||
|
|
@ -222,8 +208,7 @@ static void digest_calc_ha1(const char *alg, const char *username,
|
|||
MD5Update(&md5, ":", 1);
|
||||
MD5Update(&md5, password, strlen(password));
|
||||
MD5Final(ha1, &md5);
|
||||
if (0 == strcasecmp(alg, "md5-sess"))
|
||||
{
|
||||
if (0 == strcasecmp(alg, "md5-sess")) {
|
||||
MD5Init(&md5);
|
||||
MD5Update(&md5, ha1, sizeof(ha1));
|
||||
MD5Update(&md5, ":", 1);
|
||||
|
|
@ -248,9 +233,7 @@ static void digest_calc_ha1(const char *alg, const char *username,
|
|||
* @param hentity H(entity body) if qop="auth-int"
|
||||
* @param response request-digest or response-digest
|
||||
*/
|
||||
static void digest_calc_response(const char *ha1, const char *nonce,
|
||||
const char *noncecount, const char *cnonce, const char *qop,
|
||||
const char *method, const char *uri, char *response)
|
||||
static void digest_calc_response(const char *ha1, const char *nonce, const char *noncecount, const char *cnonce, const char *qop, const char *method, const char *uri, char *response)
|
||||
{
|
||||
struct MD5Context md5;
|
||||
unsigned char ha2[MD5_DIGEST_SIZE];
|
||||
|
|
@ -269,8 +252,7 @@ static void digest_calc_response(const char *ha1, const char *nonce,
|
|||
MD5Update(&md5, ":", 1);
|
||||
MD5Update(&md5, nonce, strlen(nonce));
|
||||
MD5Update(&md5, ":", 1);
|
||||
if ('\0' != *qop)
|
||||
{
|
||||
if ('\0' != *qop) {
|
||||
MD5Update(&md5, noncecount, strlen(noncecount));
|
||||
MD5Update(&md5, ":", 1);
|
||||
MD5Update(&md5, cnonce, strlen(cnonce));
|
||||
|
|
@ -294,27 +276,21 @@ static void digest_calc_response(const char *ha1, const char *nonce,
|
|||
* @return MHD_YES on success, MHD_NO otherwise
|
||||
*/
|
||||
|
||||
int http_digest_auth_fail_response(FILE *fp, const char *http_method,
|
||||
const char *url, const char *realm, const char *opaque)
|
||||
int http_digest_auth_fail_response(FILE *fp, const char *http_method, const char *url, const char *realm, const char *opaque)
|
||||
{
|
||||
size_t hlen;
|
||||
char nonce[HASH_MD5_HEX_LEN + 9];
|
||||
int signal_stale = 0;
|
||||
|
||||
/* Generating the server nonce */
|
||||
calculate_nonce((uint32_t) MHD_monotonic_time(), http_method,
|
||||
NONCE_PRIV_KEY, strlen(NONCE_PRIV_KEY), url, realm, nonce);
|
||||
calculate_nonce((uint32_t)MHD_monotonic_time(), http_method, NONCE_PRIV_KEY, strlen(NONCE_PRIV_KEY), url, realm, nonce);
|
||||
|
||||
/* Building the authentication header */
|
||||
hlen = snprintf(NULL, 0,
|
||||
"Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\"%s",
|
||||
realm, nonce, opaque, signal_stale ? ",stale=\"true\"" : "");
|
||||
hlen = snprintf(NULL, 0, "Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\"%s", realm, nonce, opaque, signal_stale ? ",stale=\"true\"" : "");
|
||||
{
|
||||
char header[hlen + 1];
|
||||
|
||||
snprintf(header, sizeof(header),
|
||||
"Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\"%s",
|
||||
realm, nonce, opaque, signal_stale ? ",stale=\"true\"" : "");
|
||||
snprintf(header, sizeof(header), "Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\"%s", realm, nonce, opaque, signal_stale ? ",stale=\"true\"" : "");
|
||||
|
||||
DD(DEBUG, "%s: header: %s", __FUNCTION__, header);
|
||||
|
||||
|
|
@ -339,9 +315,7 @@ int http_digest_auth_fail_response(FILE *fp, const char *http_method,
|
|||
* @return MHD_YES if authenticated, MHD_NO if not,
|
||||
* MHD_INVALID_NONCE if nonce is invalid
|
||||
*/
|
||||
int http_digest_auth_check(const char *http_method, const char *url,
|
||||
const char *header, const char *realm, const char *username,
|
||||
const char *password, unsigned int nonce_timeout)
|
||||
int http_digest_auth_check(const char *http_method, const char *url, const char *header, const char *realm, const char *username, const char *password, unsigned int nonce_timeout)
|
||||
{
|
||||
size_t len;
|
||||
char *end;
|
||||
|
|
@ -391,26 +365,23 @@ int http_digest_auth_check(const char *http_method, const char *url,
|
|||
return MHD_NO;
|
||||
|
||||
/* 8 = 4 hexadecimal numbers for the timestamp */
|
||||
nonce_time = strtoul(nonce + len - 8, (char **) NULL, 16);
|
||||
t = (uint32_t) MHD_monotonic_time();
|
||||
nonce_time = strtoul(nonce + len - 8, (char **)NULL, 16);
|
||||
t = (uint32_t)MHD_monotonic_time();
|
||||
/*
|
||||
* First level vetting for the nonce validity if the timestamp
|
||||
* attached to the nonce exceeds `nonce_timeout' then the nonce is
|
||||
* invalid.
|
||||
*/
|
||||
if ((t > nonce_time + nonce_timeout)
|
||||
|| (nonce_time + nonce_timeout < nonce_time))
|
||||
if ((t > nonce_time + nonce_timeout) || (nonce_time + nonce_timeout < nonce_time))
|
||||
return MHD_INVALID_NONCE;
|
||||
|
||||
if (0 != strncmp(uri, url, strlen(url)))
|
||||
{
|
||||
if (0 != strncmp(uri, url, strlen(url))) {
|
||||
DD(DEBUG, "Authentication failed: URI does not match.");
|
||||
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
calculate_nonce(nonce_time, http_method, NONCE_PRIV_KEY,
|
||||
strlen(NONCE_PRIV_KEY), url, realm, noncehashexp);
|
||||
calculate_nonce(nonce_time, http_method, NONCE_PRIV_KEY, strlen(NONCE_PRIV_KEY), url, realm, noncehashexp);
|
||||
|
||||
/*
|
||||
* Second level vetting for the nonce validity
|
||||
|
|
@ -425,20 +396,13 @@ int http_digest_auth_check(const char *http_method, const char *url,
|
|||
if (0 != strcmp(nonce, noncehashexp))
|
||||
return MHD_INVALID_NONCE;
|
||||
|
||||
if ((0 == lookup_sub_value(cnonce, sizeof(cnonce), header, "cnonce"))
|
||||
|| (0 == lookup_sub_value(qop, sizeof(qop), header, "qop"))
|
||||
|| ((0 != strcmp(qop, "auth")) && (0 != strcmp(qop, "")))
|
||||
|| (0 == lookup_sub_value(nc, sizeof(nc), header, "nc"))
|
||||
|| (0
|
||||
== lookup_sub_value(response, sizeof(response), header,
|
||||
"response")))
|
||||
{
|
||||
if ((0 == lookup_sub_value(cnonce, sizeof(cnonce), header, "cnonce")) || (0 == lookup_sub_value(qop, sizeof(qop), header, "qop")) || ((0 != strcmp(qop, "auth")) && (0 != strcmp(qop, ""))) || (0 == lookup_sub_value(nc, sizeof(nc), header, "nc")) ||
|
||||
(0 == lookup_sub_value(response, sizeof(response), header, "response"))) {
|
||||
DD(DEBUG, "Authentication failed, invalid format.");
|
||||
return MHD_NO;
|
||||
}
|
||||
nci = strtoul(nc, &end, 16);
|
||||
if (('\0' != *end) || ((LONG_MAX == nci) && (ERANGE == errno)))
|
||||
{
|
||||
if (('\0' != *end) || ((LONG_MAX == nci) && (ERANGE == errno))) {
|
||||
DD(DEBUG, "Authentication failed, invalid format.");
|
||||
return MHD_NO; /* invalid nonce format */
|
||||
}
|
||||
|
|
|
|||
681
event.c
681
event.c
|
|
@ -25,145 +25,132 @@
|
|||
#include "session.h"
|
||||
#include "xml.h"
|
||||
|
||||
const struct EVENT_CONST_STRUCT EVENT_CONST [] = {
|
||||
[EVENT_IDX_0BOOTSTRAP] = {"0 BOOTSTRAP", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
|
||||
[EVENT_IDX_1BOOT] = {"1 BOOT", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL},
|
||||
[EVENT_IDX_2PERIODIC] = {"2 PERIODIC", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
|
||||
[EVENT_IDX_3SCHEDULED] = {"3 SCHEDULED", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
|
||||
[EVENT_IDX_4VALUE_CHANGE] = {"4 VALUE CHANGE", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL},
|
||||
[EVENT_IDX_5KICKED] = {"5 KICKED", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
|
||||
[EVENT_IDX_6CONNECTION_REQUEST] = {"6 CONNECTION REQUEST", EVENT_TYPE_SINGLE, 0},
|
||||
[EVENT_IDX_7TRANSFER_COMPLETE] = {"7 TRANSFER COMPLETE", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
|
||||
[EVENT_IDX_8DIAGNOSTICS_COMPLETE] = {"8 DIAGNOSTICS COMPLETE", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL},
|
||||
[EVENT_IDX_9REQUEST_DOWNLOAD] = {"9 REQUEST DOWNLOAD", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
|
||||
[EVENT_IDX_10AUTONOMOUS_TRANSFER_COMPLETE] = {"10 AUTONOMOUS TRANSFER COMPLETE", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
|
||||
[EVENT_IDX_11DU_STATE_CHANGE_COMPLETE] = {"11 DU STATE CHANGE COMPLETE", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
|
||||
[EVENT_IDX_M_Reboot] = {"M Reboot", EVENT_TYPE_MULTIPLE,EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
|
||||
[EVENT_IDX_M_ScheduleInform] = {"M ScheduleInform", EVENT_TYPE_MULTIPLE,EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
|
||||
[EVENT_IDX_M_Download] = {"M Download", EVENT_TYPE_MULTIPLE,EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
|
||||
[EVENT_IDX_M_Schedule_Download] = {"M ScheduleDownload", EVENT_TYPE_MULTIPLE,EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
|
||||
[EVENT_IDX_M_Upload] = {"M Upload", EVENT_TYPE_MULTIPLE,EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
|
||||
[EVENT_IDX_M_ChangeDUState] = {"M ChangeDUState", EVENT_TYPE_MULTIPLE,EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT}
|
||||
};
|
||||
const struct EVENT_CONST_STRUCT EVENT_CONST[] = {[EVENT_IDX_0BOOTSTRAP] = { "0 BOOTSTRAP", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },
|
||||
[EVENT_IDX_1BOOT] = { "1 BOOT", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL },
|
||||
[EVENT_IDX_2PERIODIC] = { "2 PERIODIC", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },
|
||||
[EVENT_IDX_3SCHEDULED] = { "3 SCHEDULED", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },
|
||||
[EVENT_IDX_4VALUE_CHANGE] = { "4 VALUE CHANGE", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL },
|
||||
[EVENT_IDX_5KICKED] = { "5 KICKED", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },
|
||||
[EVENT_IDX_6CONNECTION_REQUEST] = { "6 CONNECTION REQUEST", EVENT_TYPE_SINGLE, 0 },
|
||||
[EVENT_IDX_7TRANSFER_COMPLETE] = { "7 TRANSFER COMPLETE", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },
|
||||
[EVENT_IDX_8DIAGNOSTICS_COMPLETE] = { "8 DIAGNOSTICS COMPLETE", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL },
|
||||
[EVENT_IDX_9REQUEST_DOWNLOAD] = { "9 REQUEST DOWNLOAD", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },
|
||||
[EVENT_IDX_10AUTONOMOUS_TRANSFER_COMPLETE] = { "10 AUTONOMOUS TRANSFER COMPLETE", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },
|
||||
[EVENT_IDX_11DU_STATE_CHANGE_COMPLETE] = { "11 DU STATE CHANGE COMPLETE", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },
|
||||
[EVENT_IDX_M_Reboot] = { "M Reboot", EVENT_TYPE_MULTIPLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },
|
||||
[EVENT_IDX_M_ScheduleInform] = { "M ScheduleInform", EVENT_TYPE_MULTIPLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },
|
||||
[EVENT_IDX_M_Download] = { "M Download", EVENT_TYPE_MULTIPLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },
|
||||
[EVENT_IDX_M_Schedule_Download] = { "M ScheduleDownload", EVENT_TYPE_MULTIPLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },
|
||||
[EVENT_IDX_M_Upload] = { "M Upload", EVENT_TYPE_MULTIPLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },
|
||||
[EVENT_IDX_M_ChangeDUState] = { "M ChangeDUState", EVENT_TYPE_MULTIPLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT } };
|
||||
|
||||
void cwmp_save_event_container (struct event_container *event_container) //to be moved to backupsession
|
||||
void cwmp_save_event_container(struct event_container *event_container) //to be moved to backupsession
|
||||
{
|
||||
struct list_head *ilist;
|
||||
struct cwmp_dm_parameter *dm_parameter;
|
||||
mxml_node_t *b;
|
||||
struct list_head *ilist;
|
||||
struct cwmp_dm_parameter *dm_parameter;
|
||||
mxml_node_t *b;
|
||||
|
||||
if (EVENT_CONST[event_container->code].RETRY & EVENT_RETRY_AFTER_REBOOT) {
|
||||
b = bkp_session_insert_event(event_container->code, event_container->command_key, event_container->id, "queue");
|
||||
if (EVENT_CONST[event_container->code].RETRY & EVENT_RETRY_AFTER_REBOOT) {
|
||||
b = bkp_session_insert_event(event_container->code, event_container->command_key, event_container->id, "queue");
|
||||
|
||||
list_for_each(ilist,&(event_container->head_dm_parameter)) {
|
||||
dm_parameter = list_entry(ilist, struct cwmp_dm_parameter, list);
|
||||
bkp_session_insert_parameter(b, dm_parameter->name);
|
||||
}
|
||||
bkp_session_save();
|
||||
}
|
||||
list_for_each (ilist, &(event_container->head_dm_parameter)) {
|
||||
dm_parameter = list_entry(ilist, struct cwmp_dm_parameter, list);
|
||||
bkp_session_insert_parameter(b, dm_parameter->name);
|
||||
}
|
||||
bkp_session_save();
|
||||
}
|
||||
}
|
||||
|
||||
struct event_container *cwmp_add_event_container (struct cwmp *cwmp, int event_code, char *command_key)
|
||||
struct event_container *cwmp_add_event_container(struct cwmp *cwmp, int event_code, char *command_key)
|
||||
{
|
||||
static int id;
|
||||
struct event_container *event_container;
|
||||
struct session *session;
|
||||
struct list_head *ilist;
|
||||
static int id;
|
||||
struct event_container *event_container;
|
||||
struct session *session;
|
||||
struct list_head *ilist;
|
||||
|
||||
if (cwmp->head_event_container == NULL)
|
||||
{
|
||||
session = cwmp_add_queue_session(cwmp);
|
||||
if (session == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
cwmp->head_event_container = &(session->head_event_container);
|
||||
}
|
||||
session = list_entry (cwmp->head_event_container, struct session,head_event_container);
|
||||
list_for_each(ilist, cwmp->head_event_container)
|
||||
{
|
||||
event_container = list_entry (ilist, struct event_container, list);
|
||||
if (event_container->code==event_code &&
|
||||
EVENT_CONST[event_code].TYPE==EVENT_TYPE_SINGLE)
|
||||
{
|
||||
return event_container;
|
||||
}
|
||||
if(event_container->code > event_code)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
event_container = calloc (1,sizeof(struct event_container));
|
||||
if (event_container==NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
INIT_LIST_HEAD (&(event_container->head_dm_parameter));
|
||||
list_add (&(event_container->list), ilist->prev);
|
||||
event_container->code = event_code;
|
||||
event_container->command_key = command_key?strdup(command_key):strdup("");
|
||||
if((id<0) || (id>=MAX_INT_ID) )
|
||||
{
|
||||
id=0;
|
||||
}
|
||||
id++;
|
||||
event_container->id = id;
|
||||
return event_container;
|
||||
if (cwmp->head_event_container == NULL) {
|
||||
session = cwmp_add_queue_session(cwmp);
|
||||
if (session == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
cwmp->head_event_container = &(session->head_event_container);
|
||||
}
|
||||
session = list_entry(cwmp->head_event_container, struct session, head_event_container);
|
||||
list_for_each (ilist, cwmp->head_event_container) {
|
||||
event_container = list_entry(ilist, struct event_container, list);
|
||||
if (event_container->code == event_code && EVENT_CONST[event_code].TYPE == EVENT_TYPE_SINGLE) {
|
||||
return event_container;
|
||||
}
|
||||
if (event_container->code > event_code) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
event_container = calloc(1, sizeof(struct event_container));
|
||||
if (event_container == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
INIT_LIST_HEAD(&(event_container->head_dm_parameter));
|
||||
list_add(&(event_container->list), ilist->prev);
|
||||
event_container->code = event_code;
|
||||
event_container->command_key = command_key ? strdup(command_key) : strdup("");
|
||||
if ((id < 0) || (id >= MAX_INT_ID)) {
|
||||
id = 0;
|
||||
}
|
||||
id++;
|
||||
event_container->id = id;
|
||||
return event_container;
|
||||
}
|
||||
|
||||
void cwmp_root_cause_event_ipdiagnostic(void)
|
||||
{
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
struct event_container *event_container;
|
||||
|
||||
pthread_mutex_lock (&(cwmp->mutex_session_queue));
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_8DIAGNOSTICS_COMPLETE, "");
|
||||
if (event_container == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
struct event_container *event_container;
|
||||
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_queue));
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_8DIAGNOSTICS_COMPLETE, "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return;
|
||||
}
|
||||
cwmp_save_event_container(event_container);
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
}
|
||||
cwmp_save_event_container(event_container);
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
pthread_cond_signal(&(cwmp->threshold_session_send));
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
int cwmp_root_cause_event_boot (struct cwmp *cwmp)
|
||||
int cwmp_root_cause_event_boot(struct cwmp *cwmp)
|
||||
{
|
||||
struct event_container *event_container;
|
||||
if (cwmp->env.boot == CWMP_START_BOOT)
|
||||
{
|
||||
pthread_mutex_lock (&(cwmp->mutex_session_queue));
|
||||
cwmp->env.boot = 0;
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_1BOOT, "");
|
||||
if (event_container == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
cwmp_save_event_container (event_container);
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
}
|
||||
return CWMP_OK;
|
||||
struct event_container *event_container;
|
||||
if (cwmp->env.boot == CWMP_START_BOOT) {
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_queue));
|
||||
cwmp->env.boot = 0;
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_1BOOT, "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
cwmp_save_event_container(event_container);
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
}
|
||||
return CWMP_OK;
|
||||
}
|
||||
int event_remove_all_event_container(struct session *session, int rem_from)
|
||||
{
|
||||
struct event_container *event_container;
|
||||
struct event_container *event_container;
|
||||
|
||||
while (session->head_event_container.next!=&(session->head_event_container)) {
|
||||
event_container = list_entry(session->head_event_container.next, struct event_container, list);
|
||||
bkp_session_delete_event(event_container->id, rem_from?"send":"queue");
|
||||
if (event_container->code == EVENT_IDX_1BOOT && rem_from == RPC_SEND) {
|
||||
remove("/etc/icwmpd/.icwmpd_boot");
|
||||
}
|
||||
free (event_container->command_key);
|
||||
free_dm_parameter_all_fromlist(&(event_container->head_dm_parameter));
|
||||
list_del(&(event_container->list));
|
||||
free (event_container);
|
||||
}
|
||||
bkp_session_save();
|
||||
return CWMP_OK;
|
||||
while (session->head_event_container.next != &(session->head_event_container)) {
|
||||
event_container = list_entry(session->head_event_container.next, struct event_container, list);
|
||||
bkp_session_delete_event(event_container->id, rem_from ? "send" : "queue");
|
||||
if (event_container->code == EVENT_IDX_1BOOT && rem_from == RPC_SEND) {
|
||||
remove("/etc/icwmpd/.icwmpd_boot");
|
||||
}
|
||||
free(event_container->command_key);
|
||||
free_dm_parameter_all_fromlist(&(event_container->head_dm_parameter));
|
||||
list_del(&(event_container->list));
|
||||
free(event_container);
|
||||
}
|
||||
bkp_session_save();
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int event_remove_noretry_event_container(struct session *session, struct cwmp *cwmp)
|
||||
|
|
@ -171,13 +158,13 @@ int event_remove_noretry_event_container(struct session *session, struct cwmp *c
|
|||
struct event_container *event_container;
|
||||
struct list_head *ilist, *q;
|
||||
|
||||
list_for_each_safe(ilist,q,&(session->head_event_container)) {
|
||||
list_for_each_safe (ilist, q, &(session->head_event_container)) {
|
||||
event_container = list_entry(ilist, struct event_container, list);
|
||||
if (EVENT_CONST[event_container->code].RETRY == 0) {
|
||||
free (event_container->command_key);
|
||||
free(event_container->command_key);
|
||||
free_dm_parameter_all_fromlist(&(event_container->head_dm_parameter));
|
||||
list_del(&(event_container->list));
|
||||
free (event_container);
|
||||
free(event_container);
|
||||
}
|
||||
|
||||
if (EVENT_CONST[event_container->code].CODE[0] == '6')
|
||||
|
|
@ -186,231 +173,221 @@ int event_remove_noretry_event_container(struct session *session, struct cwmp *c
|
|||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int cwmp_root_cause_event_bootstrap (struct cwmp *cwmp)
|
||||
int cwmp_root_cause_event_bootstrap(struct cwmp *cwmp)
|
||||
{
|
||||
char *acsurl = NULL;
|
||||
int cmp = 0;
|
||||
struct event_container *event_container;
|
||||
struct session *session;
|
||||
char *acsurl = NULL;
|
||||
int cmp = 0;
|
||||
struct event_container *event_container;
|
||||
struct session *session;
|
||||
|
||||
cwmp_load_saved_session(cwmp, &acsurl, ACS);
|
||||
cwmp_load_saved_session(cwmp, &acsurl, ACS);
|
||||
|
||||
if (acsurl == NULL)
|
||||
save_acs_bkp_config (cwmp);
|
||||
if (acsurl == NULL)
|
||||
save_acs_bkp_config(cwmp);
|
||||
|
||||
if (acsurl == NULL || ((acsurl != NULL)&&(cmp = strcmp(cwmp->conf.acsurl,acsurl)))) {
|
||||
pthread_mutex_lock (&(cwmp->mutex_session_queue));
|
||||
if (cwmp->head_event_container!=NULL && cwmp->head_session_queue.next!=&(cwmp->head_session_queue)) {
|
||||
session = list_entry(cwmp->head_event_container,struct session, head_event_container);
|
||||
event_remove_all_event_container (session,RPC_QUEUE);
|
||||
}
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_0BOOTSTRAP, "");
|
||||
FREE(acsurl);
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
cwmp_save_event_container (event_container);
|
||||
cwmp_scheduleInform_remove_all();
|
||||
cwmp_scheduledDownload_remove_all();
|
||||
if (acsurl == NULL || ((acsurl != NULL) && (cmp = strcmp(cwmp->conf.acsurl, acsurl)))) {
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_queue));
|
||||
if (cwmp->head_event_container != NULL && cwmp->head_session_queue.next != &(cwmp->head_session_queue)) {
|
||||
session = list_entry(cwmp->head_event_container, struct session, head_event_container);
|
||||
event_remove_all_event_container(session, RPC_QUEUE);
|
||||
}
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_0BOOTSTRAP, "");
|
||||
FREE(acsurl);
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
cwmp_save_event_container(event_container);
|
||||
cwmp_scheduleInform_remove_all();
|
||||
cwmp_scheduledDownload_remove_all();
|
||||
cwmp_scheduled_Download_remove_all();
|
||||
cwmp_apply_scheduled_Download_remove_all();
|
||||
cwmp_scheduledUpload_remove_all();
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
} else {
|
||||
FREE(acsurl);
|
||||
}
|
||||
cwmp_scheduledUpload_remove_all();
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
} else {
|
||||
FREE(acsurl);
|
||||
}
|
||||
|
||||
if (cmp) {
|
||||
pthread_mutex_lock (&(cwmp->mutex_session_queue));
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_4VALUE_CHANGE, "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
if (cmp) {
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_queue));
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
|
||||
char buf[64] = "Device.ManagementServer.URL";
|
||||
add_dm_parameter_tolist(&(event_container->head_dm_parameter), buf, NULL, NULL);
|
||||
cwmp_save_event_container (event_container);
|
||||
save_acs_bkp_config(cwmp);
|
||||
cwmp_scheduleInform_remove_all();
|
||||
cwmp_scheduledDownload_remove_all();
|
||||
char buf[64] = "Device.ManagementServer.URL";
|
||||
add_dm_parameter_tolist(&(event_container->head_dm_parameter), buf, NULL, NULL);
|
||||
cwmp_save_event_container(event_container);
|
||||
save_acs_bkp_config(cwmp);
|
||||
cwmp_scheduleInform_remove_all();
|
||||
cwmp_scheduledDownload_remove_all();
|
||||
cwmp_apply_scheduled_Download_remove_all();
|
||||
cwmp_scheduled_Download_remove_all();
|
||||
cwmp_scheduledUpload_remove_all();
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
}
|
||||
cwmp_scheduledUpload_remove_all();
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
}
|
||||
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int cwmp_root_cause_TransferComplete (struct cwmp *cwmp, struct transfer_complete *p)
|
||||
{
|
||||
struct event_container *event_container;
|
||||
struct session *session;
|
||||
struct rpc *rpc_acs;
|
||||
|
||||
pthread_mutex_lock (&(cwmp->mutex_session_queue));
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_7TRANSFER_COMPLETE, "");
|
||||
if (event_container == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
switch (p->type) {
|
||||
case TYPE_DOWNLOAD:
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_M_Download, p->command_key?p->command_key:"");
|
||||
if (event_container == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
break;
|
||||
case TYPE_UPLOAD:
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_M_Upload, p->command_key?p->command_key:"");
|
||||
if (event_container == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
break;
|
||||
case TYPE_SCHEDULE_DOWNLOAD:
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_M_Schedule_Download, p->command_key?p->command_key:"");
|
||||
if (event_container == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
session = list_entry (cwmp->head_event_container, struct session,head_event_container);
|
||||
if((rpc_acs = cwmp_add_session_rpc_acs(session, RPC_ACS_TRANSFER_COMPLETE)) == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
rpc_acs->extra_data = (void *)p;
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int cwmp_root_cause_dustatechangeComplete (struct cwmp *cwmp, struct du_state_change_complete *p)
|
||||
int cwmp_root_cause_TransferComplete(struct cwmp *cwmp, struct transfer_complete *p)
|
||||
{
|
||||
struct event_container *event_container;
|
||||
struct session *session;
|
||||
struct rpc *rpc_acs;
|
||||
struct event_container *event_container;
|
||||
struct session *session;
|
||||
struct rpc *rpc_acs;
|
||||
|
||||
pthread_mutex_lock (&(cwmp->mutex_session_queue));
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_11DU_STATE_CHANGE_COMPLETE, "");
|
||||
if (event_container == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_M_ChangeDUState, p->command_key?p->command_key:"");
|
||||
if (event_container == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_queue));
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_7TRANSFER_COMPLETE, "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
session = list_entry (cwmp->head_event_container, struct session,head_event_container);
|
||||
if((rpc_acs = cwmp_add_session_rpc_acs(session, RPC_ACS_DU_STATE_CHANGE_COMPLETE)) == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
rpc_acs->extra_data = (void *)p;
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_OK;
|
||||
switch (p->type) {
|
||||
case TYPE_DOWNLOAD:
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_M_Download, p->command_key ? p->command_key : "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
break;
|
||||
case TYPE_UPLOAD:
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_M_Upload, p->command_key ? p->command_key : "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
break;
|
||||
case TYPE_SCHEDULE_DOWNLOAD:
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_M_Schedule_Download, p->command_key ? p->command_key : "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
session = list_entry(cwmp->head_event_container, struct session, head_event_container);
|
||||
if ((rpc_acs = cwmp_add_session_rpc_acs(session, RPC_ACS_TRANSFER_COMPLETE)) == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
rpc_acs->extra_data = (void *)p;
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int cwmp_root_cause_getRPCMethod (struct cwmp *cwmp)
|
||||
int cwmp_root_cause_dustatechangeComplete(struct cwmp *cwmp, struct du_state_change_complete *p)
|
||||
{
|
||||
struct event_container *event_container;
|
||||
struct session *session;
|
||||
struct event_container *event_container;
|
||||
struct session *session;
|
||||
struct rpc *rpc_acs;
|
||||
|
||||
if (cwmp->env.periodic == CWMP_START_PERIODIC) {
|
||||
pthread_mutex_lock (&(cwmp->mutex_session_queue));
|
||||
cwmp->env.periodic = 0;
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_2PERIODIC, "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
cwmp_save_event_container (event_container);
|
||||
session = list_entry (cwmp->head_event_container, struct session,head_event_container);
|
||||
if (cwmp_add_session_rpc_acs(session, RPC_ACS_GET_RPC_METHODS) == NULL) {
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
}
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_queue));
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_11DU_STATE_CHANGE_COMPLETE, "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
|
||||
return CWMP_OK;
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_M_ChangeDUState, p->command_key ? p->command_key : "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
session = list_entry(cwmp->head_event_container, struct session, head_event_container);
|
||||
if ((rpc_acs = cwmp_add_session_rpc_acs(session, RPC_ACS_DU_STATE_CHANGE_COMPLETE)) == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
rpc_acs->extra_data = (void *)p;
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
void *thread_event_periodic (void *v)
|
||||
int cwmp_root_cause_getRPCMethod(struct cwmp *cwmp)
|
||||
{
|
||||
struct cwmp *cwmp = (struct cwmp *) v;
|
||||
struct event_container *event_container;
|
||||
static int periodic_interval;
|
||||
static bool periodic_enable;
|
||||
static time_t periodic_time;
|
||||
static struct timespec periodic_timeout = {0, 0};
|
||||
time_t current_time;
|
||||
long int delta_time;
|
||||
struct event_container *event_container;
|
||||
struct session *session;
|
||||
|
||||
periodic_interval = cwmp->conf.period;
|
||||
periodic_enable = cwmp->conf.periodic_enable;
|
||||
periodic_time = cwmp->conf.time;
|
||||
if (cwmp->env.periodic == CWMP_START_PERIODIC) {
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_queue));
|
||||
cwmp->env.periodic = 0;
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_2PERIODIC, "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
cwmp_save_event_container(event_container);
|
||||
session = list_entry(cwmp->head_event_container, struct session, head_event_container);
|
||||
if (cwmp_add_session_rpc_acs(session, RPC_ACS_GET_RPC_METHODS) == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
}
|
||||
|
||||
for(;;) {
|
||||
pthread_mutex_lock (&(cwmp->mutex_periodic));
|
||||
if (cwmp->conf.periodic_enable) {
|
||||
current_time = time(NULL);
|
||||
if (periodic_time != 0) {
|
||||
delta_time = (current_time - periodic_time) % periodic_interval;
|
||||
if (delta_time >= 0)
|
||||
periodic_timeout.tv_sec = current_time + periodic_interval - delta_time;
|
||||
else
|
||||
periodic_timeout.tv_sec = current_time - delta_time;
|
||||
} else {
|
||||
periodic_timeout.tv_sec = current_time + periodic_interval;
|
||||
}
|
||||
cwmp->session_status.next_periodic = periodic_timeout.tv_sec;
|
||||
pthread_cond_timedwait(&(cwmp->threshold_periodic), &(cwmp->mutex_periodic), &periodic_timeout);
|
||||
} else {
|
||||
cwmp->session_status.next_periodic = 0;
|
||||
pthread_cond_wait(&(cwmp->threshold_periodic), &(cwmp->mutex_periodic));
|
||||
}
|
||||
pthread_mutex_unlock (&(cwmp->mutex_periodic));
|
||||
if (periodic_interval != cwmp->conf.period ||
|
||||
periodic_enable != cwmp->conf.periodic_enable ||
|
||||
periodic_time != cwmp->conf.time) {
|
||||
periodic_enable = cwmp->conf.periodic_enable;
|
||||
periodic_interval = cwmp->conf.period;
|
||||
periodic_time = cwmp->conf.time;
|
||||
continue;
|
||||
}
|
||||
CWMP_LOG(INFO,"Periodic thread: add periodic event in the queue");
|
||||
pthread_mutex_lock (&(cwmp->mutex_session_queue));
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_2PERIODIC, "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
continue;
|
||||
}
|
||||
cwmp_save_event_container (event_container);
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
pthread_cond_signal(&(cwmp->threshold_session_send));
|
||||
}
|
||||
return CWMP_OK;
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
void *thread_event_periodic(void *v)
|
||||
{
|
||||
struct cwmp *cwmp = (struct cwmp *)v;
|
||||
struct event_container *event_container;
|
||||
static int periodic_interval;
|
||||
static bool periodic_enable;
|
||||
static time_t periodic_time;
|
||||
static struct timespec periodic_timeout = { 0, 0 };
|
||||
time_t current_time;
|
||||
long int delta_time;
|
||||
|
||||
periodic_interval = cwmp->conf.period;
|
||||
periodic_enable = cwmp->conf.periodic_enable;
|
||||
periodic_time = cwmp->conf.time;
|
||||
|
||||
for (;;) {
|
||||
pthread_mutex_lock(&(cwmp->mutex_periodic));
|
||||
if (cwmp->conf.periodic_enable) {
|
||||
current_time = time(NULL);
|
||||
if (periodic_time != 0) {
|
||||
delta_time = (current_time - periodic_time) % periodic_interval;
|
||||
if (delta_time >= 0)
|
||||
periodic_timeout.tv_sec = current_time + periodic_interval - delta_time;
|
||||
else
|
||||
periodic_timeout.tv_sec = current_time - delta_time;
|
||||
} else {
|
||||
periodic_timeout.tv_sec = current_time + periodic_interval;
|
||||
}
|
||||
cwmp->session_status.next_periodic = periodic_timeout.tv_sec;
|
||||
pthread_cond_timedwait(&(cwmp->threshold_periodic), &(cwmp->mutex_periodic), &periodic_timeout);
|
||||
} else {
|
||||
cwmp->session_status.next_periodic = 0;
|
||||
pthread_cond_wait(&(cwmp->threshold_periodic), &(cwmp->mutex_periodic));
|
||||
}
|
||||
pthread_mutex_unlock(&(cwmp->mutex_periodic));
|
||||
if (periodic_interval != cwmp->conf.period || periodic_enable != cwmp->conf.periodic_enable || periodic_time != cwmp->conf.time) {
|
||||
periodic_enable = cwmp->conf.periodic_enable;
|
||||
periodic_interval = cwmp->conf.period;
|
||||
periodic_time = cwmp->conf.time;
|
||||
continue;
|
||||
}
|
||||
CWMP_LOG(INFO, "Periodic thread: add periodic event in the queue");
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_queue));
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_2PERIODIC, "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
continue;
|
||||
}
|
||||
cwmp_save_event_container(event_container);
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
pthread_cond_signal(&(cwmp->threshold_session_send));
|
||||
}
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
bool event_exist_in_list(struct cwmp *cwmp, int event)
|
||||
{
|
||||
struct event_container *event_container;
|
||||
list_for_each_entry(event_container, cwmp->head_event_container, list) {
|
||||
struct event_container *event_container;
|
||||
list_for_each_entry (event_container, cwmp->head_event_container, list) {
|
||||
if (event_container->code == event)
|
||||
return true;
|
||||
}
|
||||
|
|
@ -419,39 +396,37 @@ bool event_exist_in_list(struct cwmp *cwmp, int event)
|
|||
|
||||
int cwmp_root_cause_event_periodic(struct cwmp *cwmp)
|
||||
{
|
||||
static int period = 0;
|
||||
static bool periodic_enable = false;
|
||||
static time_t periodic_time = 0;
|
||||
char local_time[27] = {0};
|
||||
struct tm *t_tm;
|
||||
|
||||
if (period == cwmp->conf.period &&
|
||||
periodic_enable == cwmp->conf.periodic_enable &&
|
||||
periodic_time == cwmp->conf.time)
|
||||
return CWMP_OK;
|
||||
static int period = 0;
|
||||
static bool periodic_enable = false;
|
||||
static time_t periodic_time = 0;
|
||||
char local_time[27] = { 0 };
|
||||
struct tm *t_tm;
|
||||
|
||||
if (period == cwmp->conf.period && periodic_enable == cwmp->conf.periodic_enable && periodic_time == cwmp->conf.time)
|
||||
return CWMP_OK;
|
||||
|
||||
pthread_mutex_lock(&(cwmp->mutex_periodic));
|
||||
period = cwmp->conf.period;
|
||||
periodic_enable = cwmp->conf.periodic_enable;
|
||||
periodic_time = cwmp->conf.time;
|
||||
CWMP_LOG(INFO, periodic_enable ? "Periodic event is enabled. Interval period = %ds" : "Periodic event is disabled", period);
|
||||
|
||||
pthread_mutex_lock(&(cwmp->mutex_periodic));
|
||||
period = cwmp->conf.period;
|
||||
periodic_enable = cwmp->conf.periodic_enable;
|
||||
periodic_time = cwmp->conf.time;
|
||||
CWMP_LOG(INFO,periodic_enable?"Periodic event is enabled. Interval period = %ds":"Periodic event is disabled", period);
|
||||
|
||||
t_tm = localtime(&periodic_time);
|
||||
if (t_tm == NULL)
|
||||
return CWMP_GEN_ERR;
|
||||
|
||||
if (strftime(local_time, sizeof(local_time), "%FT%T%z", t_tm) == 0)
|
||||
return CWMP_GEN_ERR;
|
||||
|
||||
|
||||
local_time[25] = local_time[24];
|
||||
local_time[24] = local_time[23];
|
||||
local_time[22] = ':';
|
||||
local_time[26] = '\0';
|
||||
|
||||
CWMP_LOG(INFO,periodic_time?"Periodic time is %s":"Periodic time is Unknown", local_time);
|
||||
pthread_mutex_unlock (&(cwmp->mutex_periodic));
|
||||
pthread_cond_signal(&(cwmp->threshold_periodic));
|
||||
return CWMP_OK;
|
||||
|
||||
CWMP_LOG(INFO, periodic_time ? "Periodic time is %s" : "Periodic time is Unknown", local_time);
|
||||
pthread_mutex_unlock(&(cwmp->mutex_periodic));
|
||||
pthread_cond_signal(&(cwmp->threshold_periodic));
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
void connection_request_ip_value_change(struct cwmp *cwmp, int version)
|
||||
|
|
@ -474,19 +449,19 @@ void connection_request_ip_value_change(struct cwmp *cwmp, int version)
|
|||
return;
|
||||
}
|
||||
if (strcmp(bip, ip_value) != 0) {
|
||||
pthread_mutex_lock (&(cwmp->mutex_session_queue));
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_4VALUE_CHANGE, "");
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_queue));
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, "");
|
||||
if (event_container == NULL) {
|
||||
FREE(bip);
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
FREE(ip_version);
|
||||
FREE(ip_value);
|
||||
return;
|
||||
}
|
||||
cwmp_save_event_container (event_container);
|
||||
cwmp_save_event_container(event_container);
|
||||
bkp_session_simple_insert_in_parent("connection_request", ip_version, ip_value);
|
||||
bkp_session_save();
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
pthread_cond_signal(&(cwmp->threshold_session_send));
|
||||
}
|
||||
FREE(bip);
|
||||
|
|
@ -510,35 +485,35 @@ void connection_request_port_value_change(struct cwmp *cwmp, int port)
|
|||
return;
|
||||
}
|
||||
if (strcmp(bport, bufport) != 0) {
|
||||
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_4VALUE_CHANGE, "");
|
||||
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, "");
|
||||
if (event_container == NULL) {
|
||||
FREE(bport);
|
||||
return;
|
||||
}
|
||||
cwmp_save_event_container (event_container);
|
||||
cwmp_save_event_container(event_container);
|
||||
bkp_session_simple_insert_in_parent("connection_request", "port", bufport);
|
||||
bkp_session_save();
|
||||
}
|
||||
FREE(bport);
|
||||
}
|
||||
|
||||
int cwmp_root_cause_events (struct cwmp *cwmp)
|
||||
int cwmp_root_cause_events(struct cwmp *cwmp)
|
||||
{
|
||||
int error;
|
||||
int error;
|
||||
|
||||
if ((error = cwmp_root_cause_event_bootstrap(cwmp)))
|
||||
if ((error = cwmp_root_cause_event_bootstrap(cwmp)))
|
||||
return error;
|
||||
|
||||
if ((error = cwmp_root_cause_event_boot(cwmp)))
|
||||
return error;
|
||||
if ((error = cwmp_root_cause_event_boot(cwmp)))
|
||||
return error;
|
||||
|
||||
if ((error = cwmp_root_cause_getRPCMethod(cwmp)))
|
||||
return error;
|
||||
if ((error = cwmp_root_cause_getRPCMethod(cwmp)))
|
||||
return error;
|
||||
|
||||
if ((error = cwmp_root_cause_event_periodic(cwmp)))
|
||||
return error;
|
||||
if ((error = cwmp_root_cause_event_periodic(cwmp)))
|
||||
return error;
|
||||
|
||||
return CWMP_OK;
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int cwmp_get_int_event_code(char *code)
|
||||
|
|
|
|||
147
external.c
147
external.c
|
|
@ -36,43 +36,43 @@ static char *fc_script = "/usr/sbin/icwmp";
|
|||
|
||||
#define ICWMP_PROMPT "icwmp>"
|
||||
|
||||
void external_downloadFaultResp (char *fault_code)
|
||||
void external_downloadFaultResp(char *fault_code)
|
||||
{
|
||||
FREE(external_MethodFault);
|
||||
external_MethodFault = fault_code ? strdup(fault_code) : NULL;
|
||||
}
|
||||
|
||||
void external_fetch_downloadFaultResp (char **fault)
|
||||
void external_fetch_downloadFaultResp(char **fault)
|
||||
{
|
||||
*fault = external_MethodFault;
|
||||
external_MethodFault = NULL;
|
||||
}
|
||||
|
||||
void external_uploadFaultResp (char *fault_code)
|
||||
void external_uploadFaultResp(char *fault_code)
|
||||
{
|
||||
FREE(external_MethodFault);
|
||||
external_MethodFault = fault_code ? strdup(fault_code) : NULL;
|
||||
}
|
||||
|
||||
void external_fetch_uploadFaultResp (char **fault)
|
||||
void external_fetch_uploadFaultResp(char **fault)
|
||||
{
|
||||
*fault = external_MethodFault;
|
||||
external_MethodFault = NULL;
|
||||
}
|
||||
|
||||
void external_uninstallFaultResp (char *fault_code)
|
||||
void external_uninstallFaultResp(char *fault_code)
|
||||
{
|
||||
FREE(external_MethodFault);
|
||||
external_MethodFault = fault_code ? strdup(fault_code) : NULL;
|
||||
}
|
||||
|
||||
void external_fetch_uninstallFaultResp (char **fault)
|
||||
void external_fetch_uninstallFaultResp(char **fault)
|
||||
{
|
||||
*fault = external_MethodFault;
|
||||
external_MethodFault = NULL;
|
||||
}
|
||||
|
||||
void external_du_change_stateFaultResp (char *fault_code, char *version, char *name, char *uuid, char *env)
|
||||
void external_du_change_stateFaultResp(char *fault_code, char *version, char *name, char *uuid, char *env)
|
||||
{
|
||||
FREE(external_MethodFault);
|
||||
external_MethodFault = fault_code ? strdup(fault_code) : NULL;
|
||||
|
|
@ -101,44 +101,45 @@ void external_fetch_du_change_stateFaultResp(char **fault, char **version, char
|
|||
}
|
||||
static void external_read_pipe_input(int (*external_handler)(char *msg))
|
||||
{
|
||||
char buf[1], *value = NULL, *c = NULL;
|
||||
struct pollfd fd = {
|
||||
.fd = pfds_in[0],
|
||||
.events = POLLIN
|
||||
};
|
||||
while(1) {
|
||||
poll(&fd, 1, 500000);
|
||||
if (!(fd.revents & POLLIN)) break;
|
||||
if (read(pfds_in[0], buf, sizeof(buf))<=0) break;
|
||||
if (buf[0]!='\n') {
|
||||
char buf[1], *value = NULL, *c = NULL;
|
||||
struct pollfd fd = {.fd = pfds_in[0], .events = POLLIN };
|
||||
while (1) {
|
||||
poll(&fd, 1, 500000);
|
||||
if (!(fd.revents & POLLIN))
|
||||
break;
|
||||
if (read(pfds_in[0], buf, sizeof(buf)) <= 0)
|
||||
break;
|
||||
if (buf[0] != '\n') {
|
||||
if (value)
|
||||
asprintf(&c,"%s%c",value,buf[0]);
|
||||
asprintf(&c, "%s%c", value, buf[0]);
|
||||
else
|
||||
asprintf(&c,"%c",buf[0]);
|
||||
asprintf(&c, "%c", buf[0]);
|
||||
|
||||
FREE(value);
|
||||
value = c;
|
||||
} else {
|
||||
if (!value) continue;
|
||||
if (strcmp(value, ICWMP_PROMPT)==0) {
|
||||
FREE(value);
|
||||
break;
|
||||
}
|
||||
if(external_handler) external_handler(value);
|
||||
FREE(value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!value)
|
||||
continue;
|
||||
if (strcmp(value, ICWMP_PROMPT) == 0) {
|
||||
FREE(value);
|
||||
break;
|
||||
}
|
||||
if (external_handler)
|
||||
external_handler(value);
|
||||
FREE(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void external_write_pipe_output(const char *msg)
|
||||
{
|
||||
char *value = NULL;
|
||||
char *value = NULL;
|
||||
|
||||
asprintf(&value, "%s\n", msg);
|
||||
if (write(pfds_out[1], value, strlen(value)) == -1) {
|
||||
CWMP_LOG(ERROR,"Error occured when trying to write to the pipe");
|
||||
asprintf(&value, "%s\n", msg);
|
||||
if (write(pfds_out[1], value, strlen(value)) == -1) {
|
||||
CWMP_LOG(ERROR, "Error occured when trying to write to the pipe");
|
||||
}
|
||||
free(value);
|
||||
free(value);
|
||||
}
|
||||
|
||||
static void json_obj_out_add(json_object *json_obj_out, char *name, char *val)
|
||||
|
|
@ -152,7 +153,7 @@ static void json_obj_out_add(json_object *json_obj_out, char *name, char *val)
|
|||
void external_init()
|
||||
{
|
||||
if (pipe(pfds_in) < 0)
|
||||
return;
|
||||
return;
|
||||
|
||||
if (pipe(pfds_out) < 0)
|
||||
return;
|
||||
|
|
@ -172,10 +173,10 @@ void external_init()
|
|||
const char *argv[5];
|
||||
int i = 0;
|
||||
argv[i++] = "/bin/sh";
|
||||
argv[i++] = fc_script;
|
||||
argv[i++] = "json_continuous_input";
|
||||
argv[i++] = fc_script;
|
||||
argv[i++] = "json_continuous_input";
|
||||
argv[i++] = NULL;
|
||||
execvp(argv[0], (char **) argv);
|
||||
execvp(argv[0], (char **)argv);
|
||||
|
||||
close(pfds_out[0]);
|
||||
close(pfds_in[1]);
|
||||
|
|
@ -184,25 +185,24 @@ void external_init()
|
|||
}
|
||||
|
||||
close(pfds_in[1]);
|
||||
close(pfds_out[0]);
|
||||
close(pfds_out[0]);
|
||||
|
||||
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
|
||||
{
|
||||
DD(ERROR, "icwmp script intialization: signal ignoring error");
|
||||
}
|
||||
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
|
||||
DD(ERROR, "icwmp script intialization: signal ignoring error");
|
||||
}
|
||||
external_read_pipe_input(NULL);
|
||||
|
||||
DD(INFO, "icwmp script is listening");
|
||||
return;
|
||||
|
||||
error:
|
||||
CWMP_LOG(ERROR,"icwmp script intialization failed");
|
||||
CWMP_LOG(ERROR, "icwmp script intialization failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void external_exit()
|
||||
{
|
||||
int status;
|
||||
int status;
|
||||
|
||||
json_object *json_obj_out;
|
||||
|
||||
|
|
@ -219,7 +219,7 @@ void external_exit()
|
|||
}
|
||||
|
||||
close(pfds_in[0]);
|
||||
close(pfds_out[1]);
|
||||
close(pfds_out[1]);
|
||||
}
|
||||
|
||||
int external_handle_action(int (*external_handler)(char *msg))
|
||||
|
|
@ -236,7 +236,7 @@ int external_handle_action(int (*external_handler)(char *msg))
|
|||
|
||||
int external_simple(char *command, char *arg, int c)
|
||||
{
|
||||
DD(INFO,"executing %s request", command);
|
||||
DD(INFO, "executing %s request", command);
|
||||
|
||||
json_object *json_obj_out;
|
||||
|
||||
|
|
@ -258,23 +258,22 @@ int external_simple(char *command, char *arg, int c)
|
|||
|
||||
int external_download(char *url, char *size, char *type, char *user, char *pass, time_t c)
|
||||
{
|
||||
DD(INFO,"executing download url '%s'", url);
|
||||
DD(INFO, "executing download url '%s'", url);
|
||||
char *id = NULL;
|
||||
char *cert_path = NULL;
|
||||
struct config *conf;
|
||||
json_object *json_obj_out;
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
|
||||
conf = &(cwmp->conf);
|
||||
if (strncmp(url,DOWNLOAD_PROTOCOL_HTTPS,strlen(DOWNLOAD_PROTOCOL_HTTPS)) == 0)
|
||||
{
|
||||
if(conf->https_ssl_capath)
|
||||
if (strncmp(url, DOWNLOAD_PROTOCOL_HTTPS, strlen(DOWNLOAD_PROTOCOL_HTTPS)) == 0) {
|
||||
if (conf->https_ssl_capath)
|
||||
cert_path = strdup(conf->https_ssl_capath);
|
||||
else
|
||||
cert_path = NULL;
|
||||
}
|
||||
if(cert_path)
|
||||
CWMP_LOG(DEBUG,"https certif path %s", cert_path);
|
||||
if (cert_path)
|
||||
CWMP_LOG(DEBUG, "https certif path %s", cert_path);
|
||||
if (c)
|
||||
asprintf(&id, "%ld", c);
|
||||
/* send data to the script */
|
||||
|
|
@ -284,28 +283,28 @@ int external_download(char *url, char *size, char *type, char *user, char *pass,
|
|||
json_obj_out_add(json_obj_out, "url", url);
|
||||
json_obj_out_add(json_obj_out, "size", size);
|
||||
json_obj_out_add(json_obj_out, "type", type);
|
||||
if(user)
|
||||
if (user)
|
||||
json_obj_out_add(json_obj_out, "user", user);
|
||||
if(pass)
|
||||
if (pass)
|
||||
json_obj_out_add(json_obj_out, "pass", pass);
|
||||
if(id)
|
||||
if (id)
|
||||
json_obj_out_add(json_obj_out, "ids", id);
|
||||
if(cert_path)
|
||||
if (cert_path)
|
||||
json_obj_out_add(json_obj_out, "cert_path", cert_path);
|
||||
external_write_pipe_output(json_object_to_json_string(json_obj_out));
|
||||
|
||||
json_object_put(json_obj_out);
|
||||
|
||||
if(cert_path)
|
||||
if (cert_path)
|
||||
free(cert_path);
|
||||
if(id)
|
||||
if (id)
|
||||
free(id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int external_upload(char *url, char *type, char *user, char *pass, char *name)
|
||||
{
|
||||
DD(INFO,"executing download url '%s'", url);
|
||||
DD(INFO, "executing download url '%s'", url);
|
||||
|
||||
json_object *json_obj_out;
|
||||
|
||||
|
|
@ -316,8 +315,10 @@ int external_upload(char *url, char *type, char *user, char *pass, char *name)
|
|||
json_obj_out_add(json_obj_out, "url", url);
|
||||
json_obj_out_add(json_obj_out, "type", type);
|
||||
json_obj_out_add(json_obj_out, "name", name);
|
||||
if(user) json_obj_out_add(json_obj_out, "user", user);
|
||||
if(pass) json_obj_out_add(json_obj_out, "pass", pass);
|
||||
if (user)
|
||||
json_obj_out_add(json_obj_out, "user", user);
|
||||
if (pass)
|
||||
json_obj_out_add(json_obj_out, "pass", pass);
|
||||
|
||||
external_write_pipe_output(json_object_to_json_string(json_obj_out));
|
||||
|
||||
|
|
@ -328,7 +329,7 @@ int external_upload(char *url, char *type, char *user, char *pass, char *name)
|
|||
|
||||
int external_change_du_state_install(char *url, char *uuid, char *user, char *pass, char *env)
|
||||
{
|
||||
DD(INFO,"executing DU install");
|
||||
DD(INFO, "executing DU install");
|
||||
json_object *json_obj_out;
|
||||
|
||||
/* send data to the script */
|
||||
|
|
@ -354,7 +355,7 @@ int external_change_du_state_install(char *url, char *uuid, char *user, char *pa
|
|||
|
||||
int external_change_du_state_update(char *uuid, char *url, char *user, char *pass)
|
||||
{
|
||||
DD(INFO,"executing DU update");
|
||||
DD(INFO, "executing DU update");
|
||||
json_object *json_obj_out;
|
||||
|
||||
/* send data to the script */
|
||||
|
|
@ -377,7 +378,7 @@ int external_change_du_state_update(char *uuid, char *url, char *user, char *pas
|
|||
|
||||
int external_change_du_state_uninstall(char *name, char *env)
|
||||
{
|
||||
DD(INFO,"executing DU uninstall");
|
||||
DD(INFO, "executing DU uninstall");
|
||||
json_object *json_obj_out;
|
||||
|
||||
/* send data to the script */
|
||||
|
|
@ -397,12 +398,13 @@ int external_change_du_state_uninstall(char *name, char *env)
|
|||
|
||||
int external_apply(char *action, char *arg, time_t c)
|
||||
{
|
||||
DD(INFO,"executing apply %s", action);
|
||||
DD(INFO, "executing apply %s", action);
|
||||
|
||||
json_object *json_obj_out;
|
||||
char *id = NULL;
|
||||
|
||||
if (c) asprintf(&id, "%ld", c);
|
||||
if (c)
|
||||
asprintf(&id, "%ld", c);
|
||||
|
||||
/* send data to the script */
|
||||
json_obj_out = json_object_new_object();
|
||||
|
|
@ -412,16 +414,15 @@ int external_apply(char *action, char *arg, time_t c)
|
|||
if (arg)
|
||||
json_obj_out_add(json_obj_out, "arg", arg);
|
||||
|
||||
if(id)
|
||||
if (id)
|
||||
json_obj_out_add(json_obj_out, "ids", id);
|
||||
external_write_pipe_output(json_object_to_json_string(json_obj_out));
|
||||
|
||||
json_object_put(json_obj_out);
|
||||
|
||||
if(id) {
|
||||
if (id) {
|
||||
free(id);
|
||||
id= NULL;
|
||||
id = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
202
http.c
202
http.c
|
|
@ -49,13 +49,13 @@ int http_client_init(struct cwmp *cwmp)
|
|||
|
||||
if (dhcp_dis && cwmp->retry_count_session > 0 && strcmp(dhcp_dis, "enable") == 0) {
|
||||
uci_get_state_value(UCI_DHCP_ACS_URL, &acs_var_stat);
|
||||
if(acs_var_stat){
|
||||
if (acs_var_stat) {
|
||||
if (asprintf(&http_c.url, "%s", acs_var_stat) == -1) {
|
||||
free(acs_var_stat);
|
||||
free(dhcp_dis);
|
||||
return -1;
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
if (asprintf(&http_c.url, "%s", cwmp->conf.acsurl) == -1) {
|
||||
free(dhcp_dis);
|
||||
return -1;
|
||||
|
|
@ -63,13 +63,13 @@ int http_client_init(struct cwmp *cwmp)
|
|||
}
|
||||
} else {
|
||||
if (asprintf(&http_c.url, "%s", cwmp->conf.acsurl) == -1) {
|
||||
if(dhcp_dis)
|
||||
if (dhcp_dis)
|
||||
free(dhcp_dis);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(dhcp_dis)
|
||||
if (dhcp_dis)
|
||||
free(dhcp_dis);
|
||||
|
||||
CWMP_LOG(INFO, "ACS url: %s", http_c.url);
|
||||
|
|
@ -78,21 +78,22 @@ int http_client_init(struct cwmp *cwmp)
|
|||
|
||||
curl_global_init(CURL_GLOBAL_SSL);
|
||||
curl = curl_easy_init();
|
||||
if (!curl) return -1;
|
||||
if (!curl)
|
||||
return -1;
|
||||
|
||||
if (cwmp->conf.ipv6_enable) {
|
||||
char *ip = NULL;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, http_c.url);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, HTTP_TIMEOUT);
|
||||
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
|
||||
curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip);
|
||||
curl_easy_perform(curl);
|
||||
int tmp = inet_pton(AF_INET, ip, buf);
|
||||
if (cwmp->conf.ipv6_enable) {
|
||||
char *ip = NULL;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, http_c.url);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, HTTP_TIMEOUT);
|
||||
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
|
||||
curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip);
|
||||
curl_easy_perform(curl);
|
||||
int tmp = inet_pton(AF_INET, ip, buf);
|
||||
|
||||
asprintf(&uci_cmd, "cwmp.acs.ip_version=%d", (tmp == 1) ? 4 : 6);
|
||||
uci_set_value(uci_cmd);
|
||||
free(uci_cmd);
|
||||
}
|
||||
asprintf(&uci_cmd, "cwmp.acs.ip_version=%d", (tmp == 1) ? 4 : 6);
|
||||
uci_set_value(uci_cmd);
|
||||
free(uci_cmd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -110,8 +111,7 @@ void http_client_exit(void)
|
|||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
static size_t
|
||||
http_get_response(void *buffer, size_t size, size_t rxed, char **msg_in)
|
||||
static size_t http_get_response(void *buffer, size_t size, size_t rxed, char **msg_in)
|
||||
{
|
||||
char *c;
|
||||
|
||||
|
|
@ -126,91 +126,94 @@ http_get_response(void *buffer, size_t size, size_t rxed, char **msg_in)
|
|||
return size * rxed;
|
||||
}
|
||||
|
||||
int
|
||||
http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len,char **msg_in)
|
||||
int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **msg_in)
|
||||
{
|
||||
unsigned char buf[sizeof(struct in6_addr)];
|
||||
int tmp = 0;
|
||||
CURLcode res;
|
||||
long http_code = 0;
|
||||
static char ip_acs[128] = {0};
|
||||
static char ip_acs[128] = { 0 };
|
||||
char *ip = NULL;
|
||||
char errbuf[CURL_ERROR_SIZE];
|
||||
|
||||
http_c.header_list = NULL;
|
||||
http_c.header_list = curl_slist_append(http_c.header_list, "User-Agent: iopsys-cwmp");
|
||||
if (!http_c.header_list) return -1;
|
||||
if (!http_c.header_list)
|
||||
return -1;
|
||||
http_c.header_list = curl_slist_append(http_c.header_list, "Content-Type: text/xml");
|
||||
if (!http_c.header_list) return -1;
|
||||
# ifdef ACS_FUSION
|
||||
if (!http_c.header_list)
|
||||
return -1;
|
||||
#ifdef ACS_FUSION
|
||||
char *expect_header = "Expect:";
|
||||
http_c.header_list = curl_slist_append(http_c.header_list, expect_header);
|
||||
if (!http_c.header_list) return -1;
|
||||
# endif /* ACS_FUSION */
|
||||
if (cwmp->conf.http_disable_100continue)
|
||||
{
|
||||
if (!http_c.header_list)
|
||||
return -1;
|
||||
#endif /* ACS_FUSION */
|
||||
if (cwmp->conf.http_disable_100continue) {
|
||||
char *expect_header = "Expect:";
|
||||
http_c.header_list = curl_slist_append(http_c.header_list, expect_header);
|
||||
if (!http_c.header_list) return -1;
|
||||
if (!http_c.header_list)
|
||||
return -1;
|
||||
}
|
||||
curl_easy_setopt(curl, CURLOPT_URL, http_c.url);
|
||||
curl_easy_setopt(curl, CURLOPT_USERNAME, cwmp->conf.acs_userid);
|
||||
curl_easy_setopt(curl, CURLOPT_PASSWORD, cwmp->conf.acs_passwd);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, HTTP_TIMEOUT);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, HTTP_TIMEOUT);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
|
||||
curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
|
||||
switch (cwmp->conf.compression) {
|
||||
case COMP_NONE:
|
||||
break;
|
||||
case COMP_GZIP:
|
||||
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "gzip");
|
||||
http_c.header_list = curl_slist_append(http_c.header_list, "Content-Encoding: gzip");
|
||||
break;
|
||||
case COMP_DEFLATE:
|
||||
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "deflate");
|
||||
http_c.header_list = curl_slist_append(http_c.header_list, "Content-Encoding: deflate");
|
||||
break;
|
||||
case COMP_NONE:
|
||||
break;
|
||||
case COMP_GZIP:
|
||||
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "gzip");
|
||||
http_c.header_list = curl_slist_append(http_c.header_list, "Content-Encoding: gzip");
|
||||
break;
|
||||
case COMP_DEFLATE:
|
||||
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "deflate");
|
||||
http_c.header_list = curl_slist_append(http_c.header_list, "Content-Encoding: deflate");
|
||||
break;
|
||||
}
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_c.header_list);
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, msg_out);
|
||||
if (msg_out)
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) msg_out_len);
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)msg_out_len);
|
||||
else
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, http_get_response);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, msg_in);
|
||||
|
||||
# ifdef DEVEL
|
||||
#ifdef DEVEL
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
# endif
|
||||
#endif
|
||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, fc_cookies);
|
||||
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, fc_cookies);
|
||||
|
||||
|
||||
if (cwmp->conf.acs_ssl_capath)
|
||||
curl_easy_setopt(curl, CURLOPT_CAPATH, cwmp->conf.acs_ssl_capath);
|
||||
curl_easy_setopt(curl, CURLOPT_CAPATH, cwmp->conf.acs_ssl_capath);
|
||||
if (cwmp->conf.insecure_enable) {
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
}
|
||||
uci_get_value(UCI_CPE_INTERFACE_PATH, &(cwmp->conf.interface));
|
||||
curl_easy_setopt(curl, CURLOPT_INTERFACE, cwmp->conf.interface);
|
||||
*msg_in = (char *) calloc (1, sizeof(char));
|
||||
*msg_in = (char *)calloc(1, sizeof(char));
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(res != CURLE_OK) {
|
||||
if (res != CURLE_OK) {
|
||||
size_t len = strlen(errbuf);
|
||||
if(len) {
|
||||
if (errbuf[len - 1] == '\n') errbuf[len - 1] = '\0';
|
||||
CWMP_LOG(ERROR,"libcurl: (%d) %s", res, errbuf);
|
||||
if (len) {
|
||||
if (errbuf[len - 1] == '\n')
|
||||
errbuf[len - 1] = '\0';
|
||||
CWMP_LOG(ERROR, "libcurl: (%d) %s", res, errbuf);
|
||||
} else {
|
||||
CWMP_LOG(ERROR,"libcurl: (%d) %s", res, curl_easy_strerror(res));
|
||||
CWMP_LOG(ERROR, "libcurl: (%d) %s", res, curl_easy_strerror(res));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -235,13 +238,11 @@ http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len,char **msg_i
|
|||
}
|
||||
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
||||
if(http_code == 204)
|
||||
{
|
||||
CWMP_LOG (INFO,"Receive HTTP 204 No Content");
|
||||
if (http_code == 204) {
|
||||
CWMP_LOG(INFO, "Receive HTTP 204 No Content");
|
||||
}
|
||||
|
||||
if(http_code == 415)
|
||||
{
|
||||
if (http_code == 415) {
|
||||
cwmp->conf.compression = COMP_NONE;
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -255,7 +256,8 @@ http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len,char **msg_i
|
|||
http_c.header_list = NULL;
|
||||
}
|
||||
|
||||
if (res) goto error;
|
||||
if (res)
|
||||
goto error;
|
||||
|
||||
return 0;
|
||||
|
||||
|
|
@ -270,10 +272,10 @@ error:
|
|||
|
||||
void http_success_cr()
|
||||
{
|
||||
CWMP_LOG(INFO,"Connection Request thread: add connection request event in the queue");
|
||||
pthread_mutex_lock (&(cwmp_main.mutex_session_queue));
|
||||
CWMP_LOG(INFO, "Connection Request thread: add connection request event in the queue");
|
||||
pthread_mutex_lock(&(cwmp_main.mutex_session_queue));
|
||||
cwmp_add_event_container(&cwmp_main, EVENT_IDX_6CONNECTION_REQUEST, "");
|
||||
pthread_mutex_unlock (&(cwmp_main.mutex_session_queue));
|
||||
pthread_mutex_unlock(&(cwmp_main.mutex_session_queue));
|
||||
pthread_cond_signal(&(cwmp_main.threshold_session_send));
|
||||
}
|
||||
|
||||
|
|
@ -283,7 +285,7 @@ static void http_cr_new_client(int client, bool service_available)
|
|||
char buffer[BUFSIZ];
|
||||
int8_t auth_status = 0;
|
||||
|
||||
pthread_mutex_lock (&mutex_config_load);
|
||||
pthread_mutex_lock(&mutex_config_load);
|
||||
fp = fdopen(client, "r+");
|
||||
|
||||
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||
|
|
@ -308,25 +310,25 @@ static void http_cr_new_client(int client, bool service_available)
|
|||
goto http_end;
|
||||
}
|
||||
}
|
||||
if(!service_available) {
|
||||
if (!service_available) {
|
||||
goto http_end;
|
||||
}
|
||||
goto http_done;
|
||||
|
||||
http_end:
|
||||
http_end:
|
||||
if (!service_available) {
|
||||
CWMP_LOG (INFO,"Receive Connection Request: Return 503 Service Unavailable");
|
||||
CWMP_LOG(INFO, "Receive Connection Request: Return 503 Service Unavailable");
|
||||
fputs("HTTP/1.1 503 Service Unavailable\r\n", fp);
|
||||
fputs("Connection: close\r\n", fp);
|
||||
fputs("Content-Length: 0\r\n", fp);
|
||||
} else if (auth_status) {
|
||||
CWMP_LOG (INFO,"Receive Connection Request: success authentication");
|
||||
CWMP_LOG(INFO, "Receive Connection Request: success authentication");
|
||||
fputs("HTTP/1.1 200 OK\r\n", fp);
|
||||
fputs("Connection: close\r\n", fp);
|
||||
fputs("Content-Length: 0\r\n", fp);
|
||||
http_success_cr();
|
||||
} else {
|
||||
CWMP_LOG (INFO,"Receive Connection Request: Return 401 Unauthorized");
|
||||
CWMP_LOG(INFO, "Receive Connection Request: Return 401 Unauthorized");
|
||||
fputs("HTTP/1.1 401 Unauthorized\r\n", fp);
|
||||
fputs("Connection: close\r\n", fp);
|
||||
http_digest_auth_fail_response(fp, "GET", "/", REALM, OPAQUE);
|
||||
|
|
@ -334,24 +336,23 @@ static void http_cr_new_client(int client, bool service_available)
|
|||
}
|
||||
fputs("\r\n", fp);
|
||||
|
||||
http_done:
|
||||
http_done:
|
||||
fclose(fp);
|
||||
pthread_mutex_unlock (&mutex_config_load);
|
||||
pthread_mutex_unlock(&mutex_config_load);
|
||||
}
|
||||
|
||||
void http_server_init(void)
|
||||
{
|
||||
struct sockaddr_in6 server = {0};
|
||||
struct sockaddr_in6 server = { 0 };
|
||||
unsigned short cr_port;
|
||||
|
||||
for(;;) {
|
||||
cr_port = (unsigned short) (cwmp_main.conf.connection_request_port);
|
||||
unsigned short i = (DEFAULT_CONNECTION_REQUEST_PORT == cr_port)? 1 : 0;
|
||||
for (;;) {
|
||||
cr_port = (unsigned short)(cwmp_main.conf.connection_request_port);
|
||||
unsigned short i = (DEFAULT_CONNECTION_REQUEST_PORT == cr_port) ? 1 : 0;
|
||||
//Create socket
|
||||
cwmp_main.cr_socket_desc = socket(AF_INET6 , SOCK_STREAM , 0);
|
||||
if (cwmp_main.cr_socket_desc == -1)
|
||||
{
|
||||
CWMP_LOG (ERROR,"Could not open server socket for Connection Requests, Error no is : %d, Error description is : %s", errno, strerror(errno));
|
||||
cwmp_main.cr_socket_desc = socket(AF_INET6, SOCK_STREAM, 0);
|
||||
if (cwmp_main.cr_socket_desc == -1) {
|
||||
CWMP_LOG(ERROR, "Could not open server socket for Connection Requests, Error no is : %d, Error description is : %s", errno, strerror(errno));
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -359,24 +360,22 @@ void http_server_init(void)
|
|||
fcntl(cwmp_main.cr_socket_desc, F_SETFD, fcntl(cwmp_main.cr_socket_desc, F_GETFD) | FD_CLOEXEC);
|
||||
|
||||
int reusaddr = 1;
|
||||
if (setsockopt(cwmp_main.cr_socket_desc, SOL_SOCKET, SO_REUSEADDR, &reusaddr, sizeof(int)) < 0)
|
||||
{
|
||||
CWMP_LOG (WARNING,"setsockopt(SO_REUSEADDR) failed");
|
||||
if (setsockopt(cwmp_main.cr_socket_desc, SOL_SOCKET, SO_REUSEADDR, &reusaddr, sizeof(int)) < 0) {
|
||||
CWMP_LOG(WARNING, "setsockopt(SO_REUSEADDR) failed");
|
||||
}
|
||||
|
||||
//Prepare the sockaddr_in structure
|
||||
server.sin6_family = AF_INET6;
|
||||
server.sin6_addr=in6addr_any;
|
||||
|
||||
for(;;i++) {
|
||||
server.sin6_addr = in6addr_any;
|
||||
|
||||
for (;; i++) {
|
||||
server.sin6_port = htons(cr_port);
|
||||
//Bind
|
||||
if( bind(cwmp_main.cr_socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0)
|
||||
{
|
||||
if (bind(cwmp_main.cr_socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) {
|
||||
//print the error message
|
||||
CWMP_LOG (ERROR,"Could not bind server socket on the port %d, Error no is : %d, Error description is : %s", cr_port, errno, strerror(errno));
|
||||
CWMP_LOG(ERROR, "Could not bind server socket on the port %d, Error no is : %d, Error description is : %s", cr_port, errno, strerror(errno));
|
||||
cr_port = DEFAULT_CONNECTION_REQUEST_PORT + i;
|
||||
CWMP_LOG (INFO,"Trying to use another connection request port: %d", cr_port);
|
||||
CWMP_LOG(INFO, "Trying to use another connection request port: %d", cr_port);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
|
@ -384,15 +383,15 @@ void http_server_init(void)
|
|||
break;
|
||||
}
|
||||
char buf[64];
|
||||
sprintf(buf,UCI_CPE_PORT_PATH"=%d", cr_port);
|
||||
sprintf(buf, UCI_CPE_PORT_PATH "=%d", cr_port);
|
||||
uci_set_state_value(buf);
|
||||
connection_request_port_value_change(&cwmp_main, cr_port);
|
||||
CWMP_LOG (INFO,"Connection Request server initiated with the port: %d", cr_port);
|
||||
CWMP_LOG(INFO, "Connection Request server initiated with the port: %d", cr_port);
|
||||
}
|
||||
|
||||
void http_server_listen(void)
|
||||
{
|
||||
int client_sock , c;
|
||||
int client_sock, c;
|
||||
static int cr_request = 0;
|
||||
static time_t restrict_start_time = 0;
|
||||
time_t current_time;
|
||||
|
|
@ -400,25 +399,19 @@ void http_server_listen(void)
|
|||
struct sockaddr_in6 client;
|
||||
|
||||
//Listen
|
||||
listen(cwmp_main.cr_socket_desc , 3);
|
||||
listen(cwmp_main.cr_socket_desc, 3);
|
||||
|
||||
//Accept and incoming connection
|
||||
c = sizeof(struct sockaddr_in);
|
||||
while( (client_sock = accept(cwmp_main.cr_socket_desc, (struct sockaddr *)&client, (socklen_t*)&c)) )
|
||||
{
|
||||
while ((client_sock = accept(cwmp_main.cr_socket_desc, (struct sockaddr *)&client, (socklen_t *)&c))) {
|
||||
current_time = time(NULL);
|
||||
service_available = true;
|
||||
if ((restrict_start_time==0) ||
|
||||
((current_time-restrict_start_time) > CONNECTION_REQUEST_RESTRICT_PERIOD))
|
||||
{
|
||||
if ((restrict_start_time == 0) || ((current_time - restrict_start_time) > CONNECTION_REQUEST_RESTRICT_PERIOD)) {
|
||||
restrict_start_time = current_time;
|
||||
cr_request = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
cr_request = 1;
|
||||
} else {
|
||||
cr_request++;
|
||||
if (cr_request > CONNECTION_REQUEST_RESTRICT_REQUEST)
|
||||
{
|
||||
if (cr_request > CONNECTION_REQUEST_RESTRICT_REQUEST) {
|
||||
restrict_start_time = current_time;
|
||||
service_available = false;
|
||||
}
|
||||
|
|
@ -427,9 +420,8 @@ void http_server_listen(void)
|
|||
close(client_sock);
|
||||
}
|
||||
|
||||
if (client_sock < 0)
|
||||
{
|
||||
CWMP_LOG(ERROR,"Could not accept connections for Connection Requests!");
|
||||
if (client_sock < 0) {
|
||||
CWMP_LOG(ERROR, "Could not accept connections for Connection Requests!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,23 +16,17 @@
|
|||
#include <microxml.h>
|
||||
#include "common.h"
|
||||
|
||||
#define RPC_NO_STATUS -1
|
||||
#define RPC_QUEUE 0
|
||||
#define RPC_SEND 1
|
||||
#define RPC_NO_STATUS -1
|
||||
#define RPC_QUEUE 0
|
||||
#define RPC_SEND 1
|
||||
|
||||
# define CWMP_BACKUP_SESSION "<cwmp></cwmp>"
|
||||
#define CWMP_BACKUP_SESSION "<cwmp></cwmp>"
|
||||
#define CWMP_BKP_FILE "/etc/icwmpd/.icwmpd_backup_session.xml"
|
||||
typedef enum backup_loading {
|
||||
ALL,
|
||||
ACS,
|
||||
CR_IP,
|
||||
CR_IPv6,
|
||||
CR_PORT
|
||||
} backup_loading;
|
||||
typedef enum backup_loading { ALL, ACS, CR_IP, CR_IPv6, CR_PORT } backup_loading;
|
||||
|
||||
struct search_keywords {
|
||||
char *name;
|
||||
char *value;
|
||||
char *name;
|
||||
char *value;
|
||||
};
|
||||
|
||||
extern pthread_mutex_t mutex_backup_session;
|
||||
|
|
@ -45,10 +39,10 @@ void bkp_session_delete_event(int id, char *status);
|
|||
void bkp_session_simple_insert_in_parent(char *parent, char *child, char *value);
|
||||
void bkp_session_insert_parameter(mxml_node_t *b, char *name);
|
||||
void bkp_session_simple_insert(char *parent, char *child, char *value);
|
||||
void bkp_session_move_inform_to_inform_send ();
|
||||
void bkp_session_move_inform_to_inform_queue ();
|
||||
void bkp_session_insert_schedule_inform(time_t schedule_time,char *command_key);
|
||||
void bkp_session_delete_schedule_inform(time_t schedule_time,char *command_key);
|
||||
void bkp_session_move_inform_to_inform_send();
|
||||
void bkp_session_move_inform_to_inform_queue();
|
||||
void bkp_session_insert_schedule_inform(time_t schedule_time, char *command_key);
|
||||
void bkp_session_delete_schedule_inform(time_t schedule_time, char *command_key);
|
||||
void bkp_session_insert_download(struct download *pdownload);
|
||||
void bkp_session_delete_download(struct download *pdownload);
|
||||
void bkp_session_insert_upload(struct upload *pupload);
|
||||
|
|
|
|||
401
inc/common.h
401
inc/common.h
|
|
@ -27,66 +27,66 @@
|
|||
|
||||
#define ARRAYSIZEOF(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
||||
#define MAX_EVENTS 64
|
||||
#define MAX_INT32 2147483646
|
||||
#define MAX_INT_ID MAX_INT32
|
||||
#define MIN_INT_ID 836464
|
||||
#define PERIOD_INFORM_MIN 60
|
||||
#define PERIOD_INFORM_DEFAULT 86400
|
||||
#define CONNECTION_REQUEST_RESTRICT_PERIOD 5
|
||||
#define CONNECTION_REQUEST_RESTRICT_REQUEST 50
|
||||
#define DEFAULT_CONNECTION_REQUEST_PORT 7547
|
||||
#define DEFAULT_NOTIFY_PERIOD 10
|
||||
#define DEFAULT_LWN_PORT 7547
|
||||
#define MAX_EVENTS 64
|
||||
#define MAX_INT32 2147483646
|
||||
#define MAX_INT_ID MAX_INT32
|
||||
#define MIN_INT_ID 836464
|
||||
#define PERIOD_INFORM_MIN 60
|
||||
#define PERIOD_INFORM_DEFAULT 86400
|
||||
#define CONNECTION_REQUEST_RESTRICT_PERIOD 5
|
||||
#define CONNECTION_REQUEST_RESTRICT_REQUEST 50
|
||||
#define DEFAULT_CONNECTION_REQUEST_PORT 7547
|
||||
#define DEFAULT_NOTIFY_PERIOD 10
|
||||
#define DEFAULT_LWN_PORT 7547
|
||||
#define DEFAULT_RETRY_MINIMUM_WAIT_INTERVAL 5
|
||||
#define DEFAULT_RETRY_INITIAL_INTERVAL 60
|
||||
#define DEFAULT_RETRY_INTERVAL_MULTIPLIER 2000
|
||||
#define DEFAULT_RETRY_MAX_INTERVAL 60
|
||||
#define DEFAULT_AMD_VERSION 5
|
||||
#define DEFAULT_INSTANCE_MODE 0
|
||||
#define DEFAULT_SESSION_TIMEOUT 60
|
||||
#define DEFAULT_ACSURL "http://192.168.1.1:8080/openacs/acs"
|
||||
#define DEFAULT_RETRY_INITIAL_INTERVAL 60
|
||||
#define DEFAULT_RETRY_INTERVAL_MULTIPLIER 2000
|
||||
#define DEFAULT_RETRY_MAX_INTERVAL 60
|
||||
#define DEFAULT_AMD_VERSION 5
|
||||
#define DEFAULT_INSTANCE_MODE 0
|
||||
#define DEFAULT_SESSION_TIMEOUT 60
|
||||
#define DEFAULT_ACSURL "http://192.168.1.1:8080/openacs/acs"
|
||||
|
||||
extern char *commandKey;
|
||||
|
||||
typedef struct env {
|
||||
unsigned short boot;
|
||||
unsigned short periodic;
|
||||
long int max_firmware_size;
|
||||
unsigned short boot;
|
||||
unsigned short periodic;
|
||||
long int max_firmware_size;
|
||||
} env;
|
||||
|
||||
typedef struct config {
|
||||
char *acsurl;
|
||||
char *acs_userid;
|
||||
char *acs_passwd;
|
||||
char *acs_ssl_capath;
|
||||
char *acs_ssl_version;
|
||||
char *https_ssl_capath;
|
||||
char *cpe_userid;
|
||||
char *cpe_passwd;
|
||||
char *ip;
|
||||
char *ipv6;
|
||||
char *interface;
|
||||
char *ubus_socket;
|
||||
int connection_request_port;
|
||||
int period;
|
||||
int periodic_notify_interval;
|
||||
int compression;
|
||||
time_t time;
|
||||
bool periodic_enable;
|
||||
bool periodic_notify_enable;
|
||||
bool insecure_enable;
|
||||
bool ipv6_enable;
|
||||
int retry_min_wait_interval;
|
||||
int retry_interval_multiplier;
|
||||
bool lw_notification_enable;
|
||||
char *lw_notification_hostname;
|
||||
int lw_notification_port;
|
||||
int amd_version;
|
||||
int supported_amd_version;
|
||||
unsigned int instance_mode;
|
||||
unsigned int session_timeout;
|
||||
bool http_disable_100continue;
|
||||
char *acsurl;
|
||||
char *acs_userid;
|
||||
char *acs_passwd;
|
||||
char *acs_ssl_capath;
|
||||
char *acs_ssl_version;
|
||||
char *https_ssl_capath;
|
||||
char *cpe_userid;
|
||||
char *cpe_passwd;
|
||||
char *ip;
|
||||
char *ipv6;
|
||||
char *interface;
|
||||
char *ubus_socket;
|
||||
int connection_request_port;
|
||||
int period;
|
||||
int periodic_notify_interval;
|
||||
int compression;
|
||||
time_t time;
|
||||
bool periodic_enable;
|
||||
bool periodic_notify_enable;
|
||||
bool insecure_enable;
|
||||
bool ipv6_enable;
|
||||
int retry_min_wait_interval;
|
||||
int retry_interval_multiplier;
|
||||
bool lw_notification_enable;
|
||||
char *lw_notification_hostname;
|
||||
int lw_notification_port;
|
||||
int amd_version;
|
||||
int supported_amd_version;
|
||||
unsigned int instance_mode;
|
||||
unsigned int session_timeout;
|
||||
bool http_disable_100continue;
|
||||
} config;
|
||||
|
||||
struct deviceid {
|
||||
|
|
@ -98,38 +98,38 @@ struct deviceid {
|
|||
};
|
||||
|
||||
typedef struct session_status {
|
||||
time_t last_start_time;
|
||||
time_t last_end_time;
|
||||
int last_status;
|
||||
time_t next_periodic;
|
||||
time_t next_retry;
|
||||
unsigned int success_session;
|
||||
unsigned int failure_session;
|
||||
time_t last_start_time;
|
||||
time_t last_end_time;
|
||||
int last_status;
|
||||
time_t next_periodic;
|
||||
time_t next_retry;
|
||||
unsigned int success_session;
|
||||
unsigned int failure_session;
|
||||
} session_status;
|
||||
|
||||
typedef struct cwmp {
|
||||
struct env env;
|
||||
struct config conf;
|
||||
struct deviceid deviceid;
|
||||
struct list_head head_session_queue;
|
||||
pthread_mutex_t mutex_session_queue;
|
||||
struct session *session_send;
|
||||
bool cwmp_cr_event;
|
||||
pthread_mutex_t mutex_session_send;
|
||||
pthread_cond_t threshold_session_send;
|
||||
pthread_mutex_t mutex_periodic;
|
||||
pthread_mutex_t mutex_notify_periodic;
|
||||
pthread_cond_t threshold_periodic;
|
||||
pthread_cond_t threshold_notify_periodic;
|
||||
pthread_cond_t threshold_handle_notify;
|
||||
int count_handle_notify;
|
||||
int retry_count_session;
|
||||
struct list_head *head_event_container;
|
||||
int pid_file;
|
||||
time_t start_time;
|
||||
struct session_status session_status;
|
||||
unsigned int cwmp_id;
|
||||
int cr_socket_desc;
|
||||
struct env env;
|
||||
struct config conf;
|
||||
struct deviceid deviceid;
|
||||
struct list_head head_session_queue;
|
||||
pthread_mutex_t mutex_session_queue;
|
||||
struct session *session_send;
|
||||
bool cwmp_cr_event;
|
||||
pthread_mutex_t mutex_session_send;
|
||||
pthread_cond_t threshold_session_send;
|
||||
pthread_mutex_t mutex_periodic;
|
||||
pthread_mutex_t mutex_notify_periodic;
|
||||
pthread_cond_t threshold_periodic;
|
||||
pthread_cond_t threshold_notify_periodic;
|
||||
pthread_cond_t threshold_handle_notify;
|
||||
int count_handle_notify;
|
||||
int retry_count_session;
|
||||
struct list_head *head_event_container;
|
||||
int pid_file;
|
||||
time_t start_time;
|
||||
struct session_status session_status;
|
||||
unsigned int cwmp_id;
|
||||
int cr_socket_desc;
|
||||
} cwmp;
|
||||
|
||||
enum action
|
||||
|
|
@ -140,35 +140,39 @@ enum action
|
|||
RESTART,
|
||||
};
|
||||
|
||||
enum cwmp_start {
|
||||
CWMP_START_BOOT = 1,
|
||||
enum cwmp_start
|
||||
{
|
||||
CWMP_START_BOOT = 1,
|
||||
CWMP_START_PERIODIC = 2
|
||||
};
|
||||
|
||||
enum cwmp_ret_err {
|
||||
CWMP_OK, /* No Error */
|
||||
CWMP_GEN_ERR, /* General Error */
|
||||
CWMP_MEM_ERR, /* Memory Error */
|
||||
enum cwmp_ret_err
|
||||
{
|
||||
CWMP_OK, /* No Error */
|
||||
CWMP_GEN_ERR, /* General Error */
|
||||
CWMP_MEM_ERR, /* Memory Error */
|
||||
CWMP_MUTEX_ERR,
|
||||
CWMP_RETRY_SESSION
|
||||
};
|
||||
|
||||
enum http_compression {
|
||||
COMP_NONE,
|
||||
COMP_GZIP,
|
||||
COMP_DEFLATE
|
||||
enum http_compression
|
||||
{
|
||||
COMP_NONE,
|
||||
COMP_GZIP,
|
||||
COMP_DEFLATE
|
||||
};
|
||||
|
||||
enum enum_ip_version {
|
||||
IPv4 = 4,
|
||||
IPv6 = 6
|
||||
enum enum_ip_version
|
||||
{
|
||||
IPv4 = 4,
|
||||
IPv6 = 6
|
||||
};
|
||||
|
||||
typedef struct rpc {
|
||||
struct list_head list;
|
||||
int type;
|
||||
void *extra_data;
|
||||
struct list_head *list_set_value_fault;
|
||||
struct list_head list;
|
||||
int type;
|
||||
void *extra_data;
|
||||
struct list_head *list_set_value_fault;
|
||||
} rpc;
|
||||
|
||||
struct cwmp_param_fault {
|
||||
|
|
@ -190,7 +194,8 @@ struct cwmp_dm_parameter {
|
|||
char *type;
|
||||
};
|
||||
|
||||
enum amd_version_enum {
|
||||
enum amd_version_enum
|
||||
{
|
||||
AMD_1 = 1,
|
||||
AMD_2,
|
||||
AMD_3,
|
||||
|
|
@ -198,13 +203,13 @@ enum amd_version_enum {
|
|||
AMD_5,
|
||||
};
|
||||
|
||||
enum instance_mode {
|
||||
enum instance_mode
|
||||
{
|
||||
INSTANCE_MODE_NUMBER,
|
||||
INSTANCE_MODE_ALIAS
|
||||
};
|
||||
|
||||
struct cwmp_namespaces
|
||||
{
|
||||
struct cwmp_namespaces {
|
||||
char *soap_env;
|
||||
char *soap_enc;
|
||||
char *xsd;
|
||||
|
|
@ -212,7 +217,8 @@ struct cwmp_namespaces
|
|||
char *cwmp;
|
||||
} ns;
|
||||
|
||||
enum rpc_cpe_methods_idx {
|
||||
enum rpc_cpe_methods_idx
|
||||
{
|
||||
RPC_CPE_GET_RPC_METHODS = 1,
|
||||
RPC_CPE_SET_PARAMETER_VALUES,
|
||||
RPC_CPE_GET_PARAMETER_VALUES,
|
||||
|
|
@ -234,8 +240,8 @@ enum rpc_cpe_methods_idx {
|
|||
__RPC_CPE_MAX
|
||||
};
|
||||
|
||||
|
||||
enum rpc_acs_methods_idx {
|
||||
enum rpc_acs_methods_idx
|
||||
{
|
||||
RPC_ACS_INFORM = 1,
|
||||
RPC_ACS_GET_RPC_METHODS,
|
||||
RPC_ACS_TRANSFER_COMPLETE,
|
||||
|
|
@ -243,19 +249,22 @@ enum rpc_acs_methods_idx {
|
|||
__RPC_ACS_MAX
|
||||
};
|
||||
|
||||
enum load_type {
|
||||
enum load_type
|
||||
{
|
||||
TYPE_DOWNLOAD = 0,
|
||||
TYPE_SCHEDULE_DOWNLOAD,
|
||||
TYPE_UPLOAD
|
||||
};
|
||||
|
||||
enum dustate_type {
|
||||
enum dustate_type
|
||||
{
|
||||
DU_INSTALL = 1,
|
||||
DU_UPDATE,
|
||||
DU_UNINSTALL
|
||||
};
|
||||
|
||||
enum fault_cpe_idx {
|
||||
enum fault_cpe_idx
|
||||
{
|
||||
FAULT_CPE_NO_FAULT,
|
||||
FAULT_CPE_METHOD_NOT_SUPPORTED,
|
||||
FAULT_CPE_REQUEST_DENIED,
|
||||
|
|
@ -288,7 +297,8 @@ enum fault_cpe_idx {
|
|||
__FAULT_CPE_MAX
|
||||
};
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
FAULT_CPE_TYPE_CLIENT,
|
||||
FAULT_CPE_TYPE_SERVER
|
||||
};
|
||||
|
|
@ -306,125 +316,124 @@ struct rpc_acs_method {
|
|||
int (*extra_clean)(struct session *session, struct rpc *rpc);
|
||||
};
|
||||
|
||||
typedef struct FAULT_CPE
|
||||
{
|
||||
char *CODE;
|
||||
int ICODE;
|
||||
int TYPE;
|
||||
char *DESCRIPTION;
|
||||
typedef struct FAULT_CPE {
|
||||
char *CODE;
|
||||
int ICODE;
|
||||
int TYPE;
|
||||
char *DESCRIPTION;
|
||||
} FAULT_CPE;
|
||||
|
||||
typedef struct schedule_inform {
|
||||
struct list_head list;
|
||||
time_t scheduled_time;
|
||||
char *commandKey;
|
||||
struct list_head list;
|
||||
time_t scheduled_time;
|
||||
char *commandKey;
|
||||
} schedule_inform;
|
||||
|
||||
typedef struct download {
|
||||
struct list_head list;
|
||||
time_t scheduled_time;
|
||||
int file_size;
|
||||
char *command_key;
|
||||
char *file_type;
|
||||
char *url;
|
||||
char *username;
|
||||
char *password;
|
||||
struct list_head list;
|
||||
time_t scheduled_time;
|
||||
int file_size;
|
||||
char *command_key;
|
||||
char *file_type;
|
||||
char *url;
|
||||
char *username;
|
||||
char *password;
|
||||
} download;
|
||||
|
||||
typedef struct timewindow {
|
||||
time_t windowstart;
|
||||
time_t windowend;
|
||||
char *windowmode;
|
||||
char *usermessage;
|
||||
int maxretries;
|
||||
}timewindow;
|
||||
time_t windowstart;
|
||||
time_t windowend;
|
||||
char *windowmode;
|
||||
char *usermessage;
|
||||
int maxretries;
|
||||
} timewindow;
|
||||
|
||||
typedef struct timeinterval {
|
||||
time_t windowstart;
|
||||
time_t windowend;
|
||||
int maxretries;
|
||||
}timeinterval;
|
||||
time_t windowstart;
|
||||
time_t windowend;
|
||||
int maxretries;
|
||||
} timeinterval;
|
||||
|
||||
typedef struct schedule_download {
|
||||
struct list_head list;
|
||||
struct list_head list;
|
||||
//time_t scheduled_time;
|
||||
int file_size;
|
||||
char *command_key;
|
||||
char *file_type;
|
||||
char *url;
|
||||
char *username;
|
||||
char *password;
|
||||
struct timewindow timewindowstruct[2];
|
||||
int file_size;
|
||||
char *command_key;
|
||||
char *file_type;
|
||||
char *url;
|
||||
char *username;
|
||||
char *password;
|
||||
struct timewindow timewindowstruct[2];
|
||||
} schedule_download;
|
||||
|
||||
typedef struct apply_schedule_download {
|
||||
struct list_head list;
|
||||
char *start_time;
|
||||
char *command_key;
|
||||
char *file_type;
|
||||
struct timeinterval timeintervals[2];
|
||||
struct list_head list;
|
||||
char *start_time;
|
||||
char *command_key;
|
||||
char *file_type;
|
||||
struct timeinterval timeintervals[2];
|
||||
} apply_schedule_download;
|
||||
|
||||
typedef struct change_du_state {
|
||||
struct list_head list;
|
||||
time_t timeout;
|
||||
char *command_key;
|
||||
struct list_head list_operation;
|
||||
struct list_head list;
|
||||
time_t timeout;
|
||||
char *command_key;
|
||||
struct list_head list_operation;
|
||||
} change_du_state;
|
||||
|
||||
typedef struct operations {
|
||||
struct list_head list;
|
||||
int type;
|
||||
char *url;
|
||||
char *uuid;
|
||||
char *version;
|
||||
char *username;
|
||||
char *password;
|
||||
char *executionenvref;
|
||||
struct list_head list;
|
||||
int type;
|
||||
char *url;
|
||||
char *uuid;
|
||||
char *version;
|
||||
char *username;
|
||||
char *password;
|
||||
char *executionenvref;
|
||||
} operations;
|
||||
|
||||
typedef struct upload {
|
||||
struct list_head list;
|
||||
time_t scheduled_time;
|
||||
char *command_key;
|
||||
char *file_type;
|
||||
char *url;
|
||||
char *username;
|
||||
char *password;
|
||||
char *f_instance;
|
||||
struct list_head list;
|
||||
time_t scheduled_time;
|
||||
char *command_key;
|
||||
char *file_type;
|
||||
char *url;
|
||||
char *username;
|
||||
char *password;
|
||||
char *f_instance;
|
||||
} upload;
|
||||
|
||||
typedef struct transfer_complete {
|
||||
int fault_code;
|
||||
char *command_key;
|
||||
char *start_time;
|
||||
char *complete_time;
|
||||
char *old_software_version;
|
||||
int type;
|
||||
int fault_code;
|
||||
char *command_key;
|
||||
char *start_time;
|
||||
char *complete_time;
|
||||
char *old_software_version;
|
||||
int type;
|
||||
} transfer_complete;
|
||||
|
||||
typedef struct du_state_change_complete {
|
||||
char *command_key;
|
||||
time_t timeout;
|
||||
struct list_head list_opresult;
|
||||
char *command_key;
|
||||
time_t timeout;
|
||||
struct list_head list_opresult;
|
||||
} du_state_change_complete;
|
||||
|
||||
typedef struct opresult {
|
||||
struct list_head list;
|
||||
char *uuid;
|
||||
char *du_ref;
|
||||
char *version;
|
||||
char *current_state;
|
||||
bool resolved;
|
||||
char *execution_unit_ref;
|
||||
char *start_time;
|
||||
char *complete_time;
|
||||
int fault;
|
||||
struct list_head list;
|
||||
char *uuid;
|
||||
char *du_ref;
|
||||
char *version;
|
||||
char *current_state;
|
||||
bool resolved;
|
||||
char *execution_unit_ref;
|
||||
char *start_time;
|
||||
char *complete_time;
|
||||
int fault;
|
||||
} opresult;
|
||||
|
||||
typedef struct opfault {
|
||||
int fault_code;
|
||||
char *fault_string;
|
||||
int fault_code;
|
||||
char *fault_string;
|
||||
} opfault;
|
||||
|
||||
extern struct cwmp cwmp_main;
|
||||
|
|
@ -432,15 +441,21 @@ int cwmp_exit(void);
|
|||
void add_dm_parameter_tolist(struct list_head *head, char *param_name, char *param_data, char *param_type);
|
||||
void delete_dm_parameter_fromlist(struct cwmp_dm_parameter *dm_parameter);
|
||||
void free_dm_parameter_all_fromlist(struct list_head *list);
|
||||
int global_env_init (int argc, char** argv, struct env *env);
|
||||
int global_env_init(int argc, char **argv, struct env *env);
|
||||
void cwmp_add_list_fault_param(char *param, int fault, struct list_head *list_set_value_fault);
|
||||
void cwmp_del_list_fault_param(struct cwmp_param_fault *param_fault);
|
||||
void cwmp_add_list_param_value(char *param, char* value, struct list_head *list_param_value);
|
||||
void cwmp_add_list_param_value(char *param, char *value, struct list_head *list_param_value);
|
||||
void cwmp_del_list_param_value(struct cwmp_param_value *param_value);
|
||||
void cwmp_free_all_list_param_value(struct list_head *list_param_value);
|
||||
|
||||
#ifndef FREE
|
||||
#define FREE(x) do { if (x) {free(x); x = NULL;} } while (0)
|
||||
#define FREE(x) \
|
||||
do { \
|
||||
if (x) { \
|
||||
free(x); \
|
||||
x = NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@
|
|||
#include <pthread.h>
|
||||
#include "common.h"
|
||||
|
||||
extern pthread_mutex_t mutex_config_load;
|
||||
extern pthread_mutex_t mutex_config_load;
|
||||
|
||||
int get_amd_version_config();
|
||||
int get_instance_mode_config();
|
||||
int get_session_timeout_config();
|
||||
int cwmp_config_reload(struct cwmp *cwmp);
|
||||
int global_conf_init (struct config *conf);
|
||||
int global_conf_init(struct config *conf);
|
||||
int cwmp_get_deviceid(struct cwmp *cwmp);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -32,5 +32,5 @@
|
|||
#include "notifications.h"
|
||||
#include "cwmp_uci.h"
|
||||
|
||||
int cwmp_rpc_cpe_handle_message (struct session *session, struct rpc *rpc_cpe);
|
||||
int cwmp_rpc_cpe_handle_message(struct session *session, struct rpc *rpc_cpe);
|
||||
#endif /* _CWMP_H__ */
|
||||
|
|
|
|||
|
|
@ -20,7 +20,11 @@ struct cwmp_json_arg {
|
|||
};
|
||||
|
||||
#define CWMP_JSON_ARGS (struct cwmp_json_arg[])
|
||||
#define FREE_JSON(jobj) if (jobj) { json_object_put(jobj); jobj = NULL;}
|
||||
#define FREE_JSON(jobj) \
|
||||
if (jobj) { \
|
||||
json_object_put(jobj); \
|
||||
jobj = NULL; \
|
||||
}
|
||||
int cwmp_handle_downloadFault(char *msg);
|
||||
int cwmp_handle_uploadFault(char *msg);
|
||||
int cwmp_handle_dustate_changeFault(char *msg);
|
||||
|
|
@ -33,12 +37,12 @@ int cwmp_handle_setParamAttributes(char *msg);
|
|||
int cwmp_handle_addObject(char *msg);
|
||||
int cwmp_handle_delObject(char *msg);
|
||||
void cwmp_json_fprintf(FILE *fp, int argc, struct cwmp_json_arg cwmp_arg[]);
|
||||
void cwmp_json_get_string(json_object *obj, char* key, char** value);
|
||||
void cwmp_json_get_string(json_object *obj, char *key, char **value);
|
||||
void cwmp_json_obj_init(char *str, json_object **obj);
|
||||
void cwmp_json_obj_clean(json_object **obj);
|
||||
|
||||
#define foreach_jsonobj_in_array(param_obj, parameters) \
|
||||
#define foreach_jsonobj_in_array(param_obj, parameters) \
|
||||
int k, array_length = json_object_array_length(parameters); \
|
||||
for (k=0, param_obj = json_object_array_get_idx(parameters, 0); k< array_length; k++, param_obj = json_object_array_get_idx(parameters, k)) \
|
||||
for (k = 0, param_obj = json_object_array_get_idx(parameters, 0); k < array_length; k++, param_obj = json_object_array_get_idx(parameters, k))
|
||||
|
||||
#endif /* _JSHN_H__ */
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
#define NETLINK_MAX_PAYLOAD 1024
|
||||
#define NETLINK_USER 31
|
||||
#define NETLINK_CWMP_ID "NETLINK_CWMP_ID"
|
||||
#define NETLINK_END_DATA "END_DATA"
|
||||
#define NETLINK_NULL "NULL"
|
||||
#define NETLINK_MAX_PAYLOAD 1024
|
||||
#define NETLINK_USER 31
|
||||
#define NETLINK_CWMP_ID "NETLINK_CWMP_ID"
|
||||
#define NETLINK_END_DATA "END_DATA"
|
||||
#define NETLINK_NULL "NULL"
|
||||
|
||||
int kernel_api_cwmp_value_change_call (int count, ...);
|
||||
int kernel_api_cwmp_value_change_call(int count, ...);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
#ifndef CWMP_TIME_H_
|
||||
#define CWMP_TIME_H_
|
||||
|
||||
char * mix_get_time(void);
|
||||
char * mix_get_time_of(time_t t_time);
|
||||
char *mix_get_time(void);
|
||||
char *mix_get_time_of(time_t t_time);
|
||||
|
||||
#endif /* SRC_INC_CWMP_TIME_H_ */
|
||||
|
|
|
|||
106
inc/cwmp_uci.h
106
inc/cwmp_uci.h
|
|
@ -14,45 +14,44 @@
|
|||
|
||||
#include <uci.h>
|
||||
|
||||
|
||||
//struct uci_context *cwmp_uci_ctx = ((void *)0);
|
||||
#define UCI_DHCP_DISCOVERY_PATH "cwmp.acs.dhcp_discovery"
|
||||
#define UCI_ACS_URL_PATH "cwmp.acs.url"
|
||||
#define UCI_PERIODIC_INFORM_TIME_PATH "cwmp.acs.periodic_inform_time"
|
||||
#define UCI_PERIODIC_INFORM_INTERVAL_PATH "cwmp.acs.periodic_inform_interval"
|
||||
#define UCI_PERIODIC_INFORM_ENABLE_PATH "cwmp.acs.periodic_inform_enable"
|
||||
#define UCI_ACS_USERID_PATH "cwmp.acs.userid"
|
||||
#define UCI_ACS_PASSWD_PATH "cwmp.acs.passwd"
|
||||
#define UCI_ACS_PARAMETERKEY_PATH "cwmp.acs.ParameterKey"
|
||||
#define UCI_ACS_SSL_CAPATH "cwmp.acs.ssl_capath"
|
||||
#define UCI_HTTPS_SSL_CAPATH "cwmp.acs.https_ssl_capath"
|
||||
#define UCI_ACS_INSECURE_ENABLE "cwmp.acs.insecure_enable"
|
||||
#define UCI_ACS_IPV6_ENABLE "cwmp.acs.ipv6_enable"
|
||||
#define UCI_ACS_SSL_VERSION "cwmp.acs.ssl_version"
|
||||
#define UCI_ACS_COMPRESSION "cwmp.acs.compression"
|
||||
#define UCI_ACS_RETRY_MIN_WAIT_INTERVAL "cwmp.acs.retry_min_wait_interval"
|
||||
#define HTTP_DISABLE_100CONTINUE "cwmp.acs.http_disable_100continue"
|
||||
#define UCI_ACS_RETRY_INTERVAL_MULTIPLIER "cwmp.acs.retry_interval_multiplier"
|
||||
#define UCI_LOG_SEVERITY_PATH "cwmp.cpe.log_severity"
|
||||
#define UCI_CPE_USERID_PATH "cwmp.cpe.userid"
|
||||
#define UCI_CPE_PASSWD_PATH "cwmp.cpe.passwd"
|
||||
#define UCI_CPE_INTERFACE_PATH "cwmp.cpe.interface"
|
||||
#define UCI_CPE_UBUS_SOCKET_PATH "cwmp.cpe.ubus_socket"
|
||||
#define UCI_CPE_PORT_PATH "cwmp.cpe.port"
|
||||
#define UCI_CPE_LOG_FILE_NAME "cwmp.cpe.log_file_name"
|
||||
#define UCI_CPE_LOG_MAX_SIZE "cwmp.cpe.log_max_size"
|
||||
#define UCI_CPE_ENABLE_STDOUT_LOG "cwmp.cpe.log_to_console"
|
||||
#define UCI_CPE_ENABLE_FILE_LOG "cwmp.cpe.log_to_file"
|
||||
#define UCI_CPE_AMD_VERSION "cwmp.cpe.amd_version"
|
||||
#define UCI_CPE_INSTANCE_MODE "cwmp.cpe.instance_mode"
|
||||
#define UCI_CPE_SESSION_TIMEOUT "cwmp.cpe.session_timeout"
|
||||
#define UCI_CPE_EXEC_DOWNLOAD "cwmp.cpe.exec_download"
|
||||
#define UCI_CPE_NOTIFY_PERIODIC_ENABLE "cwmp.cpe.periodic_notify_enable"
|
||||
#define UCI_CPE_NOTIFY_PERIOD "cwmp.cpe.periodic_notify_interval"
|
||||
#define LW_NOTIFICATION_ENABLE "cwmp.lwn.enable"
|
||||
#define LW_NOTIFICATION_HOSTNAME "cwmp.lwn.hostname"
|
||||
#define LW_NOTIFICATION_PORT "cwmp.lwn.port"
|
||||
#define UCI_DHCP_ACS_URL "cwmp.acs.dhcp_url"
|
||||
#define UCI_DHCP_DISCOVERY_PATH "cwmp.acs.dhcp_discovery"
|
||||
#define UCI_ACS_URL_PATH "cwmp.acs.url"
|
||||
#define UCI_PERIODIC_INFORM_TIME_PATH "cwmp.acs.periodic_inform_time"
|
||||
#define UCI_PERIODIC_INFORM_INTERVAL_PATH "cwmp.acs.periodic_inform_interval"
|
||||
#define UCI_PERIODIC_INFORM_ENABLE_PATH "cwmp.acs.periodic_inform_enable"
|
||||
#define UCI_ACS_USERID_PATH "cwmp.acs.userid"
|
||||
#define UCI_ACS_PASSWD_PATH "cwmp.acs.passwd"
|
||||
#define UCI_ACS_PARAMETERKEY_PATH "cwmp.acs.ParameterKey"
|
||||
#define UCI_ACS_SSL_CAPATH "cwmp.acs.ssl_capath"
|
||||
#define UCI_HTTPS_SSL_CAPATH "cwmp.acs.https_ssl_capath"
|
||||
#define UCI_ACS_INSECURE_ENABLE "cwmp.acs.insecure_enable"
|
||||
#define UCI_ACS_IPV6_ENABLE "cwmp.acs.ipv6_enable"
|
||||
#define UCI_ACS_SSL_VERSION "cwmp.acs.ssl_version"
|
||||
#define UCI_ACS_COMPRESSION "cwmp.acs.compression"
|
||||
#define UCI_ACS_RETRY_MIN_WAIT_INTERVAL "cwmp.acs.retry_min_wait_interval"
|
||||
#define HTTP_DISABLE_100CONTINUE "cwmp.acs.http_disable_100continue"
|
||||
#define UCI_ACS_RETRY_INTERVAL_MULTIPLIER "cwmp.acs.retry_interval_multiplier"
|
||||
#define UCI_LOG_SEVERITY_PATH "cwmp.cpe.log_severity"
|
||||
#define UCI_CPE_USERID_PATH "cwmp.cpe.userid"
|
||||
#define UCI_CPE_PASSWD_PATH "cwmp.cpe.passwd"
|
||||
#define UCI_CPE_INTERFACE_PATH "cwmp.cpe.interface"
|
||||
#define UCI_CPE_UBUS_SOCKET_PATH "cwmp.cpe.ubus_socket"
|
||||
#define UCI_CPE_PORT_PATH "cwmp.cpe.port"
|
||||
#define UCI_CPE_LOG_FILE_NAME "cwmp.cpe.log_file_name"
|
||||
#define UCI_CPE_LOG_MAX_SIZE "cwmp.cpe.log_max_size"
|
||||
#define UCI_CPE_ENABLE_STDOUT_LOG "cwmp.cpe.log_to_console"
|
||||
#define UCI_CPE_ENABLE_FILE_LOG "cwmp.cpe.log_to_file"
|
||||
#define UCI_CPE_AMD_VERSION "cwmp.cpe.amd_version"
|
||||
#define UCI_CPE_INSTANCE_MODE "cwmp.cpe.instance_mode"
|
||||
#define UCI_CPE_SESSION_TIMEOUT "cwmp.cpe.session_timeout"
|
||||
#define UCI_CPE_EXEC_DOWNLOAD "cwmp.cpe.exec_download"
|
||||
#define UCI_CPE_NOTIFY_PERIODIC_ENABLE "cwmp.cpe.periodic_notify_enable"
|
||||
#define UCI_CPE_NOTIFY_PERIOD "cwmp.cpe.periodic_notify_interval"
|
||||
#define LW_NOTIFICATION_ENABLE "cwmp.lwn.enable"
|
||||
#define LW_NOTIFICATION_HOSTNAME "cwmp.lwn.hostname"
|
||||
#define LW_NOTIFICATION_PORT "cwmp.lwn.port"
|
||||
#define UCI_DHCP_ACS_URL "cwmp.acs.dhcp_url"
|
||||
|
||||
#define UCI_CONFIG_DIR "/etc/config/"
|
||||
#define LIB_DB_CONFIG "/lib/db/config"
|
||||
|
|
@ -68,7 +67,8 @@ typedef enum uci_config_action {
|
|||
CWMP_CMD_DEL,
|
||||
} uci_config_action;
|
||||
|
||||
enum uci_paths_types {
|
||||
enum uci_paths_types
|
||||
{
|
||||
UCI_STANDARD_CONFIG,
|
||||
UCI_DB_CONFIG,
|
||||
UCI_BOARD_DB_CONFIG,
|
||||
|
|
@ -76,7 +76,8 @@ enum uci_paths_types {
|
|||
UCI_BBFDM_CONFIG
|
||||
};
|
||||
|
||||
enum cwmp_uci_cmp {
|
||||
enum cwmp_uci_cmp
|
||||
{
|
||||
CWMP_CMP_SECTION,
|
||||
CWMP_CMP_OPTION_EQUAL,
|
||||
CWMP_CMP_OPTION_REGEX,
|
||||
|
|
@ -86,15 +87,15 @@ enum cwmp_uci_cmp {
|
|||
CWMP_CMP_FILTER_FUNC
|
||||
};
|
||||
|
||||
enum cwmp_uci_walk {
|
||||
enum cwmp_uci_walk
|
||||
{
|
||||
CWMP_GET_FIRST_SECTION,
|
||||
CWMP_GET_NEXT_SECTION
|
||||
};
|
||||
|
||||
|
||||
struct config_uci_list {
|
||||
struct list_head list;
|
||||
char *value;
|
||||
struct list_head list;
|
||||
char *value;
|
||||
};
|
||||
|
||||
struct uci_paths {
|
||||
|
|
@ -106,22 +107,17 @@ int cwmp_uci_init(int uci_path_type);
|
|||
void cwmp_uci_exit(void);
|
||||
int cwmp_uci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *package, char *section, char *option, char *value);
|
||||
int cwmp_uci_get_option_value_list(char *package, char *section, char *option, struct list_head *list);
|
||||
int uci_get_state_value(char *cmd,char **value);
|
||||
int uci_get_state_value(char *cmd, char **value);
|
||||
int uci_set_state_value(char *cmd);
|
||||
int uci_set_value(char *cmd);
|
||||
int uci_get_value(char *cmd,char **value);
|
||||
char* cwmp_db_get_value_string(char *package, char *section, char *option);
|
||||
struct uci_section *cwmp_uci_walk_section (char *package, char *stype, void *arg1, void *arg2, int cmp , int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk);
|
||||
int uci_get_value(char *cmd, char **value);
|
||||
char *cwmp_db_get_value_string(char *package, char *section, char *option);
|
||||
struct uci_section *cwmp_uci_walk_section(char *package, char *stype, void *arg1, void *arg2, int cmp, int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk);
|
||||
int cwmp_uci_get_value_by_section_string(struct uci_section *s, char *option, char **value);
|
||||
int cwmp_uci_get_option_value_string(char *package, char *section, char *option, int uci_type, char **value);
|
||||
|
||||
#define cwmp_uci_path_foreach_option_eq(package, stype, option, val, section) \
|
||||
for (section = cwmp_uci_walk_section(package, stype, option, val, CWMP_CMP_OPTION_EQUAL, NULL, NULL, CWMP_GET_FIRST_SECTION); \
|
||||
section != NULL; \
|
||||
section = cwmp_uci_walk_section(package, stype, option, val, CWMP_CMP_OPTION_EQUAL, NULL, section, CWMP_GET_NEXT_SECTION))
|
||||
for (section = cwmp_uci_walk_section(package, stype, option, val, CWMP_CMP_OPTION_EQUAL, NULL, NULL, CWMP_GET_FIRST_SECTION); section != NULL; section = cwmp_uci_walk_section(package, stype, option, val, CWMP_CMP_OPTION_EQUAL, NULL, section, CWMP_GET_NEXT_SECTION))
|
||||
|
||||
#define cwmp_uci_path_foreach_sections(package, stype, section) \
|
||||
for (section = cwmp_uci_walk_section(package, stype, NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); \
|
||||
section != NULL; \
|
||||
section = cwmp_uci_walk_section(package, stype, NULL, NULL, CMP_SECTION, NULL, section, GET_NEXT_SECTION))
|
||||
#define cwmp_uci_path_foreach_sections(package, stype, section) for (section = cwmp_uci_walk_section(package, stype, NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); section != NULL; section = cwmp_uci_walk_section(package, stype, NULL, NULL, CMP_SECTION, NULL, section, GET_NEXT_SECTION))
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -12,6 +12,6 @@
|
|||
#ifndef __ZLIB_H
|
||||
#define __ZLIB_H
|
||||
|
||||
int zlib_compress (char *message, unsigned char **zmsg, int *zlen, int type);
|
||||
int zlib_compress(char *message, unsigned char **zmsg, int *zlen, int type);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
#include "common.h"
|
||||
#include "cwmp_json.h"
|
||||
|
||||
|
||||
#define DM_ROOT_OBJ "Device."
|
||||
extern bool transaction_started;
|
||||
extern int transaction_id;
|
||||
|
|
@ -12,7 +11,8 @@ extern json_object *actual_global_json_obj;
|
|||
extern json_object *old_list_notify;
|
||||
extern json_object *actual_list_notify;
|
||||
|
||||
enum notify_type {
|
||||
enum notify_type
|
||||
{
|
||||
OLD_LIST_NOTIFY,
|
||||
ACTUAL_LIST_NOTIFY
|
||||
};
|
||||
|
|
@ -21,14 +21,14 @@ int cwmp_transaction_start(char *app);
|
|||
int cwmp_transaction_commit();
|
||||
int cwmp_transaction_abort();
|
||||
int cwmp_transaction_status();
|
||||
char* cwmp_get_parameter_values(char *parameter_name, json_object **parameters);
|
||||
char* cwmp_set_parameter_value(char* parameter_name, char* value, char* parameter_key, int* flag);
|
||||
char* cwmp_set_multiple_parameters_values(struct list_head parameters_values_list, char* parameter_key, int* flag, json_object **faults_array);
|
||||
char* cwmp_add_object(char* object_name, char* key, char **instance);
|
||||
char* cwmp_delete_object(char* object_name, char* key);
|
||||
char* cwmp_get_parameter_names(char* object_name, bool next_level, json_object **parameters);
|
||||
char* cwmp_get_parameter_attributes(char* parameter_name, json_object **parameters);
|
||||
char* cwmp_set_parameter_attributes(char* parameter_name, char* notification);
|
||||
char *cwmp_get_parameter_values(char *parameter_name, json_object **parameters);
|
||||
char *cwmp_set_parameter_value(char *parameter_name, char *value, char *parameter_key, int *flag);
|
||||
char *cwmp_set_multiple_parameters_values(struct list_head parameters_values_list, char *parameter_key, int *flag, json_object **faults_array);
|
||||
char *cwmp_add_object(char *object_name, char *key, char **instance);
|
||||
char *cwmp_delete_object(char *object_name, char *key);
|
||||
char *cwmp_get_parameter_names(char *object_name, bool next_level, json_object **parameters);
|
||||
char *cwmp_get_parameter_attributes(char *parameter_name, json_object **parameters);
|
||||
char *cwmp_set_parameter_attributes(char *parameter_name, char *notification);
|
||||
int cwmp_update_enabled_list_notify(int instance_moden, int notify_type);
|
||||
|
||||
#endif /* SRC_DATAMODELIFACE_H_ */
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
#ifndef __DIAGNOSTIC__H
|
||||
#define __DIAGNOSTIC__H
|
||||
|
||||
bool set_diagnostic_parameter_structure_value(char *parameter_name, char* value);
|
||||
bool set_diagnostic_parameter_structure_value(char *parameter_name, char *value);
|
||||
|
||||
int cwmp_download_diagnostics();
|
||||
int cwmp_upload_diagnostics();
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DIGESTAUTH_H_
|
||||
#define DIGESTAUTH_H_
|
||||
|
||||
|
|
@ -28,11 +27,8 @@
|
|||
*/
|
||||
#define MHD_INVALID_NONCE -1
|
||||
|
||||
int http_digest_auth_fail_response(FILE *fp, const char *http_method,
|
||||
const char *url, const char *realm, const char *opaque);
|
||||
int http_digest_auth_fail_response(FILE *fp, const char *http_method, const char *url, const char *realm, const char *opaque);
|
||||
|
||||
int http_digest_auth_check(const char *http_method, const char *url,
|
||||
const char *header, const char *realm, const char *username,
|
||||
const char *password, unsigned int nonce_timeout);
|
||||
int http_digest_auth_check(const char *http_method, const char *url, const char *header, const char *realm, const char *username, const char *password, unsigned int nonce_timeout);
|
||||
|
||||
#endif /* DIGESTAUTH_H_ */
|
||||
|
|
|
|||
40
inc/event.h
40
inc/event.h
|
|
@ -13,33 +13,35 @@
|
|||
#define EVENT_H_
|
||||
#include "common.h"
|
||||
typedef struct event_container {
|
||||
struct list_head list;
|
||||
int code; /* required element of type xsd:string */
|
||||
char *command_key;
|
||||
struct list_head head_dm_parameter;
|
||||
int id;
|
||||
struct list_head list;
|
||||
int code; /* required element of type xsd:string */
|
||||
char *command_key;
|
||||
struct list_head head_dm_parameter;
|
||||
int id;
|
||||
} event_container;
|
||||
|
||||
typedef struct EVENT_CONST_STRUCT
|
||||
{
|
||||
char *CODE;
|
||||
unsigned int TYPE;
|
||||
unsigned short RETRY;
|
||||
typedef struct EVENT_CONST_STRUCT {
|
||||
char *CODE;
|
||||
unsigned int TYPE;
|
||||
unsigned short RETRY;
|
||||
|
||||
} EVENT_CONST_STRUCT;
|
||||
|
||||
enum event_retry_after_enum {
|
||||
enum event_retry_after_enum
|
||||
{
|
||||
EVENT_RETRY_AFTER_TRANSMIT_FAIL = 0x1,
|
||||
EVENT_RETRY_AFTER_REBOOT = 0x2,
|
||||
EVENT_RETRY_AFTER_BOOTSTRAP = 0x4
|
||||
};
|
||||
|
||||
enum event_type_enum {
|
||||
enum event_type_enum
|
||||
{
|
||||
EVENT_TYPE_SINGLE = 0x0,
|
||||
EVENT_TYPE_MULTIPLE = 0x1
|
||||
};
|
||||
|
||||
enum event_idx_enum {
|
||||
enum event_idx_enum
|
||||
{
|
||||
EVENT_IDX_0BOOTSTRAP,
|
||||
EVENT_IDX_1BOOT,
|
||||
EVENT_IDX_2PERIODIC,
|
||||
|
|
@ -61,18 +63,16 @@ enum event_idx_enum {
|
|||
__EVENT_IDX_MAX
|
||||
};
|
||||
|
||||
extern const struct EVENT_CONST_STRUCT EVENT_CONST [__EVENT_IDX_MAX];
|
||||
extern const struct EVENT_CONST_STRUCT EVENT_CONST[__EVENT_IDX_MAX];
|
||||
|
||||
|
||||
|
||||
struct event_container *cwmp_add_event_container (struct cwmp *cwmp, int event_idx, char *command_key);
|
||||
struct event_container *cwmp_add_event_container(struct cwmp *cwmp, int event_idx, char *command_key);
|
||||
int event_remove_all_event_container(struct session *session, int rem_from);
|
||||
int event_remove_noretry_event_container(struct session *session, struct cwmp *cwmp);
|
||||
void cwmp_save_event_container (struct event_container *event_container);
|
||||
void *thread_event_periodic (void *v);
|
||||
void cwmp_save_event_container(struct event_container *event_container);
|
||||
void *thread_event_periodic(void *v);
|
||||
void connection_request_ip_value_change(struct cwmp *cwmp, int version);
|
||||
void connection_request_port_value_change(struct cwmp *cwmp, int port);
|
||||
int cwmp_get_int_event_code(char *code);
|
||||
bool event_exist_in_list(struct cwmp *cwmp, int event);
|
||||
int cwmp_root_cause_events (struct cwmp *cwmp);
|
||||
int cwmp_root_cause_events(struct cwmp *cwmp);
|
||||
#endif /* SRC_INC_EVENT_H_ */
|
||||
|
|
|
|||
|
|
@ -15,17 +15,17 @@
|
|||
#define _FREECWMP_EXTERNAL_H__
|
||||
#include <time.h>
|
||||
|
||||
void external_du_change_stateFaultResp (char *fault_code, char *version, char *name, char *uuid, char *env);
|
||||
void external_downloadFaultResp (char *fault_code);
|
||||
void external_fetch_downloadFaultResp (char **fault_code);
|
||||
void external_uploadFaultResp (char *fault_code);
|
||||
void external_fetch_uploadFaultResp (char **fault_code);
|
||||
void external_uninstallFaultResp (char *fault_code);
|
||||
void external_fetch_uninstallFaultResp (char **fault);
|
||||
void external_du_change_stateFaultResp(char *fault_code, char *version, char *name, char *uuid, char *env);
|
||||
void external_downloadFaultResp(char *fault_code);
|
||||
void external_fetch_downloadFaultResp(char **fault_code);
|
||||
void external_uploadFaultResp(char *fault_code);
|
||||
void external_fetch_uploadFaultResp(char **fault_code);
|
||||
void external_uninstallFaultResp(char *fault_code);
|
||||
void external_fetch_uninstallFaultResp(char **fault);
|
||||
int external_simple(char *command, char *arg, int c);
|
||||
int external_download(char *url, char *size, char *type, char *user, char *pass,time_t c);
|
||||
int external_download(char *url, char *size, char *type, char *user, char *pass, time_t c);
|
||||
int external_upload(char *url, char *type, char *user, char *pass, char *name);
|
||||
int external_apply(char *action, char *arg,time_t c);
|
||||
int external_apply(char *action, char *arg, time_t c);
|
||||
void external_fetch_du_change_stateFaultResp(char **fault, char **version, char **name, char **uuid, char **env);
|
||||
int external_change_du_state_install(char *url, char *uuid, char *user, char *pass, char *env);
|
||||
int external_change_du_state_update(char *uuid, char *url, char *user, char *pass);
|
||||
|
|
@ -37,4 +37,3 @@ void external_init();
|
|||
void external_exit();
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -15,19 +15,17 @@ extern char *fc_cookies;
|
|||
|
||||
#define HTTP_TIMEOUT 30
|
||||
|
||||
struct http_client
|
||||
{
|
||||
struct http_client {
|
||||
struct curl_slist *header_list;
|
||||
char *url;
|
||||
};
|
||||
|
||||
int http_client_init(struct cwmp *cwmp);
|
||||
void http_client_exit(void);
|
||||
int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len,char **msg_in);
|
||||
int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **msg_in);
|
||||
|
||||
void http_server_init(void);
|
||||
void http_server_listen(void);
|
||||
void http_success_cr();
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
75
inc/log.h
75
inc/log.h
|
|
@ -13,7 +13,8 @@
|
|||
#ifndef _LOG_H_
|
||||
#define _LOG_H_
|
||||
|
||||
enum log_severity_enum {
|
||||
enum log_severity_enum
|
||||
{
|
||||
EMERG,
|
||||
ALERT,
|
||||
CRITIC,
|
||||
|
|
@ -24,66 +25,68 @@ enum log_severity_enum {
|
|||
DEBUG
|
||||
};
|
||||
|
||||
enum log_xmlmsg_enum {
|
||||
enum log_xmlmsg_enum
|
||||
{
|
||||
XML_MSG_IN,
|
||||
XML_MSG_OUT
|
||||
};
|
||||
|
||||
void puts_log(int severity, const char *fmt, ...);
|
||||
void puts_log_xmlmsg(int severity, char *msg, int msgtype);
|
||||
int log_set_log_file_name (char *value);
|
||||
int log_set_log_file_name(char *value);
|
||||
int log_set_file_max_size(char *value);
|
||||
int log_set_on_console(char *value);
|
||||
int log_set_on_file(char *value);
|
||||
int log_set_severity_idx (char *value);
|
||||
#define DEFAULT_LOG_FILE_SIZE 10240
|
||||
#define DEFAULT_LOG_FILE_NAME "/var/log/icwmpd.log"
|
||||
#define DEFAULT_LOG_SEVERITY INFO
|
||||
int log_set_severity_idx(char *value);
|
||||
#define DEFAULT_LOG_FILE_SIZE 10240
|
||||
#define DEFAULT_LOG_FILE_NAME "/var/log/icwmpd.log"
|
||||
#define DEFAULT_LOG_SEVERITY INFO
|
||||
|
||||
#ifdef WITH_CWMP_DEBUG
|
||||
# ifndef CWMP_LOG
|
||||
# define CWMP_LOG(SEV,MESSAGE,args...) puts_log(SEV,MESSAGE,##args);
|
||||
# define CWMP_LOG_XML_MSG puts_log_xmlmsg
|
||||
# endif
|
||||
#ifndef CWMP_LOG
|
||||
#define CWMP_LOG(SEV, MESSAGE, args...) puts_log(SEV, MESSAGE, ##args);
|
||||
#define CWMP_LOG_XML_MSG puts_log_xmlmsg
|
||||
#endif
|
||||
#else
|
||||
# define CWMP_LOG(SEV,MESSAGE,args...)
|
||||
# define CWMP_LOG_XML_MSG(X, Y, Z)
|
||||
#define CWMP_LOG(SEV, MESSAGE, args...)
|
||||
#define CWMP_LOG_XML_MSG(X, Y, Z)
|
||||
#endif
|
||||
|
||||
#ifdef WITH_DEV_DEBUG
|
||||
# ifndef DD
|
||||
# define DD(SEV,MESSAGE,args...) puts_log(SEV,MESSAGE,##args);
|
||||
# endif
|
||||
#ifndef DD
|
||||
#define DD(SEV, MESSAGE, args...) puts_log(SEV, MESSAGE, ##args);
|
||||
#endif
|
||||
#else
|
||||
# define DD(SEV,MESSAGE,args...)
|
||||
#define DD(SEV, MESSAGE, args...)
|
||||
#endif
|
||||
|
||||
#ifndef DETECT_CRASH
|
||||
#define DETECT_CRASH(MESSAGE,args...) { \
|
||||
const char *A[] = {MESSAGE}; \
|
||||
printf("DETECT_CRASH: %s %s %d\n",__FUNCTION__,__FILE__,__LINE__); fflush(stdout);\
|
||||
if(sizeof(A) > 0) \
|
||||
printf(*A,##args); \
|
||||
sleep(1); \
|
||||
}
|
||||
#define DETECT_CRASH(MESSAGE, args...) \
|
||||
{ \
|
||||
const char *A[] = { MESSAGE }; \
|
||||
printf("DETECT_CRASH: %s %s %d\n", __FUNCTION__, __FILE__, __LINE__); \
|
||||
fflush(stdout); \
|
||||
if (sizeof(A) > 0) \
|
||||
printf(*A, ##args); \
|
||||
sleep(1); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef TRACE
|
||||
#define TRACE_TYPE 0
|
||||
static inline void trace_empty_func()
|
||||
{
|
||||
}
|
||||
static inline void trace_empty_func() {}
|
||||
#if TRACE_TYPE == 2
|
||||
#define TRACE(MESSAGE,args...) do { \
|
||||
const char *A[] = {MESSAGE}; \
|
||||
fprintf(stderr, "TRACE: %s %s %d ",__FUNCTION__,__FILE__,__LINE__); \
|
||||
if(sizeof(A) > 0) \
|
||||
fprintf(stderr, *A,##args); \
|
||||
fprintf(stderr, "\n"); \
|
||||
fflush(stderr); \
|
||||
} while(0)
|
||||
#define TRACE(MESSAGE, args...) \
|
||||
do { \
|
||||
const char *A[] = { MESSAGE }; \
|
||||
fprintf(stderr, "TRACE: %s %s %d ", __FUNCTION__, __FILE__, __LINE__); \
|
||||
if (sizeof(A) > 0) \
|
||||
fprintf(stderr, *A, ##args); \
|
||||
fprintf(stderr, "\n"); \
|
||||
fflush(stderr); \
|
||||
} while (0)
|
||||
#elif TRACE_TYPE == 1
|
||||
#define TRACE(MESSAGE, ...) printf(MESSAGE, ## __VA_ARGS__)
|
||||
#define TRACE(MESSAGE, ...) printf(MESSAGE, ##__VA_ARGS__)
|
||||
#else
|
||||
#define TRACE(MESSAGE, ...) trace_empty_func()
|
||||
#endif
|
||||
|
|
|
|||
22
inc/md5.h
22
inc/md5.h
|
|
@ -23,30 +23,22 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define HIGHFIRST
|
||||
#endif
|
||||
|
||||
#define MD5_DIGEST_SIZE 16
|
||||
|
||||
struct MD5Context
|
||||
{
|
||||
uint32_t buf[4];
|
||||
uint32_t bits[2];
|
||||
unsigned char in[64];
|
||||
struct MD5Context {
|
||||
uint32_t buf[4];
|
||||
uint32_t bits[2];
|
||||
unsigned char in[64];
|
||||
};
|
||||
|
||||
void MD5Init(struct MD5Context *ctx);
|
||||
|
||||
void
|
||||
MD5Init(struct MD5Context *ctx);
|
||||
void MD5Update(struct MD5Context *ctx, const void *buf, unsigned len);
|
||||
|
||||
void
|
||||
MD5Update(struct MD5Context *ctx,
|
||||
const void *buf,
|
||||
unsigned len);
|
||||
|
||||
void MD5Final(unsigned char digest[MD5_DIGEST_SIZE],
|
||||
struct MD5Context *ctx);
|
||||
void MD5Final(unsigned char digest[MD5_DIGEST_SIZE], struct MD5Context *ctx);
|
||||
|
||||
#endif /* !MD5_H */
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@
|
|||
#include "datamodel_interface.h"
|
||||
#include "xml.h"
|
||||
|
||||
enum NOTIFICATION_STATUS {
|
||||
enum NOTIFICATION_STATUS
|
||||
{
|
||||
NOTIF_NONE = 0,
|
||||
NOTIF_PASSIVE = 1 << 1,
|
||||
NOTIF_ACTIVE = 1 << 2,
|
||||
|
|
@ -35,7 +36,7 @@ extern pthread_mutex_t mutex_value_change;
|
|||
int cwmp_update_enabled_notify_file();
|
||||
int check_value_change(void);
|
||||
void sotfware_version_value_change(struct cwmp *cwmp, struct transfer_complete *p);
|
||||
void *thread_periodic_check_notify (void *v);
|
||||
void *thread_periodic_check_notify(void *v);
|
||||
void send_active_value_change(void);
|
||||
void add_list_value_change(char *param_name, char *param_data, char *param_type);
|
||||
void add_lw_list_value_change(char *param_name, char *param_data, char *param_type);
|
||||
|
|
|
|||
|
|
@ -16,50 +16,52 @@
|
|||
#include "common.h"
|
||||
|
||||
typedef struct session {
|
||||
struct list_head list;
|
||||
struct list_head head_event_container;
|
||||
struct list_head head_rpc_cpe;
|
||||
struct list_head head_rpc_acs;
|
||||
mxml_node_t *tree_in;
|
||||
mxml_node_t *tree_out;
|
||||
mxml_node_t *body_in;
|
||||
bool hold_request;
|
||||
bool digest_auth;
|
||||
int fault_code;
|
||||
int error;
|
||||
struct list_head list;
|
||||
struct list_head head_event_container;
|
||||
struct list_head head_rpc_cpe;
|
||||
struct list_head head_rpc_acs;
|
||||
mxml_node_t *tree_in;
|
||||
mxml_node_t *tree_out;
|
||||
mxml_node_t *body_in;
|
||||
bool hold_request;
|
||||
bool digest_auth;
|
||||
int fault_code;
|
||||
int error;
|
||||
} session;
|
||||
|
||||
enum end_session_enum {
|
||||
enum end_session_enum
|
||||
{
|
||||
END_SESSION_REBOOT = 1,
|
||||
END_SESSION_EXTERNAL_ACTION = 1<<1,
|
||||
END_SESSION_RELOAD = 1<<2,
|
||||
END_SESSION_FACTORY_RESET = 1<<3,
|
||||
END_SESSION_IPPING_DIAGNOSTIC = 1<<4,
|
||||
END_SESSION_DOWNLOAD_DIAGNOSTIC = 1<<5,
|
||||
END_SESSION_UPLOAD_DIAGNOSTIC = 1<<6,
|
||||
END_SESSION_X_FACTORY_RESET_SOFT = 1<<7,
|
||||
END_SESSION_NSLOOKUP_DIAGNOSTIC = 1<<8,
|
||||
END_SESSION_TRACEROUTE_DIAGNOSTIC = 1<<9,
|
||||
END_SESSION_UDPECHO_DIAGNOSTIC = 1<<10,
|
||||
END_SESSION_SERVERSELECTION_DIAGNOSTIC = 1<<11,
|
||||
END_SESSION_SET_NOTIFICATION_UPDATE = 1<<12,
|
||||
END_SESSION_EXTERNAL_ACTION = 1 << 1,
|
||||
END_SESSION_RELOAD = 1 << 2,
|
||||
END_SESSION_FACTORY_RESET = 1 << 3,
|
||||
END_SESSION_IPPING_DIAGNOSTIC = 1 << 4,
|
||||
END_SESSION_DOWNLOAD_DIAGNOSTIC = 1 << 5,
|
||||
END_SESSION_UPLOAD_DIAGNOSTIC = 1 << 6,
|
||||
END_SESSION_X_FACTORY_RESET_SOFT = 1 << 7,
|
||||
END_SESSION_NSLOOKUP_DIAGNOSTIC = 1 << 8,
|
||||
END_SESSION_TRACEROUTE_DIAGNOSTIC = 1 << 9,
|
||||
END_SESSION_UDPECHO_DIAGNOSTIC = 1 << 10,
|
||||
END_SESSION_SERVERSELECTION_DIAGNOSTIC = 1 << 11,
|
||||
END_SESSION_SET_NOTIFICATION_UPDATE = 1 << 12,
|
||||
END_SESSION_TRANSACTION_COMMIT = 1 << 13
|
||||
};
|
||||
|
||||
enum enum_session_status {
|
||||
SESSION_WAITING,
|
||||
SESSION_RUNNING,
|
||||
SESSION_FAILURE,
|
||||
SESSION_SUCCESS
|
||||
enum enum_session_status
|
||||
{
|
||||
SESSION_WAITING,
|
||||
SESSION_RUNNING,
|
||||
SESSION_FAILURE,
|
||||
SESSION_SUCCESS
|
||||
};
|
||||
|
||||
extern unsigned int end_session_flag;
|
||||
|
||||
void cwmp_set_end_session(unsigned int flag);
|
||||
struct rpc *cwmp_add_session_rpc_cpe (struct session *session, int type);
|
||||
struct session *cwmp_add_queue_session (struct cwmp *cwmp);
|
||||
struct rpc *cwmp_add_session_rpc_acs (struct session *session, int type);
|
||||
struct rpc *cwmp_add_session_rpc_cpe(struct session *session, int type);
|
||||
struct session *cwmp_add_queue_session(struct cwmp *cwmp);
|
||||
struct rpc *cwmp_add_session_rpc_acs(struct session *session, int type);
|
||||
int cwmp_apply_acs_changes();
|
||||
int cwmp_move_session_to_session_send (struct cwmp *cwmp, struct session *session);
|
||||
struct rpc *cwmp_add_session_rpc_acs_head (struct session *session, int type);
|
||||
int cwmp_move_session_to_session_send(struct cwmp *cwmp, struct session *session);
|
||||
struct rpc *cwmp_add_session_rpc_acs_head(struct session *session, int type);
|
||||
#endif /* SRC_INC_SESSION_H_ */
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@
|
|||
int ubus_init(struct cwmp *cwmp);
|
||||
void ubus_exit(void);
|
||||
|
||||
enum cwmp_ubus_arg_type {
|
||||
enum cwmp_ubus_arg_type
|
||||
{
|
||||
UBUS_String,
|
||||
UBUS_Integer,
|
||||
UBUS_Array_Obj,
|
||||
|
|
@ -34,12 +35,12 @@ struct key_value {
|
|||
};
|
||||
|
||||
union array_membre {
|
||||
char* str_value;
|
||||
char *str_value;
|
||||
struct key_value param_value;
|
||||
};
|
||||
|
||||
union ubus_value {
|
||||
char* str_val;
|
||||
char *str_val;
|
||||
int int_val;
|
||||
bool bool_val;
|
||||
union array_membre array_value[ARRAY_MAX];
|
||||
|
|
|
|||
126
inc/xml.h
126
inc/xml.h
|
|
@ -18,59 +18,66 @@
|
|||
#include "common.h"
|
||||
#include "session.h"
|
||||
|
||||
#define CWMP_MXML_TAB_SPACE " "
|
||||
#define DOWNLOAD_PROTOCOL_HTTP "http://"
|
||||
#define DOWNLOAD_PROTOCOL_HTTPS "https://"
|
||||
#define DOWNLOAD_PROTOCOL_FTP "ftp://"
|
||||
#define MAX_DOWNLOAD_QUEUE 10
|
||||
#define MAX_SCHEDULE_INFORM_QUEUE 10
|
||||
#define CWMP_MXML_TAB_SPACE " "
|
||||
#define DOWNLOAD_PROTOCOL_HTTP "http://"
|
||||
#define DOWNLOAD_PROTOCOL_HTTPS "https://"
|
||||
#define DOWNLOAD_PROTOCOL_FTP "ftp://"
|
||||
#define MAX_DOWNLOAD_QUEUE 10
|
||||
#define MAX_SCHEDULE_INFORM_QUEUE 10
|
||||
|
||||
#define MXML_DELETE(X) do {if (X) { mxmlDelete(X); X = NULL; } } while(0)
|
||||
#define MXML_DELETE(X) \
|
||||
do { \
|
||||
if (X) { \
|
||||
mxmlDelete(X); \
|
||||
X = NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
extern struct list_head list_schedule_inform;
|
||||
extern struct list_head list_download;
|
||||
extern struct list_head list_upload;
|
||||
extern struct list_head list_schedule_download;
|
||||
extern struct list_head list_apply_schedule_download;
|
||||
extern struct list_head list_change_du_state;
|
||||
extern int count_download_queue;
|
||||
extern struct list_head list_schedule_inform;
|
||||
extern struct list_head list_download;
|
||||
extern struct list_head list_upload;
|
||||
extern struct list_head list_schedule_download;
|
||||
extern struct list_head list_apply_schedule_download;
|
||||
extern struct list_head list_change_du_state;
|
||||
extern int count_download_queue;
|
||||
extern const struct rpc_cpe_method rpc_cpe_methods[__RPC_CPE_MAX];
|
||||
extern const struct rpc_acs_method rpc_acs_methods[__RPC_ACS_MAX];
|
||||
|
||||
enum fault_code_enum {
|
||||
FAULT_9000 = 9000,// Method not supported
|
||||
FAULT_9001,// Request denied
|
||||
FAULT_9002,// Internal error
|
||||
FAULT_9003,// Invalid arguments
|
||||
FAULT_9004,// Resources exceeded
|
||||
FAULT_9005,// Invalid parameter name
|
||||
FAULT_9006,// Invalid parameter type
|
||||
FAULT_9007,// Invalid parameter value
|
||||
FAULT_9008,// Attempt to set a non-writable parameter
|
||||
FAULT_9009,// Notification request rejected
|
||||
FAULT_9010,// Download failure
|
||||
FAULT_9011,// Upload failure
|
||||
FAULT_9012,// File transfer server authentication failure
|
||||
FAULT_9013,// Unsupported protocol for file transfer
|
||||
FAULT_9014,// Download failure: unable to join multicast group
|
||||
FAULT_9015,// Download failure: unable to contact file server
|
||||
FAULT_9016,// Download failure: unable to access file
|
||||
FAULT_9017,// Download failure: unable to complete download
|
||||
FAULT_9018,// Download failure: file corrupted
|
||||
FAULT_9019,// Download failure: file authentication failure
|
||||
FAULT_9020,// Download failure: unable to complete download
|
||||
FAULT_9021,// Cancelation of file transfer not permitted
|
||||
FAULT_9022,// Invalid UUID format
|
||||
FAULT_9023,// Unknown Execution Environment
|
||||
FAULT_9024,// Disabled Execution Environment
|
||||
FAULT_9025,// Diployment Unit to Execution environment mismatch
|
||||
FAULT_9026,// Duplicate Deployment Unit
|
||||
FAULT_9027,// System Ressources Exceeded
|
||||
FAULT_9028,// Unknown Deployment Unit
|
||||
FAULT_9029,// Invalid Deployment Unit State
|
||||
FAULT_9030,// Invalid Deployment Unit Update: Downgrade not permitted
|
||||
FAULT_9031,// Invalid Deployment Unit Update: Version not specified
|
||||
FAULT_9032,// Invalid Deployment Unit Update: Version already exist
|
||||
enum fault_code_enum
|
||||
{
|
||||
FAULT_9000 = 9000, // Method not supported
|
||||
FAULT_9001, // Request denied
|
||||
FAULT_9002, // Internal error
|
||||
FAULT_9003, // Invalid arguments
|
||||
FAULT_9004, // Resources exceeded
|
||||
FAULT_9005, // Invalid parameter name
|
||||
FAULT_9006, // Invalid parameter type
|
||||
FAULT_9007, // Invalid parameter value
|
||||
FAULT_9008, // Attempt to set a non-writable parameter
|
||||
FAULT_9009, // Notification request rejected
|
||||
FAULT_9010, // Download failure
|
||||
FAULT_9011, // Upload failure
|
||||
FAULT_9012, // File transfer server authentication failure
|
||||
FAULT_9013, // Unsupported protocol for file transfer
|
||||
FAULT_9014, // Download failure: unable to join multicast group
|
||||
FAULT_9015, // Download failure: unable to contact file server
|
||||
FAULT_9016, // Download failure: unable to access file
|
||||
FAULT_9017, // Download failure: unable to complete download
|
||||
FAULT_9018, // Download failure: file corrupted
|
||||
FAULT_9019, // Download failure: file authentication failure
|
||||
FAULT_9020, // Download failure: unable to complete download
|
||||
FAULT_9021, // Cancelation of file transfer not permitted
|
||||
FAULT_9022, // Invalid UUID format
|
||||
FAULT_9023, // Unknown Execution Environment
|
||||
FAULT_9024, // Disabled Execution Environment
|
||||
FAULT_9025, // Diployment Unit to Execution environment mismatch
|
||||
FAULT_9026, // Duplicate Deployment Unit
|
||||
FAULT_9027, // System Ressources Exceeded
|
||||
FAULT_9028, // Unknown Deployment Unit
|
||||
FAULT_9029, // Invalid Deployment Unit State
|
||||
FAULT_9030, // Invalid Deployment Unit Update: Downgrade not permitted
|
||||
FAULT_9031, // Invalid Deployment Unit Update: Version not specified
|
||||
FAULT_9032, // Invalid Deployment Unit Update: Version already exist
|
||||
__FAULT_MAX
|
||||
};
|
||||
|
||||
|
|
@ -89,7 +96,7 @@ int cwmp_handle_rpc_cpe_download(struct session *session, struct rpc *rpc);
|
|||
int cwmp_handle_rpc_cpe_upload(struct session *session, struct rpc *rpc);
|
||||
int cwmp_handle_rpc_cpe_factory_reset(struct session *session, struct rpc *rpc);
|
||||
int cwmp_handle_rpc_cpe_x_factory_reset_soft(struct session *session, struct rpc *rpc);
|
||||
int cancel_transfer(char * key);
|
||||
int cancel_transfer(char *key);
|
||||
int cwmp_handle_rpc_cpe_cancel_transfer(struct session *session, struct rpc *rpc);
|
||||
int cwmp_handle_rpc_cpe_schedule_inform(struct session *session, struct rpc *rpc);
|
||||
int cwmp_handle_rpc_cpe_schedule_download(struct session *session, struct rpc *rpc);
|
||||
|
|
@ -110,25 +117,25 @@ int xml_prepare_msg_out(struct session *session);
|
|||
int xml_prepare_lwnotification_message(char **msg_out);
|
||||
int xml_set_cwmp_id_rpc_cpe(struct session *session);
|
||||
int cwmp_create_fault_message(struct session *session, struct rpc *rpc_cpe, int fault_code);
|
||||
int cwmp_get_fault_code (int fault_code);
|
||||
int cwmp_get_fault_code_by_string (char* fault_code);
|
||||
int cwmp_get_fault_code(int fault_code);
|
||||
int cwmp_get_fault_code_by_string(char *fault_code);
|
||||
int cwmp_scheduleInform_remove_all();
|
||||
int cwmp_scheduledDownload_remove_all();
|
||||
int cwmp_scheduledUpload_remove_all();
|
||||
int cwmp_scheduled_Download_remove_all();
|
||||
int cwmp_apply_scheduled_Download_remove_all();
|
||||
struct transfer_complete *cwmp_set_data_rpc_acs_transferComplete();
|
||||
void *thread_cwmp_rpc_cpe_scheduleInform (void *v);
|
||||
void *thread_cwmp_rpc_cpe_download (void *v);
|
||||
void *thread_cwmp_rpc_cpe_upload (void *v);
|
||||
void *thread_cwmp_rpc_cpe_schedule_download (void *v);
|
||||
void *thread_cwmp_rpc_cpe_apply_schedule_download (void *v);
|
||||
void *thread_cwmp_rpc_cpe_change_du_state (void *v);
|
||||
void *thread_cwmp_rpc_cpe_scheduleInform(void *v);
|
||||
void *thread_cwmp_rpc_cpe_download(void *v);
|
||||
void *thread_cwmp_rpc_cpe_upload(void *v);
|
||||
void *thread_cwmp_rpc_cpe_schedule_download(void *v);
|
||||
void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v);
|
||||
void *thread_cwmp_rpc_cpe_change_du_state(void *v);
|
||||
|
||||
const char *whitespace_cb(mxml_node_t *node, int where);
|
||||
|
||||
int cwmp_root_cause_TransferComplete (struct cwmp *cwmp, struct transfer_complete *p);
|
||||
int cwmp_root_cause_dustatechangeComplete (struct cwmp *cwmp, struct du_state_change_complete *p);
|
||||
int cwmp_root_cause_TransferComplete(struct cwmp *cwmp, struct transfer_complete *p);
|
||||
int cwmp_root_cause_dustatechangeComplete(struct cwmp *cwmp, struct du_state_change_complete *p);
|
||||
void cwmp_root_cause_event_ipdiagnostic(void);
|
||||
int xml_set_cwmp_id(struct session *session);
|
||||
int xml_send_message(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
|
||||
|
|
@ -140,4 +147,3 @@ int cwmp_add_apply_schedule_download(struct schedule_download *schedule_download
|
|||
int cwmp_free_apply_schedule_download_request(struct apply_schedule_download *apply_schedule_download);
|
||||
char *calculate_lwnotification_cnonce();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
240
kcwmp.c
240
kcwmp.c
|
|
@ -18,11 +18,11 @@
|
|||
#include "cwmp_kernel.h"
|
||||
|
||||
typedef struct kernel_cwmp_input {
|
||||
char **argv;
|
||||
int argc;
|
||||
int handler;
|
||||
struct mutex mutex;
|
||||
wait_queue_head_t thresholdq;
|
||||
char **argv;
|
||||
int argc;
|
||||
int handler;
|
||||
struct mutex mutex;
|
||||
wait_queue_head_t thresholdq;
|
||||
} KERNEL_CWMP_INPUT;
|
||||
|
||||
static struct sock *nl_sk = NULL;
|
||||
|
|
@ -32,158 +32,136 @@ MODULE_LICENSE("IOPSYS");
|
|||
|
||||
static void kernel_api_cwmp_value_change_listener(struct sk_buff *skb)
|
||||
{
|
||||
struct nlmsghdr *nlh;
|
||||
int pid;
|
||||
struct sk_buff *skb_out;
|
||||
int msg_size;
|
||||
char *msg;
|
||||
char *recv;
|
||||
int i, res;
|
||||
|
||||
struct nlmsghdr *nlh;
|
||||
int pid;
|
||||
struct sk_buff *skb_out;
|
||||
int msg_size;
|
||||
char *msg;
|
||||
char *recv;
|
||||
int i,res;
|
||||
nlh = (struct nlmsghdr *)skb->data;
|
||||
recv = (char *)nlmsg_data(nlh);
|
||||
|
||||
nlh = (struct nlmsghdr*)skb->data;
|
||||
recv = (char*)nlmsg_data(nlh);
|
||||
if (strcmp(recv, NETLINK_CWMP_ID) != 0) {
|
||||
return;
|
||||
}
|
||||
pid = nlh->nlmsg_pid; /*pid of sending process */
|
||||
|
||||
if (strcmp(recv,NETLINK_CWMP_ID)!=0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pid = nlh->nlmsg_pid; /*pid of sending process */
|
||||
while (kernel_cwmp_input.argc == 0) {
|
||||
if (wait_event_interruptible(kernel_cwmp_input.thresholdq, kernel_cwmp_input.handler)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
kernel_cwmp_input.handler = 0;
|
||||
|
||||
mutex_lock(&(kernel_cwmp_input.mutex));
|
||||
|
||||
while (kernel_cwmp_input.argc==0)
|
||||
{
|
||||
if ( wait_event_interruptible( kernel_cwmp_input.thresholdq, kernel_cwmp_input.handler)) {
|
||||
return ;
|
||||
}
|
||||
}
|
||||
kernel_cwmp_input.handler = 0;
|
||||
for (i = 0; i <= kernel_cwmp_input.argc; i++) {
|
||||
if (i < kernel_cwmp_input.argc) {
|
||||
msg = kernel_cwmp_input.argv[i];
|
||||
} else {
|
||||
msg = NETLINK_END_DATA;
|
||||
}
|
||||
msg_size = strlen(msg);
|
||||
skb_out = nlmsg_new(msg_size, 0);
|
||||
if (!skb_out) {
|
||||
printk(KERN_ERR "Failed to allocate new skb\n");
|
||||
return;
|
||||
}
|
||||
|
||||
mutex_lock (&(kernel_cwmp_input.mutex));
|
||||
nlh = nlmsg_put(skb_out, 0, 0, NLMSG_DONE, msg_size, 0);
|
||||
NETLINK_CB(skb_out).dst_group = 0; /* not in mcast group */
|
||||
strncpy(nlmsg_data(nlh), msg, msg_size);
|
||||
res = nlmsg_unicast(nl_sk, skb_out, pid);
|
||||
|
||||
for (i=0;i<=kernel_cwmp_input.argc;i++)
|
||||
{
|
||||
if (i<kernel_cwmp_input.argc)
|
||||
{
|
||||
msg = kernel_cwmp_input.argv[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = NETLINK_END_DATA;
|
||||
}
|
||||
msg_size = strlen(msg);
|
||||
skb_out = nlmsg_new(msg_size,0);
|
||||
if(!skb_out)
|
||||
{
|
||||
printk(KERN_ERR "Failed to allocate new skb\n");
|
||||
return;
|
||||
}
|
||||
if (i < kernel_cwmp_input.argc) {
|
||||
kfree(kernel_cwmp_input.argv[i]);
|
||||
}
|
||||
}
|
||||
if (kernel_cwmp_input.argv != NULL) {
|
||||
kfree(kernel_cwmp_input.argv);
|
||||
kernel_cwmp_input.argv = NULL;
|
||||
}
|
||||
|
||||
nlh=nlmsg_put(skb_out,0,0,NLMSG_DONE,msg_size,0);
|
||||
NETLINK_CB(skb_out).dst_group = 0; /* not in mcast group */
|
||||
strncpy(nlmsg_data(nlh),msg,msg_size);
|
||||
res=nlmsg_unicast(nl_sk,skb_out,pid);
|
||||
|
||||
if (i<kernel_cwmp_input.argc)
|
||||
{
|
||||
kfree(kernel_cwmp_input.argv[i]);
|
||||
}
|
||||
|
||||
}
|
||||
if (kernel_cwmp_input.argv!=NULL)
|
||||
{
|
||||
kfree(kernel_cwmp_input.argv);
|
||||
kernel_cwmp_input.argv = NULL;
|
||||
}
|
||||
|
||||
kernel_cwmp_input.argc = 0;
|
||||
mutex_unlock (&(kernel_cwmp_input.mutex));
|
||||
kernel_cwmp_input.argc = 0;
|
||||
mutex_unlock(&(kernel_cwmp_input.mutex));
|
||||
}
|
||||
|
||||
static int /*__init*/ kernel_api_cwmp_value_change_init(void)
|
||||
{
|
||||
|
||||
printk(KERN_INFO "Entering kernel cwmp module: %s\n",__FUNCTION__);
|
||||
memset (&kernel_cwmp_input, 0, sizeof(struct kernel_cwmp_input));
|
||||
init_waitqueue_head(&kernel_cwmp_input.thresholdq);
|
||||
mutex_init(&kernel_cwmp_input.mutex);
|
||||
nl_sk=netlink_kernel_create(&init_net, NETLINK_USER, 0, kernel_api_cwmp_value_change_listener, NULL, THIS_MODULE);
|
||||
if(!nl_sk)
|
||||
{
|
||||
printk(KERN_ALERT "Error creating socket.\n");
|
||||
return -10;
|
||||
}
|
||||
return 0;
|
||||
printk(KERN_INFO "Entering kernel cwmp module: %s\n", __FUNCTION__);
|
||||
memset(&kernel_cwmp_input, 0, sizeof(struct kernel_cwmp_input));
|
||||
init_waitqueue_head(&kernel_cwmp_input.thresholdq);
|
||||
mutex_init(&kernel_cwmp_input.mutex);
|
||||
nl_sk = netlink_kernel_create(&init_net, NETLINK_USER, 0, kernel_api_cwmp_value_change_listener, NULL, THIS_MODULE);
|
||||
if (!nl_sk) {
|
||||
printk(KERN_ALERT "Error creating socket.\n");
|
||||
return -10;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void /*__exit*/ kernel_api_cwmp_value_change_exit(void)
|
||||
{
|
||||
printk(KERN_INFO "Exiting kernel cwmp module: %s\n",__FUNCTION__);
|
||||
netlink_kernel_release(nl_sk);
|
||||
printk(KERN_INFO "Exiting kernel cwmp module: %s\n", __FUNCTION__);
|
||||
netlink_kernel_release(nl_sk);
|
||||
}
|
||||
|
||||
int kernel_api_cwmp_value_change_call (int count, ...)
|
||||
int kernel_api_cwmp_value_change_call(int count, ...)
|
||||
{
|
||||
int i;
|
||||
va_list args;
|
||||
char *s;
|
||||
int i;
|
||||
va_list args;
|
||||
char *s;
|
||||
|
||||
if (kernel_cwmp_input.argc>0)
|
||||
{
|
||||
kernel_cwmp_input.handler = 1;
|
||||
wake_up_interruptible(&(kernel_cwmp_input.thresholdq));
|
||||
return 1;
|
||||
}
|
||||
if (kernel_cwmp_input.argc > 0) {
|
||||
kernel_cwmp_input.handler = 1;
|
||||
wake_up_interruptible(&(kernel_cwmp_input.thresholdq));
|
||||
return 1;
|
||||
}
|
||||
|
||||
mutex_lock (&(kernel_cwmp_input.mutex));
|
||||
kernel_cwmp_input.argv = kmalloc(count*sizeof(char *),GFP_KERNEL);
|
||||
mutex_lock(&(kernel_cwmp_input.mutex));
|
||||
kernel_cwmp_input.argv = kmalloc(count * sizeof(char *), GFP_KERNEL);
|
||||
|
||||
if (kernel_cwmp_input.argv==NULL)
|
||||
{
|
||||
goto kernel_api_cwmp_error;
|
||||
}
|
||||
if (kernel_cwmp_input.argv == NULL) {
|
||||
goto kernel_api_cwmp_error;
|
||||
}
|
||||
|
||||
va_start(args, count);
|
||||
for (i=0;i<count;i++)
|
||||
{
|
||||
s = (char *) va_arg(args, char *);
|
||||
if (s==NULL)
|
||||
{
|
||||
s = NETLINK_NULL;
|
||||
}
|
||||
kernel_cwmp_input.argv[i] = kmalloc(strlen(s),GFP_KERNEL);
|
||||
if (kernel_cwmp_input.argv[i]==NULL)
|
||||
{
|
||||
goto kernel_api_cwmp_error;
|
||||
}
|
||||
strcpy(kernel_cwmp_input.argv[i],s);
|
||||
kernel_cwmp_input.argc++;
|
||||
}
|
||||
va_end(args);
|
||||
mutex_unlock (&(kernel_cwmp_input.mutex));
|
||||
kernel_cwmp_input.handler = 1;
|
||||
wake_up_interruptible(&(kernel_cwmp_input.thresholdq));
|
||||
return 1;
|
||||
va_start(args, count);
|
||||
for (i = 0; i < count; i++) {
|
||||
s = (char *)va_arg(args, char *);
|
||||
if (s == NULL) {
|
||||
s = NETLINK_NULL;
|
||||
}
|
||||
kernel_cwmp_input.argv[i] = kmalloc(strlen(s), GFP_KERNEL);
|
||||
if (kernel_cwmp_input.argv[i] == NULL) {
|
||||
goto kernel_api_cwmp_error;
|
||||
}
|
||||
strcpy(kernel_cwmp_input.argv[i], s);
|
||||
kernel_cwmp_input.argc++;
|
||||
}
|
||||
va_end(args);
|
||||
mutex_unlock(&(kernel_cwmp_input.mutex));
|
||||
kernel_cwmp_input.handler = 1;
|
||||
wake_up_interruptible(&(kernel_cwmp_input.thresholdq));
|
||||
return 1;
|
||||
|
||||
kernel_api_cwmp_error:
|
||||
|
||||
if (kernel_cwmp_input.argv!=NULL)
|
||||
{
|
||||
for (i=0;i<kernel_cwmp_input.argc;i++)
|
||||
{
|
||||
if (kernel_cwmp_input.argv[i]!=NULL)
|
||||
{
|
||||
kfree(kernel_cwmp_input.argv[i]);
|
||||
}
|
||||
}
|
||||
kfree(kernel_cwmp_input.argv);
|
||||
kernel_cwmp_input.argv = NULL;
|
||||
}
|
||||
kernel_cwmp_input.argc = 0;
|
||||
mutex_unlock (&(kernel_cwmp_input.mutex));
|
||||
return 1;
|
||||
if (kernel_cwmp_input.argv != NULL) {
|
||||
for (i = 0; i < kernel_cwmp_input.argc; i++) {
|
||||
if (kernel_cwmp_input.argv[i] != NULL) {
|
||||
kfree(kernel_cwmp_input.argv[i]);
|
||||
}
|
||||
}
|
||||
kfree(kernel_cwmp_input.argv);
|
||||
kernel_cwmp_input.argv = NULL;
|
||||
}
|
||||
kernel_cwmp_input.argc = 0;
|
||||
mutex_unlock(&(kernel_cwmp_input.mutex));
|
||||
return 1;
|
||||
}
|
||||
EXPORT_SYMBOL(kernel_api_cwmp_value_change_call);
|
||||
|
||||
module_init(kernel_api_cwmp_value_change_init); module_exit(kernel_api_cwmp_value_change_exit);
|
||||
|
||||
module_init(kernel_api_cwmp_value_change_init);
|
||||
module_exit(kernel_api_cwmp_value_change_exit);
|
||||
|
|
|
|||
324
log.c
324
log.c
|
|
@ -15,215 +15,175 @@
|
|||
#include "common.h"
|
||||
#include "log.h"
|
||||
|
||||
static char *SEVERITY_NAMES[8] = {"[EMERG] ","[ALERT] ","[CRITIC] ","[ERROR] ","[WARNING]","[NOTICE] ","[INFO] ","[DEBUG] "};
|
||||
static int log_severity = DEFAULT_LOG_SEVERITY;
|
||||
static long int log_max_size = DEFAULT_LOG_FILE_SIZE;
|
||||
static char log_file_name[256];
|
||||
static bool enable_log_file = true;
|
||||
static bool enable_log_stdout = false;
|
||||
static pthread_mutex_t mutex_log = PTHREAD_MUTEX_INITIALIZER;
|
||||
static char *SEVERITY_NAMES[8] = { "[EMERG] ", "[ALERT] ", "[CRITIC] ", "[ERROR] ", "[WARNING]", "[NOTICE] ", "[INFO] ", "[DEBUG] " };
|
||||
static int log_severity = DEFAULT_LOG_SEVERITY;
|
||||
static long int log_max_size = DEFAULT_LOG_FILE_SIZE;
|
||||
static char log_file_name[256];
|
||||
static bool enable_log_file = true;
|
||||
static bool enable_log_stdout = false;
|
||||
static pthread_mutex_t mutex_log = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
int log_set_severity_idx (char *value)
|
||||
int log_set_severity_idx(char *value)
|
||||
{
|
||||
int i;
|
||||
for (i = 0;i < 8; i++) {
|
||||
if (strstr(SEVERITY_NAMES[i],value) != NULL) {
|
||||
log_severity = i;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
int i;
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (strstr(SEVERITY_NAMES[i], value) != NULL) {
|
||||
log_severity = i;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int log_set_log_file_name (char *value)
|
||||
int log_set_log_file_name(char *value)
|
||||
{
|
||||
if(value != NULL) {
|
||||
strcpy(log_file_name,value);
|
||||
} else {
|
||||
strcpy(log_file_name,DEFAULT_LOG_FILE_NAME);
|
||||
}
|
||||
return 1;
|
||||
if (value != NULL) {
|
||||
strcpy(log_file_name, value);
|
||||
} else {
|
||||
strcpy(log_file_name, DEFAULT_LOG_FILE_NAME);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
int log_set_file_max_size(char *value)
|
||||
{
|
||||
if(value != NULL)
|
||||
{
|
||||
log_max_size = atol(value);
|
||||
}
|
||||
return 1;
|
||||
if (value != NULL) {
|
||||
log_max_size = atol(value);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
int log_set_on_console(char *value)
|
||||
{
|
||||
if(strcmp(value,"enable") == 0)
|
||||
{
|
||||
enable_log_stdout = true;
|
||||
}
|
||||
if(strcmp(value,"disable") == 0)
|
||||
{
|
||||
enable_log_stdout = false;
|
||||
}
|
||||
return 1;
|
||||
if (strcmp(value, "enable") == 0) {
|
||||
enable_log_stdout = true;
|
||||
}
|
||||
if (strcmp(value, "disable") == 0) {
|
||||
enable_log_stdout = false;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
int log_set_on_file(char *value)
|
||||
{
|
||||
if(strcmp(value,"enable") == 0)
|
||||
{
|
||||
enable_log_file = true;
|
||||
}
|
||||
if(strcmp(value,"disable") == 0)
|
||||
{
|
||||
enable_log_file = false;
|
||||
}
|
||||
return 1;
|
||||
if (strcmp(value, "enable") == 0) {
|
||||
enable_log_file = true;
|
||||
}
|
||||
if (strcmp(value, "disable") == 0) {
|
||||
enable_log_file = false;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void puts_log(int severity, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int i;
|
||||
struct tm *Tm;
|
||||
struct timeval tv;
|
||||
FILE *pLog = NULL;
|
||||
struct stat st;
|
||||
long int size = 0;
|
||||
char log_file_name_bak[256];
|
||||
char buf[1024];
|
||||
char buf_file[1024];
|
||||
va_list args;
|
||||
int i;
|
||||
struct tm *Tm;
|
||||
struct timeval tv;
|
||||
FILE *pLog = NULL;
|
||||
struct stat st;
|
||||
long int size = 0;
|
||||
char log_file_name_bak[256];
|
||||
char buf[1024];
|
||||
char buf_file[1024];
|
||||
|
||||
if (severity>log_severity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_lock (&mutex_log);
|
||||
if (severity > log_severity) {
|
||||
return;
|
||||
}
|
||||
|
||||
gettimeofday(&tv, 0);
|
||||
Tm = localtime(&tv.tv_sec);
|
||||
i = sprintf(buf,"%02d-%02d-%4d, %02d:%02d:%02d %s ",
|
||||
Tm->tm_mday,
|
||||
Tm->tm_mon+1,
|
||||
Tm->tm_year+1900,
|
||||
Tm->tm_hour,
|
||||
Tm->tm_min,
|
||||
Tm->tm_sec,
|
||||
SEVERITY_NAMES[severity]);
|
||||
if(strlen(log_file_name) == 0)
|
||||
{
|
||||
strcpy(log_file_name,DEFAULT_LOG_FILE_NAME);
|
||||
}
|
||||
if(enable_log_file)
|
||||
{
|
||||
if (stat(log_file_name, &st) == 0)
|
||||
{
|
||||
size = st.st_size;
|
||||
}
|
||||
if(size >= log_max_size)
|
||||
{
|
||||
sprintf(log_file_name_bak,"%s.1",log_file_name);
|
||||
rename(log_file_name,log_file_name_bak);
|
||||
pLog = fopen(log_file_name,"w");
|
||||
}
|
||||
else
|
||||
{
|
||||
pLog = fopen(log_file_name,"a+");
|
||||
}
|
||||
}
|
||||
va_start(args, fmt);
|
||||
i += vsprintf(buf+i, fmt, args);
|
||||
if(enable_log_file)
|
||||
{
|
||||
strcpy(buf_file,buf);
|
||||
strcat(buf_file,"\n");
|
||||
fputs (buf_file, pLog);
|
||||
}
|
||||
va_end(args);
|
||||
if(enable_log_file)
|
||||
{
|
||||
fclose(pLog);
|
||||
}
|
||||
if(enable_log_stdout)
|
||||
{
|
||||
puts(buf);
|
||||
}
|
||||
pthread_mutex_unlock (&mutex_log);
|
||||
pthread_mutex_lock(&mutex_log);
|
||||
|
||||
gettimeofday(&tv, 0);
|
||||
Tm = localtime(&tv.tv_sec);
|
||||
i = sprintf(buf, "%02d-%02d-%4d, %02d:%02d:%02d %s ", Tm->tm_mday, Tm->tm_mon + 1, Tm->tm_year + 1900, Tm->tm_hour, Tm->tm_min, Tm->tm_sec, SEVERITY_NAMES[severity]);
|
||||
if (strlen(log_file_name) == 0) {
|
||||
strcpy(log_file_name, DEFAULT_LOG_FILE_NAME);
|
||||
}
|
||||
if (enable_log_file) {
|
||||
if (stat(log_file_name, &st) == 0) {
|
||||
size = st.st_size;
|
||||
}
|
||||
if (size >= log_max_size) {
|
||||
sprintf(log_file_name_bak, "%s.1", log_file_name);
|
||||
rename(log_file_name, log_file_name_bak);
|
||||
pLog = fopen(log_file_name, "w");
|
||||
} else {
|
||||
pLog = fopen(log_file_name, "a+");
|
||||
}
|
||||
}
|
||||
va_start(args, fmt);
|
||||
i += vsprintf(buf + i, fmt, args);
|
||||
if (enable_log_file) {
|
||||
strcpy(buf_file, buf);
|
||||
strcat(buf_file, "\n");
|
||||
fputs(buf_file, pLog);
|
||||
}
|
||||
va_end(args);
|
||||
if (enable_log_file) {
|
||||
fclose(pLog);
|
||||
}
|
||||
if (enable_log_stdout) {
|
||||
puts(buf);
|
||||
}
|
||||
pthread_mutex_unlock(&mutex_log);
|
||||
}
|
||||
|
||||
void puts_log_xmlmsg(int severity, char *msg, int msgtype)
|
||||
{
|
||||
struct tm *Tm;
|
||||
struct timeval tv;
|
||||
FILE *pLog = NULL;
|
||||
struct stat st;
|
||||
long int size = 0;
|
||||
char log_file_name_bak[256];
|
||||
char buf[1024];
|
||||
char *description, *separator;
|
||||
struct tm *Tm;
|
||||
struct timeval tv;
|
||||
FILE *pLog = NULL;
|
||||
struct stat st;
|
||||
long int size = 0;
|
||||
char log_file_name_bak[256];
|
||||
char buf[1024];
|
||||
char *description, *separator;
|
||||
|
||||
if (severity>log_severity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (severity > log_severity) {
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&mutex_log);
|
||||
pthread_mutex_lock(&mutex_log);
|
||||
|
||||
gettimeofday(&tv, 0);
|
||||
Tm = localtime(&tv.tv_sec);
|
||||
sprintf(buf,"%02d-%02d-%4d, %02d:%02d:%02d %s ",
|
||||
Tm->tm_mday,
|
||||
Tm->tm_mon+1,
|
||||
Tm->tm_year+1900,
|
||||
Tm->tm_hour,
|
||||
Tm->tm_min,
|
||||
Tm->tm_sec,
|
||||
SEVERITY_NAMES[severity]);
|
||||
if(strlen(log_file_name) == 0)
|
||||
{
|
||||
strcpy(log_file_name,DEFAULT_LOG_FILE_NAME);
|
||||
}
|
||||
gettimeofday(&tv, 0);
|
||||
Tm = localtime(&tv.tv_sec);
|
||||
sprintf(buf, "%02d-%02d-%4d, %02d:%02d:%02d %s ", Tm->tm_mday, Tm->tm_mon + 1, Tm->tm_year + 1900, Tm->tm_hour, Tm->tm_min, Tm->tm_sec, SEVERITY_NAMES[severity]);
|
||||
if (strlen(log_file_name) == 0) {
|
||||
strcpy(log_file_name, DEFAULT_LOG_FILE_NAME);
|
||||
}
|
||||
|
||||
if (msgtype == XML_MSG_IN) {
|
||||
description = "MESSAGE IN\n";
|
||||
separator = "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
|
||||
if (msgtype == XML_MSG_IN) {
|
||||
description = "MESSAGE IN\n";
|
||||
separator = "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
|
||||
|
||||
}
|
||||
else {
|
||||
description = "MESSAGE OUT\n";
|
||||
separator = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
|
||||
}
|
||||
if(enable_log_file)
|
||||
{
|
||||
|
||||
if (stat(log_file_name, &st) == 0)
|
||||
{
|
||||
size = st.st_size;
|
||||
}
|
||||
if(size >= log_max_size)
|
||||
{
|
||||
sprintf(log_file_name_bak,"%s.1",log_file_name);
|
||||
rename(log_file_name,log_file_name_bak);
|
||||
pLog = fopen(log_file_name,"w");
|
||||
}
|
||||
else
|
||||
{
|
||||
pLog = fopen(log_file_name,"a+");
|
||||
}
|
||||
fputs (buf, pLog);
|
||||
fputs(description, pLog);
|
||||
fputs(separator, pLog);
|
||||
fputs (msg, pLog);
|
||||
fputs ("\n", pLog);
|
||||
fputs(separator, pLog);
|
||||
fclose(pLog);
|
||||
|
||||
}
|
||||
if(enable_log_stdout)
|
||||
{
|
||||
puts (buf);
|
||||
puts(description);
|
||||
puts(separator);
|
||||
puts (msg);
|
||||
puts ("\n");
|
||||
puts(separator);
|
||||
}
|
||||
pthread_mutex_unlock (&mutex_log);
|
||||
} else {
|
||||
description = "MESSAGE OUT\n";
|
||||
separator = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
|
||||
}
|
||||
if (enable_log_file) {
|
||||
if (stat(log_file_name, &st) == 0) {
|
||||
size = st.st_size;
|
||||
}
|
||||
if (size >= log_max_size) {
|
||||
sprintf(log_file_name_bak, "%s.1", log_file_name);
|
||||
rename(log_file_name, log_file_name_bak);
|
||||
pLog = fopen(log_file_name, "w");
|
||||
} else {
|
||||
pLog = fopen(log_file_name, "a+");
|
||||
}
|
||||
fputs(buf, pLog);
|
||||
fputs(description, pLog);
|
||||
fputs(separator, pLog);
|
||||
fputs(msg, pLog);
|
||||
fputs("\n", pLog);
|
||||
fputs(separator, pLog);
|
||||
fclose(pLog);
|
||||
}
|
||||
if (enable_log_stdout) {
|
||||
puts(buf);
|
||||
puts(description);
|
||||
puts(separator);
|
||||
puts(msg);
|
||||
puts("\n");
|
||||
puts(separator);
|
||||
}
|
||||
pthread_mutex_unlock(&mutex_log);
|
||||
}
|
||||
|
|
|
|||
335
md5.c
335
md5.c
|
|
@ -17,31 +17,27 @@
|
|||
|
||||
#include "md5.h"
|
||||
|
||||
# if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define HIGHFIRST
|
||||
#endif
|
||||
|
||||
#ifndef HIGHFIRST
|
||||
#define byteReverse(buf, len) /* Nothing */
|
||||
#define byteReverse(buf, len) /* Nothing */
|
||||
#else
|
||||
/*
|
||||
* Note: this code is harmless on little-endian machines.
|
||||
*/
|
||||
static void
|
||||
byteReverse(unsigned char *buf,
|
||||
unsigned longs)
|
||||
static void byteReverse(unsigned char *buf, unsigned longs)
|
||||
{
|
||||
uint32_t t;
|
||||
do {
|
||||
t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
|
||||
((unsigned) buf[1] << 8 | buf[0]);
|
||||
*(uint32_t *) buf = t;
|
||||
buf += 4;
|
||||
} while (--longs);
|
||||
uint32_t t;
|
||||
do {
|
||||
t = (uint32_t)((unsigned)buf[3] << 8 | buf[2]) << 16 | ((unsigned)buf[1] << 8 | buf[0]);
|
||||
*(uint32_t *)buf = t;
|
||||
buf += 4;
|
||||
} while (--longs);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* The four core functions - F1 is optimized somewhat */
|
||||
|
||||
/* #define F1(x, y, z) (x & y | ~x & z) */
|
||||
|
|
@ -51,216 +47,203 @@ byteReverse(unsigned char *buf,
|
|||
#define F4(x, y, z) (y ^ (x | ~z))
|
||||
|
||||
/* This is the central step in the MD5 algorithm. */
|
||||
#define MD5STEP(f, w, x, y, z, data, s) \
|
||||
( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
|
||||
#define MD5STEP(f, w, x, y, z, data, s) (w += f(x, y, z) + data, w = w << s | w >> (32 - s), w += x)
|
||||
|
||||
/*
|
||||
* The core of the MD5 algorithm, this alters an existing MD5 hash to
|
||||
* reflect the addition of 16 longwords of new data. MD5Update blocks
|
||||
* the data and converts bytes into longwords for this routine.
|
||||
*/
|
||||
static void
|
||||
MD5Transform(uint32_t buf[4],
|
||||
uint32_t in[16])
|
||||
static void MD5Transform(uint32_t buf[4], uint32_t in[16])
|
||||
{
|
||||
uint32_t a, b, c, d;
|
||||
uint32_t a, b, c, d;
|
||||
|
||||
a = buf[0];
|
||||
b = buf[1];
|
||||
c = buf[2];
|
||||
d = buf[3];
|
||||
a = buf[0];
|
||||
b = buf[1];
|
||||
c = buf[2];
|
||||
d = buf[3];
|
||||
|
||||
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
|
||||
|
||||
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
|
||||
|
||||
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
|
||||
|
||||
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
|
||||
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
|
||||
* initialization constants.
|
||||
*/
|
||||
void
|
||||
MD5Init(struct MD5Context *ctx)
|
||||
void MD5Init(struct MD5Context *ctx)
|
||||
{
|
||||
ctx->buf[0] = 0x67452301;
|
||||
ctx->buf[1] = 0xefcdab89;
|
||||
ctx->buf[2] = 0x98badcfe;
|
||||
ctx->buf[3] = 0x10325476;
|
||||
ctx->buf[0] = 0x67452301;
|
||||
ctx->buf[1] = 0xefcdab89;
|
||||
ctx->buf[2] = 0x98badcfe;
|
||||
ctx->buf[3] = 0x10325476;
|
||||
|
||||
ctx->bits[0] = 0;
|
||||
ctx->bits[1] = 0;
|
||||
ctx->bits[0] = 0;
|
||||
ctx->bits[1] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update context to reflect the concatenation of another buffer full
|
||||
* of bytes.
|
||||
*/
|
||||
void
|
||||
MD5Update(struct MD5Context *ctx,
|
||||
const void *data,
|
||||
unsigned len)
|
||||
void MD5Update(struct MD5Context *ctx, const void *data, unsigned len)
|
||||
{
|
||||
const unsigned char *buf = data;
|
||||
uint32_t t;
|
||||
const unsigned char *buf = data;
|
||||
uint32_t t;
|
||||
|
||||
/* Update bitcount */
|
||||
/* Update bitcount */
|
||||
|
||||
t = ctx->bits[0];
|
||||
if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t)
|
||||
ctx->bits[1]++; /* Carry from low to high */
|
||||
ctx->bits[1] += len >> 29;
|
||||
t = ctx->bits[0];
|
||||
if ((ctx->bits[0] = t + ((uint32_t)len << 3)) < t)
|
||||
ctx->bits[1]++; /* Carry from low to high */
|
||||
ctx->bits[1] += len >> 29;
|
||||
|
||||
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
|
||||
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
|
||||
|
||||
/* Handle any leading odd-sized chunks */
|
||||
/* Handle any leading odd-sized chunks */
|
||||
|
||||
if (t) {
|
||||
unsigned char *p = (unsigned char *) ctx->in + t;
|
||||
if (t) {
|
||||
unsigned char *p = (unsigned char *)ctx->in + t;
|
||||
|
||||
t = 64 - t;
|
||||
if (len < t) {
|
||||
memcpy(p, buf, len);
|
||||
return;
|
||||
t = 64 - t;
|
||||
if (len < t) {
|
||||
memcpy(p, buf, len);
|
||||
return;
|
||||
}
|
||||
memcpy(p, buf, t);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32_t *)ctx->in);
|
||||
buf += t;
|
||||
len -= t;
|
||||
}
|
||||
memcpy(p, buf, t);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32_t *) ctx->in);
|
||||
buf += t;
|
||||
len -= t;
|
||||
}
|
||||
/* Process data in 64-byte chunks */
|
||||
/* Process data in 64-byte chunks */
|
||||
|
||||
while (len >= 64) {
|
||||
memcpy(ctx->in, buf, 64);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32_t *) ctx->in);
|
||||
buf += 64;
|
||||
len -= 64;
|
||||
}
|
||||
while (len >= 64) {
|
||||
memcpy(ctx->in, buf, 64);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32_t *)ctx->in);
|
||||
buf += 64;
|
||||
len -= 64;
|
||||
}
|
||||
|
||||
/* Handle any remaining bytes of data. */
|
||||
/* Handle any remaining bytes of data. */
|
||||
|
||||
memcpy(ctx->in, buf, len);
|
||||
memcpy(ctx->in, buf, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Final wrapup - pad to 64-byte boundary with the bit pattern
|
||||
* 1 0* (64-bit count of bits processed, MSB-first)
|
||||
*/
|
||||
void
|
||||
MD5Final(unsigned char digest[16],
|
||||
struct MD5Context *ctx)
|
||||
void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
|
||||
{
|
||||
unsigned count;
|
||||
unsigned char *p;
|
||||
unsigned count;
|
||||
unsigned char *p;
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
count = (ctx->bits[0] >> 3) & 0x3F;
|
||||
|
||||
/* Set the first char of padding to 0x80. This is safe since there is
|
||||
/* Compute number of bytes mod 64 */
|
||||
count = (ctx->bits[0] >> 3) & 0x3F;
|
||||
|
||||
/* Set the first char of padding to 0x80. This is safe since there is
|
||||
always at least one byte free */
|
||||
p = ctx->in + count;
|
||||
*p++ = 0x80;
|
||||
|
||||
/* Bytes of padding needed to make 64 bytes */
|
||||
count = 64 - 1 - count;
|
||||
|
||||
/* Pad out to 56 mod 64 */
|
||||
if (count < 8)
|
||||
{
|
||||
/* Two lots of padding: Pad the first block to 64 bytes */
|
||||
memset(p, 0, count);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32_t *) ctx->in);
|
||||
|
||||
/* Now fill the next block with 56 bytes */
|
||||
memset(ctx->in, 0, 56);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Pad block to 56 bytes */
|
||||
memset(p, 0, count - 8);
|
||||
}
|
||||
byteReverse(ctx->in, 14);
|
||||
|
||||
/* Append length in bits and transform */
|
||||
((uint32_t *) ctx->in)[14] = ctx->bits[0];
|
||||
((uint32_t *) ctx->in)[15] = ctx->bits[1];
|
||||
|
||||
MD5Transform(ctx->buf, (uint32_t *) ctx->in);
|
||||
byteReverse((unsigned char *) ctx->buf, 4);
|
||||
memcpy(digest, ctx->buf, 16);
|
||||
memset(ctx, 0, sizeof(struct MD5Context)); /* In case it's sensitive */
|
||||
p = ctx->in + count;
|
||||
*p++ = 0x80;
|
||||
|
||||
/* Bytes of padding needed to make 64 bytes */
|
||||
count = 64 - 1 - count;
|
||||
|
||||
/* Pad out to 56 mod 64 */
|
||||
if (count < 8) {
|
||||
/* Two lots of padding: Pad the first block to 64 bytes */
|
||||
memset(p, 0, count);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32_t *)ctx->in);
|
||||
|
||||
/* Now fill the next block with 56 bytes */
|
||||
memset(ctx->in, 0, 56);
|
||||
} else {
|
||||
/* Pad block to 56 bytes */
|
||||
memset(p, 0, count - 8);
|
||||
}
|
||||
byteReverse(ctx->in, 14);
|
||||
|
||||
/* Append length in bits and transform */
|
||||
((uint32_t *)ctx->in)[14] = ctx->bits[0];
|
||||
((uint32_t *)ctx->in)[15] = ctx->bits[1];
|
||||
|
||||
MD5Transform(ctx->buf, (uint32_t *)ctx->in);
|
||||
byteReverse((unsigned char *)ctx->buf, 4);
|
||||
memcpy(digest, ctx->buf, 16);
|
||||
memset(ctx, 0, sizeof(struct MD5Context)); /* In case it's sensitive */
|
||||
}
|
||||
|
||||
/* end of md5.c */
|
||||
|
|
|
|||
76
netlink.c
76
netlink.c
|
|
@ -37,8 +37,8 @@
|
|||
|
||||
static int itfcmp(char *itf1, char *itf2);
|
||||
static void netlink_new_msg(struct uloop_fd *ufd, unsigned events);
|
||||
static struct uloop_fd netlink_event = { .cb = netlink_new_msg };
|
||||
static struct uloop_fd netlink_event_v6 = { .cb = netlink_new_msg };
|
||||
static struct uloop_fd netlink_event = {.cb = netlink_new_msg };
|
||||
static struct uloop_fd netlink_event_v6 = {.cb = netlink_new_msg };
|
||||
|
||||
static int itfcmp(char *itf1, char *itf2)
|
||||
{
|
||||
|
|
@ -48,45 +48,45 @@ static int itfcmp(char *itf1, char *itf2)
|
|||
char *buf1 = NULL;
|
||||
char *buf2 = NULL;
|
||||
|
||||
if(itf1[0] == '\0')
|
||||
if (itf1[0] == '\0')
|
||||
goto end;
|
||||
str = strchr(itf1, '.');
|
||||
if(str == NULL)
|
||||
goto end;
|
||||
if (str == NULL)
|
||||
goto end;
|
||||
index = (int)(str - itf1);
|
||||
if(!index)
|
||||
if (!index)
|
||||
goto end;
|
||||
buf1 = malloc(index);
|
||||
strncpy(buf1, itf1, index);
|
||||
if(!buf1)
|
||||
if (!buf1)
|
||||
goto end;
|
||||
buf1[index] = '\0';
|
||||
if(itf2[0] == '\0')
|
||||
if (itf2[0] == '\0')
|
||||
goto end;
|
||||
str = strchr(itf2, '.');
|
||||
if(str == NULL)
|
||||
goto end;
|
||||
if (str == NULL)
|
||||
goto end;
|
||||
index = (int)(str - itf2);
|
||||
if(!index)
|
||||
if (!index)
|
||||
goto end;
|
||||
buf2 = malloc(index);
|
||||
if(!buf2)
|
||||
if (!buf2)
|
||||
goto end;
|
||||
buf2[index] = '\0';
|
||||
strncpy(buf2, itf1, index);
|
||||
if(strcmp(buf1, buf2) == 0)
|
||||
if (strcmp(buf1, buf2) == 0)
|
||||
status = 0;
|
||||
end:
|
||||
if(buf1)
|
||||
if (buf1)
|
||||
free(buf1);
|
||||
if(buf2)
|
||||
if (buf2)
|
||||
free(buf2);
|
||||
return status;
|
||||
}
|
||||
|
||||
static void freecwmp_netlink_interface(struct nlmsghdr *nlh)
|
||||
{
|
||||
struct ifaddrmsg *ifa = (struct ifaddrmsg *) NLMSG_DATA(nlh);
|
||||
struct ifaddrmsg *ifa = (struct ifaddrmsg *)NLMSG_DATA(nlh);
|
||||
struct rtattr *rth = IFA_RTA(ifa);
|
||||
int rtl = IFA_PAYLOAD(nlh);
|
||||
char if_name[IFNAMSIZ], if_addr[INET_ADDRSTRLEN];
|
||||
|
|
@ -96,14 +96,14 @@ static void freecwmp_netlink_interface(struct nlmsghdr *nlh)
|
|||
memset(&if_addr, 0, sizeof(if_addr));
|
||||
|
||||
char pradd_v6[128];
|
||||
if(ifa->ifa_family == AF_INET) { //CASE IPv4
|
||||
if (ifa->ifa_family == AF_INET) { //CASE IPv4
|
||||
while (rtl && RTA_OK(rth, rtl)) {
|
||||
if (rth->rta_type != IFA_LOCAL) {
|
||||
rth = RTA_NEXT(rth, rtl);
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t addr = htonl(* (uint32_t *)RTA_DATA(rth));
|
||||
uint32_t addr = htonl(*(uint32_t *)RTA_DATA(rth));
|
||||
if (htonl(13) == 13) {
|
||||
// running on big endian system
|
||||
} else {
|
||||
|
|
@ -119,10 +119,10 @@ static void freecwmp_netlink_interface(struct nlmsghdr *nlh)
|
|||
|
||||
inet_ntop(AF_INET, &(addr), if_addr, INET_ADDRSTRLEN);
|
||||
|
||||
if (cwmp_main.conf.ip) FREE(cwmp_main.conf.ip);
|
||||
if (cwmp_main.conf.ip)
|
||||
FREE(cwmp_main.conf.ip);
|
||||
cwmp_main.conf.ip = strdup(if_addr);
|
||||
if (asprintf(&c,"cwmp.cpe.ip=%s",cwmp_main.conf.ip) != -1)
|
||||
{
|
||||
if (asprintf(&c, "cwmp.cpe.ip=%s", cwmp_main.conf.ip) != -1) {
|
||||
uci_set_state_value(c);
|
||||
free(c);
|
||||
}
|
||||
|
|
@ -141,10 +141,10 @@ static void freecwmp_netlink_interface(struct nlmsghdr *nlh)
|
|||
rth = RTA_NEXT(rth, rtl);
|
||||
continue;
|
||||
}
|
||||
if (cwmp_main.conf.ipv6) FREE(cwmp_main.conf.ipv6);
|
||||
if (cwmp_main.conf.ipv6)
|
||||
FREE(cwmp_main.conf.ipv6);
|
||||
cwmp_main.conf.ipv6 = strdup(pradd_v6);
|
||||
if (asprintf(&c,"cwmp.cpe.ipv6=%s",cwmp_main.conf.ipv6) != -1)
|
||||
{
|
||||
if (asprintf(&c, "cwmp.cpe.ipv6=%s", cwmp_main.conf.ipv6) != -1) {
|
||||
uci_set_state_value(c);
|
||||
free(c);
|
||||
}
|
||||
|
|
@ -164,7 +164,7 @@ static void netlink_new_msg(struct uloop_fd *ufd, unsigned events __attribute__(
|
|||
|
||||
nlh = (struct nlmsghdr *)buffer;
|
||||
if ((int)(msg_size = recv(ufd->fd, nlh, BUFSIZ, 0)) == -1) {
|
||||
CWMP_LOG(ERROR,"error receiving netlink message");
|
||||
CWMP_LOG(ERROR, "error receiving netlink message");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -173,12 +173,12 @@ static void netlink_new_msg(struct uloop_fd *ufd, unsigned events __attribute__(
|
|||
int req_len = len - sizeof(*nlh);
|
||||
|
||||
if (req_len < 0 || (size_t)len > msg_size) {
|
||||
CWMP_LOG(ERROR,"error reading netlink message");
|
||||
CWMP_LOG(ERROR, "error reading netlink message");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NLMSG_OK(nlh, msg_size)) {
|
||||
CWMP_LOG(ERROR,"netlink message is not NLMSG_OK");
|
||||
CWMP_LOG(ERROR, "netlink message is not NLMSG_OK");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -186,7 +186,7 @@ static void netlink_new_msg(struct uloop_fd *ufd, unsigned events __attribute__(
|
|||
freecwmp_netlink_interface(nlh);
|
||||
|
||||
msg_size -= NLMSG_ALIGN(len);
|
||||
nlh = (struct nlmsghdr*)((char*)nlh + NLMSG_ALIGN(len));
|
||||
nlh = (struct nlmsghdr *)((char *)nlh + NLMSG_ALIGN(len));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -203,14 +203,14 @@ int netlink_init_v6(void)
|
|||
memset(&req, 0, sizeof(req));
|
||||
|
||||
if ((sock[0] = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) == -1) {
|
||||
CWMP_LOG(ERROR,"couldn't open NETLINK_ROUTE socket");
|
||||
CWMP_LOG(ERROR, "couldn't open NETLINK_ROUTE socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
addr.nl_family = AF_NETLINK;
|
||||
addr.nl_groups = RTMGRP_IPV6_IFADDR;
|
||||
if ((bind(sock[0], (struct sockaddr *)&addr, sizeof(addr))) == -1) {
|
||||
CWMP_LOG(ERROR,"couldn't bind netlink socket");
|
||||
CWMP_LOG(ERROR, "couldn't bind netlink socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -218,7 +218,7 @@ int netlink_init_v6(void)
|
|||
uloop_fd_add(&netlink_event_v6, ULOOP_READ | ULOOP_EDGE_TRIGGER);
|
||||
|
||||
if ((sock[1] = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) == -1) {
|
||||
CWMP_LOG(ERROR,"couldn't open NETLINK_ROUTE socket");
|
||||
CWMP_LOG(ERROR, "couldn't open NETLINK_ROUTE socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -228,11 +228,11 @@ int netlink_init_v6(void)
|
|||
req.msg.ifa_family = AF_INET6;
|
||||
|
||||
if ((send(sock[1], &req, req.hdr.nlmsg_len, 0)) == -1) {
|
||||
CWMP_LOG(ERROR,"couldn't send netlink socket");
|
||||
CWMP_LOG(ERROR, "couldn't send netlink socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct uloop_fd dummy_event = { .fd = sock[1] };
|
||||
struct uloop_fd dummy_event = {.fd = sock[1] };
|
||||
netlink_new_msg(&dummy_event, 0);
|
||||
|
||||
return 0;
|
||||
|
|
@ -251,14 +251,14 @@ int netlink_init(void)
|
|||
memset(&req, 0, sizeof(req));
|
||||
|
||||
if ((sock[0] = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) == -1) {
|
||||
CWMP_LOG(ERROR,"couldn't open NETLINK_ROUTE socket");
|
||||
CWMP_LOG(ERROR, "couldn't open NETLINK_ROUTE socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
addr.nl_family = AF_NETLINK;
|
||||
addr.nl_groups = RTMGRP_IPV4_IFADDR;
|
||||
if ((bind(sock[0], (struct sockaddr *)&addr, sizeof(addr))) == -1) {
|
||||
CWMP_LOG(ERROR,"couldn't bind netlink socket");
|
||||
CWMP_LOG(ERROR, "couldn't bind netlink socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -266,7 +266,7 @@ int netlink_init(void)
|
|||
uloop_fd_add(&netlink_event, ULOOP_READ | ULOOP_EDGE_TRIGGER);
|
||||
|
||||
if ((sock[1] = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) == -1) {
|
||||
CWMP_LOG(ERROR,"couldn't open NETLINK_ROUTE socket");
|
||||
CWMP_LOG(ERROR, "couldn't open NETLINK_ROUTE socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -276,11 +276,11 @@ int netlink_init(void)
|
|||
req.msg.ifa_family = AF_INET;
|
||||
|
||||
if ((send(sock[1], &req, req.hdr.nlmsg_len, 0)) == -1) {
|
||||
CWMP_LOG(ERROR,"couldn't send netlink socket");
|
||||
CWMP_LOG(ERROR, "couldn't send netlink socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct uloop_fd dummy_event = { .fd = sock[1] };
|
||||
struct uloop_fd dummy_event = {.fd = sock[1] };
|
||||
netlink_new_msg(&dummy_event, 0);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
154
notifications.c
154
notifications.c
|
|
@ -34,35 +34,40 @@ int cwmp_update_enabled_notify_file()
|
|||
if (fp == NULL) {
|
||||
return 0;
|
||||
}
|
||||
foreach_jsonobj_in_array(param_obj, old_list_notify) {
|
||||
foreach_jsonobj_in_array(param_obj, old_list_notify)
|
||||
{
|
||||
json_object_object_get_ex(param_obj, "parameter", ¶m_name_obj);
|
||||
if (!param_name_obj || strlen((char*)json_object_get_string(param_name_obj))<=0)
|
||||
if (!param_name_obj || strlen((char *)json_object_get_string(param_name_obj)) <= 0)
|
||||
continue;
|
||||
json_object_object_get_ex(param_obj, "value", &value_obj);
|
||||
json_object_object_get_ex(param_obj, "type", &type_obj);
|
||||
json_object_object_get_ex(param_obj, "notification", ¬ification_obj);
|
||||
cwmp_json_fprintf(fp, 4, CWMP_JSON_ARGS{{"parameter", (char*)json_object_get_string(param_name_obj)}, {"notification", notification_obj?(char*)json_object_get_string(notification_obj):""}, {"value", value_obj?(char*)json_object_get_string(value_obj):""}, {"type", type_obj?(char*)json_object_get_string(type_obj):""}});
|
||||
cwmp_json_fprintf(fp, 4, CWMP_JSON_ARGS{ { "parameter", (char *)json_object_get_string(param_name_obj) },
|
||||
{ "notification", notification_obj ? (char *)json_object_get_string(notification_obj) : "" },
|
||||
{ "value", value_obj ? (char *)json_object_get_string(value_obj) : "" },
|
||||
{ "type", type_obj ? (char *)json_object_get_string(type_obj) : "" } });
|
||||
}
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void get_parameter_value_from_parameters_list(json_object* list_params_obj, char* parameter_name, struct cwmp_dm_parameter **ret_dm_param)
|
||||
void get_parameter_value_from_parameters_list(json_object *list_params_obj, char *parameter_name, struct cwmp_dm_parameter **ret_dm_param)
|
||||
{
|
||||
json_object *param_obj = NULL, *param_name_obj = NULL, *value_obj = NULL, *type_obj = NULL;
|
||||
|
||||
foreach_jsonobj_in_array(param_obj, list_params_obj) {
|
||||
foreach_jsonobj_in_array(param_obj, list_params_obj)
|
||||
{
|
||||
json_object_object_get_ex(param_obj, "parameter", ¶m_name_obj);
|
||||
if (!param_name_obj || strlen((char*)json_object_get_string(param_name_obj))<=0)
|
||||
if (!param_name_obj || strlen((char *)json_object_get_string(param_name_obj)) <= 0)
|
||||
continue;
|
||||
if (strcmp((char*)json_object_get_string(param_name_obj), parameter_name) != 0)
|
||||
if (strcmp((char *)json_object_get_string(param_name_obj), parameter_name) != 0)
|
||||
continue;
|
||||
*ret_dm_param = (struct cwmp_dm_parameter*) calloc(1,sizeof(struct cwmp_dm_parameter));
|
||||
*ret_dm_param = (struct cwmp_dm_parameter *)calloc(1, sizeof(struct cwmp_dm_parameter));
|
||||
json_object_object_get_ex(param_obj, "value", &value_obj);
|
||||
(*ret_dm_param)->name = strdup(parameter_name);
|
||||
(*ret_dm_param)->data = strdup(value_obj?(char*)json_object_get_string(value_obj):"");
|
||||
(*ret_dm_param)->data = strdup(value_obj ? (char *)json_object_get_string(value_obj) : "");
|
||||
json_object_object_get_ex(param_obj, "type", &type_obj);
|
||||
(*ret_dm_param)->type = strdup(type_obj?(char*)json_object_get_string(type_obj):"");
|
||||
(*ret_dm_param)->type = strdup(type_obj ? (char *)json_object_get_string(type_obj) : "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -86,16 +91,16 @@ int check_value_change(void)
|
|||
while (fgets(buf, 512, fp) != NULL) {
|
||||
int len = strlen(buf);
|
||||
if (len)
|
||||
buf[len-1] = '\0';
|
||||
buf[len - 1] = '\0';
|
||||
cwmp_json_obj_init(buf, &buf_json_obj);
|
||||
json_object_object_get_ex(buf_json_obj, "parameter", ¶m_name_obj);
|
||||
if(param_name_obj == NULL || strlen((char*)json_object_get_string(param_name_obj))<= 0)
|
||||
if (param_name_obj == NULL || strlen((char *)json_object_get_string(param_name_obj)) <= 0)
|
||||
continue;
|
||||
parameter = strdup((char*)json_object_get_string(param_name_obj));
|
||||
parameter = strdup((char *)json_object_get_string(param_name_obj));
|
||||
json_object_object_get_ex(buf_json_obj, "value", &value_obj);
|
||||
json_object_object_get_ex(buf_json_obj, "notification", ¬ification_obj);
|
||||
value =strdup(value_obj?(char*)json_object_get_string(value_obj):"");
|
||||
notification = strdup(notification_obj?(char*)json_object_get_string(notification_obj):"");
|
||||
value = strdup(value_obj ? (char *)json_object_get_string(value_obj) : "");
|
||||
notification = strdup(notification_obj ? (char *)json_object_get_string(notification_obj) : "");
|
||||
cwmp_json_obj_clean(&buf_json_obj);
|
||||
if (param_name_obj) {
|
||||
json_object_put(param_name_obj);
|
||||
|
|
@ -112,10 +117,10 @@ int check_value_change(void)
|
|||
get_parameter_value_from_parameters_list(actual_list_notify, parameter, &dm_parameter);
|
||||
if (dm_parameter == NULL)
|
||||
continue;
|
||||
if (notification && (strlen(notification) > 0) && (notification[0] >= '1') && (dm_parameter->data != NULL) && (value != NULL) && (strcmp(dm_parameter->data, value) != 0)){
|
||||
if (notification && (strlen(notification) > 0) && (notification[0] >= '1') && (dm_parameter->data != NULL) && (value != NULL) && (strcmp(dm_parameter->data, value) != 0)) {
|
||||
if (notification[0] == '1' || notification[0] == '2')
|
||||
add_list_value_change(parameter, dm_parameter->data, dm_parameter->type);
|
||||
if (notification[0] >= '3' )
|
||||
if (notification[0] >= '3')
|
||||
add_lw_list_value_change(parameter, dm_parameter->data, dm_parameter->type);
|
||||
|
||||
if (notification[0] == '1')
|
||||
|
|
@ -133,7 +138,6 @@ int check_value_change(void)
|
|||
FREE(dm_parameter->data);
|
||||
FREE(dm_parameter->type);
|
||||
FREE(dm_parameter);
|
||||
|
||||
}
|
||||
fclose(fp);
|
||||
return is_notify;
|
||||
|
|
@ -147,47 +151,45 @@ void sotfware_version_value_change(struct cwmp *cwmp, struct transfer_complete *
|
|||
return;
|
||||
|
||||
current_software_version = cwmp->deviceid.softwareversion;
|
||||
if (p->old_software_version && current_software_version &&
|
||||
strcmp(p->old_software_version, current_software_version) != 0) {
|
||||
pthread_mutex_lock (&(cwmp->mutex_session_queue));
|
||||
cwmp_add_event_container (cwmp, EVENT_IDX_4VALUE_CHANGE, "");
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
if (p->old_software_version && current_software_version && strcmp(p->old_software_version, current_software_version) != 0) {
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_queue));
|
||||
cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, "");
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
}
|
||||
}
|
||||
|
||||
void *thread_periodic_check_notify (void *v)
|
||||
void *thread_periodic_check_notify(void *v)
|
||||
{
|
||||
struct cwmp *cwmp = (struct cwmp *) v;
|
||||
static int periodic_interval;
|
||||
static bool periodic_enable;
|
||||
static struct timespec periodic_timeout = {0, 0};
|
||||
time_t current_time;
|
||||
int is_notify;
|
||||
struct cwmp *cwmp = (struct cwmp *)v;
|
||||
static int periodic_interval;
|
||||
static bool periodic_enable;
|
||||
static struct timespec periodic_timeout = { 0, 0 };
|
||||
time_t current_time;
|
||||
int is_notify;
|
||||
|
||||
periodic_interval = cwmp->conf.periodic_notify_interval;
|
||||
periodic_enable = cwmp->conf.periodic_notify_enable;
|
||||
periodic_interval = cwmp->conf.periodic_notify_interval;
|
||||
periodic_enable = cwmp->conf.periodic_notify_enable;
|
||||
|
||||
for(;;) {
|
||||
if (periodic_enable) {
|
||||
pthread_mutex_lock (&(cwmp->mutex_notify_periodic));
|
||||
current_time = time(NULL);
|
||||
periodic_timeout.tv_sec = current_time + periodic_interval;
|
||||
pthread_cond_timedwait(&(cwmp->threshold_notify_periodic), &(cwmp->mutex_notify_periodic), &periodic_timeout);
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_send));
|
||||
is_notify = check_value_change();
|
||||
if (is_notify > 0)
|
||||
cwmp_update_enabled_notify_file();
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_send));
|
||||
if (is_notify & NOTIF_ACTIVE)
|
||||
send_active_value_change();
|
||||
if (is_notify & NOTIF_LW_ACTIVE)
|
||||
cwmp_lwnotification();
|
||||
pthread_mutex_unlock (&(cwmp->mutex_notify_periodic));
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return CWMP_OK;
|
||||
for (;;) {
|
||||
if (periodic_enable) {
|
||||
pthread_mutex_lock(&(cwmp->mutex_notify_periodic));
|
||||
current_time = time(NULL);
|
||||
periodic_timeout.tv_sec = current_time + periodic_interval;
|
||||
pthread_cond_timedwait(&(cwmp->threshold_notify_periodic), &(cwmp->mutex_notify_periodic), &periodic_timeout);
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_send));
|
||||
is_notify = check_value_change();
|
||||
if (is_notify > 0)
|
||||
cwmp_update_enabled_notify_file();
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_send));
|
||||
if (is_notify & NOTIF_ACTIVE)
|
||||
send_active_value_change();
|
||||
if (is_notify & NOTIF_LW_ACTIVE)
|
||||
cwmp_lwnotification();
|
||||
pthread_mutex_unlock(&(cwmp->mutex_notify_periodic));
|
||||
} else
|
||||
break;
|
||||
}
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
void add_list_value_change(char *param_name, char *param_data, char *param_type)
|
||||
|
|
@ -218,22 +220,18 @@ void send_active_value_change(void)
|
|||
/*
|
||||
* Light Weight Notifications
|
||||
*/
|
||||
void add_lw_list_value_change(char *param_name, char *param_data, char *param_type)
|
||||
{
|
||||
add_dm_parameter_tolist(&list_lw_value_change, param_name, param_data, param_type);
|
||||
}
|
||||
|
||||
void add_lw_list_value_change(char *param_name, char *param_data, char *param_type) { add_dm_parameter_tolist(&list_lw_value_change, param_name, param_data, param_type); }
|
||||
static void udplw_server_param(struct addrinfo **res)
|
||||
{
|
||||
struct addrinfo hints = {0};
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
struct config *conf;
|
||||
struct addrinfo hints = { 0 };
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
struct config *conf;
|
||||
char *port;
|
||||
conf = &(cwmp->conf);
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
asprintf(&port, "%d", conf->lw_notification_port);
|
||||
getaddrinfo(conf->lw_notification_hostname,port,&hints,res);
|
||||
getaddrinfo(conf->lw_notification_hostname, port, &hints, res);
|
||||
//FREE(port);
|
||||
}
|
||||
|
||||
|
|
@ -242,30 +240,29 @@ static void message_compute_signature(char *msg_out, char *signature)
|
|||
int i;
|
||||
int result_len = 20;
|
||||
unsigned char *result;
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
struct config *conf;
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
struct config *conf;
|
||||
conf = &(cwmp->conf);
|
||||
/* unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
|
||||
/* unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
|
||||
const unsigned char *d, size_t n, unsigned char *md,
|
||||
unsigned int *md_len);*/
|
||||
result = HMAC(EVP_sha1(), conf->acs_passwd, strlen(conf->acs_passwd),
|
||||
(unsigned char *)msg_out, strlen(msg_out), NULL, NULL);
|
||||
result = HMAC(EVP_sha1(), conf->acs_passwd, strlen(conf->acs_passwd), (unsigned char *)msg_out, strlen(msg_out), NULL, NULL);
|
||||
for (i = 0; i < result_len; i++) {
|
||||
sprintf(&(signature[i * 2]), "%02X", result[i]);
|
||||
}
|
||||
signature[i * 2 ] = '\0';
|
||||
signature[i * 2] = '\0';
|
||||
FREE(result);
|
||||
}
|
||||
|
||||
char *calculate_lwnotification_cnonce()
|
||||
{
|
||||
int i;
|
||||
char *cnonce = malloc( 33 * sizeof(char));
|
||||
srand((unsigned int) time(NULL));
|
||||
char *cnonce = malloc(33 * sizeof(char));
|
||||
srand((unsigned int)time(NULL));
|
||||
for (i = 0; i < 4; i++) {
|
||||
sprintf(&(cnonce[i * 8]), "%08x", rand());
|
||||
}
|
||||
cnonce[i * 8 ] = '\0';
|
||||
cnonce[i * 8] = '\0';
|
||||
return cnonce;
|
||||
}
|
||||
|
||||
|
|
@ -275,7 +272,7 @@ static void send_udp_message(struct addrinfo *servaddr, char *msg)
|
|||
|
||||
fd = socket(servaddr->ai_family, SOCK_DGRAM, 0);
|
||||
|
||||
if ( fd >= 0) {
|
||||
if (fd >= 0) {
|
||||
sendto(fd, msg, strlen(msg), 0, servaddr->ai_addr, servaddr->ai_addrlen);
|
||||
close(fd);
|
||||
}
|
||||
|
|
@ -283,7 +280,6 @@ static void send_udp_message(struct addrinfo *servaddr, char *msg)
|
|||
|
||||
void del_list_lw_notify(struct cwmp_dm_parameter *dm_parameter)
|
||||
{
|
||||
|
||||
list_del(&dm_parameter->list);
|
||||
free(dm_parameter->name);
|
||||
free(dm_parameter);
|
||||
|
|
@ -303,20 +299,14 @@ void cwmp_lwnotification()
|
|||
char *msg, *msg_out;
|
||||
char signature[41];
|
||||
struct addrinfo *servaddr;
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
struct config *conf;
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
struct config *conf;
|
||||
conf = &(cwmp->conf);
|
||||
|
||||
udplw_server_param(&servaddr);
|
||||
xml_prepare_lwnotification_message(&msg_out);
|
||||
message_compute_signature(msg_out, signature);
|
||||
asprintf(&msg, "%s \n %s: %s \n %s: %s \n %s: %d\n %s: %s\n\n%s",
|
||||
"POST /HTTPS/1.1",
|
||||
"HOST", conf->lw_notification_hostname,
|
||||
"Content-Type", "test/xml; charset=utf-8",
|
||||
"Content-Lenght", strlen(msg_out),
|
||||
"Signature",signature,
|
||||
msg_out);
|
||||
asprintf(&msg, "%s \n %s: %s \n %s: %s \n %s: %d\n %s: %s\n\n%s", "POST /HTTPS/1.1", "HOST", conf->lw_notification_hostname, "Content-Type", "test/xml; charset=utf-8", "Content-Lenght", strlen(msg_out), "Signature", signature, msg_out);
|
||||
|
||||
send_udp_message(servaddr, msg);
|
||||
free_all_list_lw_notify();
|
||||
|
|
|
|||
133
session.c
133
session.c
|
|
@ -16,99 +16,92 @@
|
|||
|
||||
unsigned int end_session_flag = 0;
|
||||
|
||||
void cwmp_set_end_session(unsigned int flag)
|
||||
void cwmp_set_end_session(unsigned int flag) { end_session_flag |= flag; }
|
||||
struct rpc *cwmp_add_session_rpc_cpe(struct session *session, int type)
|
||||
{
|
||||
end_session_flag |= flag;
|
||||
struct rpc *rpc_cpe;
|
||||
|
||||
rpc_cpe = calloc(1, sizeof(struct rpc));
|
||||
if (rpc_cpe == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
rpc_cpe->type = type;
|
||||
list_add_tail(&(rpc_cpe->list), &(session->head_rpc_cpe));
|
||||
return rpc_cpe;
|
||||
}
|
||||
|
||||
struct rpc *cwmp_add_session_rpc_cpe (struct session *session, int type)
|
||||
struct rpc *cwmp_add_session_rpc_acs(struct session *session, int type)
|
||||
{
|
||||
struct rpc *rpc_cpe;
|
||||
struct rpc *rpc_acs;
|
||||
|
||||
rpc_cpe = calloc (1,sizeof(struct rpc));
|
||||
if (rpc_cpe==NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
rpc_cpe->type = type;
|
||||
list_add_tail (&(rpc_cpe->list), &(session->head_rpc_cpe));
|
||||
return rpc_cpe;
|
||||
}
|
||||
|
||||
struct rpc *cwmp_add_session_rpc_acs (struct session *session, int type)
|
||||
{
|
||||
struct rpc *rpc_acs;
|
||||
|
||||
rpc_acs = calloc (1,sizeof(struct rpc));
|
||||
if (rpc_acs==NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
rpc_acs->type = type;
|
||||
list_add_tail (&(rpc_acs->list), &(session->head_rpc_acs));
|
||||
return rpc_acs;
|
||||
rpc_acs = calloc(1, sizeof(struct rpc));
|
||||
if (rpc_acs == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
rpc_acs->type = type;
|
||||
list_add_tail(&(rpc_acs->list), &(session->head_rpc_acs));
|
||||
return rpc_acs;
|
||||
}
|
||||
|
||||
int cwmp_apply_acs_changes(void)
|
||||
{
|
||||
int error;
|
||||
int error;
|
||||
|
||||
if ((error = cwmp_config_reload(&cwmp_main)))
|
||||
return error;
|
||||
if ((error = cwmp_config_reload(&cwmp_main)))
|
||||
return error;
|
||||
|
||||
if ((error = cwmp_root_cause_events(&cwmp_main)))
|
||||
return error;
|
||||
if ((error = cwmp_root_cause_events(&cwmp_main)))
|
||||
return error;
|
||||
|
||||
return CWMP_OK;
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int cwmp_move_session_to_session_send (struct cwmp *cwmp, struct session *session)
|
||||
int cwmp_move_session_to_session_send(struct cwmp *cwmp, struct session *session)
|
||||
{
|
||||
pthread_mutex_lock (&(cwmp->mutex_session_queue));
|
||||
if (cwmp->session_send != NULL) {
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_MUTEX_ERR;
|
||||
}
|
||||
list_del (&(session->list));
|
||||
cwmp->session_send = session;
|
||||
cwmp->head_event_container = NULL;
|
||||
bkp_session_move_inform_to_inform_send ();
|
||||
bkp_session_save();
|
||||
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
|
||||
return CWMP_OK;
|
||||
pthread_mutex_lock(&(cwmp->mutex_session_queue));
|
||||
if (cwmp->session_send != NULL) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_MUTEX_ERR;
|
||||
}
|
||||
list_del(&(session->list));
|
||||
cwmp->session_send = session;
|
||||
cwmp->head_event_container = NULL;
|
||||
bkp_session_move_inform_to_inform_send();
|
||||
bkp_session_save();
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
struct rpc *cwmp_add_session_rpc_acs_head (struct session *session, int type)
|
||||
struct rpc *cwmp_add_session_rpc_acs_head(struct session *session, int type)
|
||||
{
|
||||
struct rpc *rpc_acs;
|
||||
struct rpc *rpc_acs;
|
||||
|
||||
rpc_acs = calloc (1,sizeof(struct rpc));
|
||||
if (rpc_acs==NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
rpc_acs->type = type;
|
||||
list_add (&(rpc_acs->list), &(session->head_rpc_acs));
|
||||
return rpc_acs;
|
||||
rpc_acs = calloc(1, sizeof(struct rpc));
|
||||
if (rpc_acs == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
rpc_acs->type = type;
|
||||
list_add(&(rpc_acs->list), &(session->head_rpc_acs));
|
||||
return rpc_acs;
|
||||
}
|
||||
|
||||
struct session *cwmp_add_queue_session (struct cwmp *cwmp)
|
||||
struct session *cwmp_add_queue_session(struct cwmp *cwmp)
|
||||
{
|
||||
struct session *session = NULL;
|
||||
struct rpc *rpc_acs;
|
||||
struct session *session = NULL;
|
||||
struct rpc *rpc_acs;
|
||||
|
||||
session = calloc(1, sizeof(struct session));
|
||||
if (session == NULL)
|
||||
return NULL;
|
||||
session = calloc(1, sizeof(struct session));
|
||||
if (session == NULL)
|
||||
return NULL;
|
||||
|
||||
list_add_tail (&(session->list), &(cwmp->head_session_queue));
|
||||
INIT_LIST_HEAD (&(session->head_event_container));
|
||||
INIT_LIST_HEAD (&(session->head_rpc_acs));
|
||||
INIT_LIST_HEAD (&(session->head_rpc_cpe));
|
||||
if ((rpc_acs = cwmp_add_session_rpc_acs_head(session, RPC_ACS_INFORM)) == NULL) {
|
||||
FREE(session);
|
||||
return NULL;
|
||||
}
|
||||
list_add_tail(&(session->list), &(cwmp->head_session_queue));
|
||||
INIT_LIST_HEAD(&(session->head_event_container));
|
||||
INIT_LIST_HEAD(&(session->head_rpc_acs));
|
||||
INIT_LIST_HEAD(&(session->head_rpc_cpe));
|
||||
if ((rpc_acs = cwmp_add_session_rpc_acs_head(session, RPC_ACS_INFORM)) == NULL) {
|
||||
FREE(session);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return session;
|
||||
return session;
|
||||
}
|
||||
|
|
|
|||
253
ubus.c
253
ubus.c
|
|
@ -32,39 +32,32 @@ static struct blob_buf b;
|
|||
static json_object *json_res = NULL;
|
||||
|
||||
static const char *arr_session_status[] = {
|
||||
[SESSION_WAITING] = "waiting",
|
||||
[SESSION_RUNNING] = "running",
|
||||
[SESSION_FAILURE] = "failure",
|
||||
[SESSION_SUCCESS] = "success",
|
||||
[SESSION_WAITING] = "waiting", [SESSION_RUNNING] = "running", [SESSION_FAILURE] = "failure", [SESSION_SUCCESS] = "success",
|
||||
};
|
||||
|
||||
|
||||
enum command {
|
||||
enum command
|
||||
{
|
||||
COMMAND_NAME,
|
||||
__COMMAND_MAX
|
||||
};
|
||||
|
||||
static const struct blobmsg_policy command_policy[] = {
|
||||
[COMMAND_NAME] = { .name = "command", .type = BLOBMSG_TYPE_STRING },
|
||||
[COMMAND_NAME] = {.name = "command", .type = BLOBMSG_TYPE_STRING },
|
||||
};
|
||||
|
||||
void *thread_exit_program (void *v __attribute__((unused)))
|
||||
void *thread_exit_program(void *v __attribute__((unused)))
|
||||
{
|
||||
CWMP_LOG(INFO,"EXIT ICWMP");
|
||||
CWMP_LOG(INFO, "EXIT ICWMP");
|
||||
pthread_mutex_lock(&mutex_backup_session);
|
||||
cwmp_exit();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static int
|
||||
cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)),
|
||||
struct ubus_request_data *req, const char *method __attribute__((unused)),
|
||||
struct blob_attr *msg)
|
||||
static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)), struct ubus_request_data *req, const char *method __attribute__((unused)), struct blob_attr *msg)
|
||||
{
|
||||
struct blob_attr *tb[__COMMAND_MAX];
|
||||
|
||||
blobmsg_parse(command_policy, ARRAYSIZEOF(command_policy), tb,
|
||||
blob_data(msg), blob_len(msg));
|
||||
blobmsg_parse(command_policy, ARRAYSIZEOF(command_policy), tb, blob_data(msg), blob_len(msg));
|
||||
|
||||
if (!tb[COMMAND_NAME])
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
|
|
@ -86,11 +79,10 @@ cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj __attribut
|
|||
cwmp_set_end_session(END_SESSION_RELOAD);
|
||||
blobmsg_add_u32(&b, "status", 0);
|
||||
blobmsg_add_string(&b, "info", "Session running, reload at the end of the session");
|
||||
}
|
||||
else {
|
||||
pthread_mutex_lock (&(cwmp_main.mutex_session_queue));
|
||||
} else {
|
||||
pthread_mutex_lock(&(cwmp_main.mutex_session_queue));
|
||||
cwmp_apply_acs_changes();
|
||||
pthread_mutex_unlock (&(cwmp_main.mutex_session_queue));
|
||||
pthread_mutex_unlock(&(cwmp_main.mutex_session_queue));
|
||||
blobmsg_add_u32(&b, "status", 0);
|
||||
if (asprintf(&info, "icwmpd config reloaded") == -1)
|
||||
return -1;
|
||||
|
|
@ -113,7 +105,7 @@ cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj __attribut
|
|||
CWMP_LOG(INFO, "triggered ubus exit");
|
||||
int rc = flock(cwmp_main.pid_file, LOCK_UN | LOCK_NB);
|
||||
close(cwmp_main.pid_file);
|
||||
if(rc) {
|
||||
if (rc) {
|
||||
char *piderr = "PID file unlock failed!";
|
||||
fprintf(stderr, "%s\n", piderr);
|
||||
CWMP_LOG(ERROR, "%s", piderr);
|
||||
|
|
@ -128,11 +120,10 @@ cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj __attribut
|
|||
|
||||
blob_buf_free(&b);
|
||||
close(cwmp_main.cr_socket_desc);
|
||||
CWMP_LOG(INFO,"Close connection request server socket");
|
||||
CWMP_LOG(INFO, "Close connection request server socket");
|
||||
error = pthread_create(&exit_thread, NULL, &thread_exit_program, NULL);
|
||||
if (error<0)
|
||||
{
|
||||
CWMP_LOG(ERROR,"Error when creating the exit thread!");
|
||||
if (error < 0) {
|
||||
CWMP_LOG(ERROR, "Error when creating the exit thread!");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -153,90 +144,83 @@ cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj __attribut
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline time_t get_session_status_next_time() {
|
||||
time_t ntime = 0;
|
||||
if(list_schedule_inform.next!=&(list_schedule_inform)) {
|
||||
struct schedule_inform *schedule_inform;
|
||||
schedule_inform = list_entry(list_schedule_inform.next,struct schedule_inform, list);
|
||||
ntime = schedule_inform->scheduled_time;
|
||||
}
|
||||
if (!ntime || (cwmp_main.session_status.next_retry && ntime > cwmp_main.session_status.next_retry)) {
|
||||
ntime = cwmp_main.session_status.next_retry;
|
||||
}
|
||||
if (!ntime || (cwmp_main.session_status.next_periodic && ntime > cwmp_main.session_status.next_periodic)) {
|
||||
ntime = cwmp_main.session_status.next_periodic;
|
||||
}
|
||||
return ntime;
|
||||
}
|
||||
|
||||
static int
|
||||
cwmp_handle_status(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)),
|
||||
struct ubus_request_data *req, const char *method __attribute__((unused)),
|
||||
struct blob_attr *msg __attribute__((unused)))
|
||||
static inline time_t get_session_status_next_time()
|
||||
{
|
||||
void *c;
|
||||
time_t ntime = 0;
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
|
||||
c = blobmsg_open_table(&b, "cwmp");
|
||||
blobmsg_add_string(&b, "status", "up");
|
||||
blobmsg_add_string(&b, "start_time", mix_get_time_of(cwmp_main.start_time));
|
||||
blobmsg_add_string(&b, "acs_url", cwmp_main.conf.acsurl);
|
||||
blobmsg_close_table(&b, c);
|
||||
|
||||
c = blobmsg_open_table(&b, "last_session");
|
||||
blobmsg_add_string(&b, "status", cwmp_main.session_status.last_start_time ? arr_session_status[cwmp_main.session_status.last_status] : "N/A");
|
||||
blobmsg_add_string(&b, "start_time", cwmp_main.session_status.last_start_time ? mix_get_time_of(cwmp_main.session_status.last_start_time) : "N/A");
|
||||
blobmsg_add_string(&b, "end_time", cwmp_main.session_status.last_end_time ? mix_get_time_of(cwmp_main.session_status.last_end_time) : "N/A");
|
||||
blobmsg_close_table(&b, c);
|
||||
|
||||
c = blobmsg_open_table(&b, "next_session");
|
||||
blobmsg_add_string(&b, "status", arr_session_status[SESSION_WAITING]);
|
||||
ntime = get_session_status_next_time();
|
||||
blobmsg_add_string(&b, "start_time", ntime ? mix_get_time_of(ntime) : "N/A");
|
||||
blobmsg_add_string(&b, "end_time", "N/A");
|
||||
blobmsg_close_table(&b, c);
|
||||
|
||||
c = blobmsg_open_table(&b, "statistics");
|
||||
blobmsg_add_u32(&b, "success_sessions", cwmp_main.session_status.success_session);
|
||||
blobmsg_add_u32(&b, "failure_sessions", cwmp_main.session_status.failure_session);
|
||||
blobmsg_add_u32(&b, "total_sessions", cwmp_main.session_status.success_session + cwmp_main.session_status.failure_session);
|
||||
blobmsg_close_table(&b, c);
|
||||
|
||||
|
||||
ubus_send_reply(ctx, req, b.head);
|
||||
blob_buf_free(&b);
|
||||
|
||||
return 0;
|
||||
time_t ntime = 0;
|
||||
if (list_schedule_inform.next != &(list_schedule_inform)) {
|
||||
struct schedule_inform *schedule_inform;
|
||||
schedule_inform = list_entry(list_schedule_inform.next, struct schedule_inform, list);
|
||||
ntime = schedule_inform->scheduled_time;
|
||||
}
|
||||
if (!ntime || (cwmp_main.session_status.next_retry && ntime > cwmp_main.session_status.next_retry)) {
|
||||
ntime = cwmp_main.session_status.next_retry;
|
||||
}
|
||||
if (!ntime || (cwmp_main.session_status.next_periodic && ntime > cwmp_main.session_status.next_periodic)) {
|
||||
ntime = cwmp_main.session_status.next_periodic;
|
||||
}
|
||||
return ntime;
|
||||
}
|
||||
|
||||
enum enum_inform {
|
||||
static int cwmp_handle_status(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)), struct ubus_request_data *req, const char *method __attribute__((unused)), struct blob_attr *msg __attribute__((unused)))
|
||||
{
|
||||
void *c;
|
||||
time_t ntime = 0;
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
|
||||
c = blobmsg_open_table(&b, "cwmp");
|
||||
blobmsg_add_string(&b, "status", "up");
|
||||
blobmsg_add_string(&b, "start_time", mix_get_time_of(cwmp_main.start_time));
|
||||
blobmsg_add_string(&b, "acs_url", cwmp_main.conf.acsurl);
|
||||
blobmsg_close_table(&b, c);
|
||||
|
||||
c = blobmsg_open_table(&b, "last_session");
|
||||
blobmsg_add_string(&b, "status", cwmp_main.session_status.last_start_time ? arr_session_status[cwmp_main.session_status.last_status] : "N/A");
|
||||
blobmsg_add_string(&b, "start_time", cwmp_main.session_status.last_start_time ? mix_get_time_of(cwmp_main.session_status.last_start_time) : "N/A");
|
||||
blobmsg_add_string(&b, "end_time", cwmp_main.session_status.last_end_time ? mix_get_time_of(cwmp_main.session_status.last_end_time) : "N/A");
|
||||
blobmsg_close_table(&b, c);
|
||||
|
||||
c = blobmsg_open_table(&b, "next_session");
|
||||
blobmsg_add_string(&b, "status", arr_session_status[SESSION_WAITING]);
|
||||
ntime = get_session_status_next_time();
|
||||
blobmsg_add_string(&b, "start_time", ntime ? mix_get_time_of(ntime) : "N/A");
|
||||
blobmsg_add_string(&b, "end_time", "N/A");
|
||||
blobmsg_close_table(&b, c);
|
||||
|
||||
c = blobmsg_open_table(&b, "statistics");
|
||||
blobmsg_add_u32(&b, "success_sessions", cwmp_main.session_status.success_session);
|
||||
blobmsg_add_u32(&b, "failure_sessions", cwmp_main.session_status.failure_session);
|
||||
blobmsg_add_u32(&b, "total_sessions", cwmp_main.session_status.success_session + cwmp_main.session_status.failure_session);
|
||||
blobmsg_close_table(&b, c);
|
||||
|
||||
ubus_send_reply(ctx, req, b.head);
|
||||
blob_buf_free(&b);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum enum_inform
|
||||
{
|
||||
INFORM_GET_RPC_METHODS,
|
||||
INFORM_EVENT,
|
||||
__INFORM_MAX
|
||||
};
|
||||
|
||||
static const struct blobmsg_policy inform_policy[] = {
|
||||
[INFORM_GET_RPC_METHODS] = { .name = "GetRPCMethods", .type = BLOBMSG_TYPE_BOOL },
|
||||
[INFORM_EVENT] = { .name = "event", .type = BLOBMSG_TYPE_STRING },
|
||||
[INFORM_GET_RPC_METHODS] = {.name = "GetRPCMethods", .type = BLOBMSG_TYPE_BOOL }, [INFORM_EVENT] = {.name = "event", .type = BLOBMSG_TYPE_STRING },
|
||||
};
|
||||
|
||||
static int
|
||||
cwmp_handle_inform(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)),
|
||||
struct ubus_request_data *req, const char *method __attribute__((unused)),
|
||||
struct blob_attr *msg)
|
||||
static int cwmp_handle_inform(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)), struct ubus_request_data *req, const char *method __attribute__((unused)), struct blob_attr *msg)
|
||||
{
|
||||
struct blob_attr *tb[__INFORM_MAX];
|
||||
bool grm = false;
|
||||
char *event = "";
|
||||
struct event_container *event_container;
|
||||
struct session *session;
|
||||
struct blob_attr *tb[__INFORM_MAX];
|
||||
bool grm = false;
|
||||
char *event = "";
|
||||
struct event_container *event_container;
|
||||
struct session *session;
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
blob_buf_init(&b, 0);
|
||||
|
||||
blobmsg_parse(inform_policy, ARRAYSIZEOF(inform_policy), tb,
|
||||
blob_data(msg), blob_len(msg));
|
||||
blobmsg_parse(inform_policy, ARRAYSIZEOF(inform_policy), tb, blob_data(msg), blob_len(msg));
|
||||
|
||||
if (tb[INFORM_GET_RPC_METHODS]) {
|
||||
grm = blobmsg_data(tb[INFORM_GET_RPC_METHODS]);
|
||||
|
|
@ -245,55 +229,47 @@ cwmp_handle_inform(struct ubus_context *ctx, struct ubus_object *obj __attribute
|
|||
event = blobmsg_data(tb[INFORM_EVENT]);
|
||||
}
|
||||
if (grm) {
|
||||
pthread_mutex_lock (&(cwmp_main.mutex_session_queue));
|
||||
event_container = cwmp_add_event_container (&cwmp_main, EVENT_IDX_2PERIODIC, "");
|
||||
if (event_container == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp_main.mutex_session_queue));
|
||||
pthread_mutex_lock(&(cwmp_main.mutex_session_queue));
|
||||
event_container = cwmp_add_event_container(&cwmp_main, EVENT_IDX_2PERIODIC, "");
|
||||
if (event_container == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp_main.mutex_session_queue));
|
||||
return 0;
|
||||
}
|
||||
cwmp_save_event_container (event_container);
|
||||
session = list_entry (cwmp_main.head_event_container, struct session,head_event_container);
|
||||
if(cwmp_add_session_rpc_acs(session, RPC_ACS_GET_RPC_METHODS) == NULL)
|
||||
{
|
||||
pthread_mutex_unlock (&(cwmp_main.mutex_session_queue));
|
||||
cwmp_save_event_container(event_container);
|
||||
session = list_entry(cwmp_main.head_event_container, struct session, head_event_container);
|
||||
if (cwmp_add_session_rpc_acs(session, RPC_ACS_GET_RPC_METHODS) == NULL) {
|
||||
pthread_mutex_unlock(&(cwmp_main.mutex_session_queue));
|
||||
return 0;
|
||||
}
|
||||
pthread_mutex_unlock (&(cwmp_main.mutex_session_queue));
|
||||
pthread_mutex_unlock(&(cwmp_main.mutex_session_queue));
|
||||
pthread_cond_signal(&(cwmp_main.threshold_session_send));
|
||||
blobmsg_add_u32(&b, "status", 1);
|
||||
blobmsg_add_string(&b, "info", "Session with GetRPCMethods will start");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
int event_code = cwmp_get_int_event_code(event);
|
||||
pthread_mutex_lock (&(cwmp_main.mutex_session_queue));
|
||||
cwmp_add_event_container (&cwmp_main, event_code, "");
|
||||
pthread_mutex_unlock (&(cwmp_main.mutex_session_queue));
|
||||
pthread_mutex_lock(&(cwmp_main.mutex_session_queue));
|
||||
cwmp_add_event_container(&cwmp_main, event_code, "");
|
||||
pthread_mutex_unlock(&(cwmp_main.mutex_session_queue));
|
||||
pthread_cond_signal(&(cwmp_main.threshold_session_send));
|
||||
if (cwmp_main.session_status.last_status == SESSION_RUNNING) {
|
||||
blobmsg_add_u32(&b, "status", -1);
|
||||
blobmsg_add_string(&b, "info", "Session already running, event will be sent at the end of the session");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
blobmsg_add_u32(&b, "status", 1);
|
||||
blobmsg_add_string(&b, "info", "Session started");
|
||||
}
|
||||
}
|
||||
ubus_send_reply(ctx, req, b.head);
|
||||
blob_buf_free(&b);
|
||||
ubus_send_reply(ctx, req, b.head);
|
||||
blob_buf_free(&b);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct ubus_method freecwmp_methods[] = {
|
||||
UBUS_METHOD("command", cwmp_handle_command, command_policy),
|
||||
UBUS_METHOD_NOARG("status", cwmp_handle_status),
|
||||
UBUS_METHOD("inform", cwmp_handle_inform, inform_policy),
|
||||
UBUS_METHOD("command", cwmp_handle_command, command_policy), UBUS_METHOD_NOARG("status", cwmp_handle_status), UBUS_METHOD("inform", cwmp_handle_inform, inform_policy),
|
||||
};
|
||||
|
||||
static struct ubus_object_type main_object_type =
|
||||
UBUS_OBJECT_TYPE("freecwmpd", freecwmp_methods);
|
||||
static struct ubus_object_type main_object_type = UBUS_OBJECT_TYPE("freecwmpd", freecwmp_methods);
|
||||
|
||||
static struct ubus_object main_object = {
|
||||
.name = "tr069",
|
||||
|
|
@ -302,32 +278,32 @@ static struct ubus_object main_object = {
|
|||
.n_methods = ARRAYSIZEOF(freecwmp_methods),
|
||||
};
|
||||
|
||||
int
|
||||
ubus_init(struct cwmp *cwmp)
|
||||
int ubus_init(struct cwmp *cwmp)
|
||||
{
|
||||
uloop_init();
|
||||
|
||||
if (netlink_init()) {
|
||||
CWMP_LOG(ERROR,"netlink initialization failed");
|
||||
CWMP_LOG(ERROR, "netlink initialization failed");
|
||||
}
|
||||
|
||||
if (cwmp->conf.ipv6_enable) {
|
||||
if (netlink_init_v6()) {
|
||||
CWMP_LOG(ERROR,"netlink initialization failed");
|
||||
if (netlink_init_v6()) {
|
||||
CWMP_LOG(ERROR, "netlink initialization failed");
|
||||
}
|
||||
}
|
||||
ctx = ubus_connect(cwmp->conf.ubus_socket);
|
||||
if (!ctx) return -1;
|
||||
if (!ctx)
|
||||
return -1;
|
||||
|
||||
ubus_add_uloop(ctx);
|
||||
|
||||
if (ubus_add_object(ctx, &main_object)) return -1;
|
||||
uloop_run();
|
||||
if (ubus_add_object(ctx, &main_object))
|
||||
return -1;
|
||||
uloop_run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
ubus_exit(void)
|
||||
void ubus_exit(void)
|
||||
{
|
||||
if (ctx)
|
||||
ubus_free(ctx);
|
||||
|
|
@ -354,7 +330,7 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a
|
|||
int i = 0;
|
||||
int rc = 0;
|
||||
struct ubus_context *ubus_ctx = NULL;
|
||||
struct blob_buf b = {0};
|
||||
struct blob_buf b = { 0 };
|
||||
|
||||
json_res = NULL;
|
||||
|
||||
|
|
@ -369,8 +345,7 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a
|
|||
blobmsg_add_string(&b, u_args[i].key, u_args[i].val.str_val);
|
||||
else if (u_args[i].type == UBUS_Integer) {
|
||||
blobmsg_add_u32(&b, u_args[i].key, u_args[i].val.int_val);
|
||||
}
|
||||
else if (u_args[i].type == UBUS_Array_Obj || u_args[i].type == UBUS_Array_Str){
|
||||
} else if (u_args[i].type == UBUS_Array_Obj || u_args[i].type == UBUS_Array_Str) {
|
||||
void *a, *t;
|
||||
int j;
|
||||
a = blobmsg_open_array(&b, u_args[i].key);
|
||||
|
|
@ -395,8 +370,8 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a
|
|||
struct cwmp_param_value *param_value;
|
||||
void *a, *t;
|
||||
a = blobmsg_open_array(&b, u_args[i].key);
|
||||
list_for_each_entry(param_value, u_args[i].val.param_value_list, list) {
|
||||
if(!param_value->param)
|
||||
list_for_each_entry (param_value, u_args[i].val.param_value_list, list) {
|
||||
if (!param_value->param)
|
||||
break;
|
||||
t = blobmsg_open_table(&b, "");
|
||||
blobmsg_add_string(&b, "path", param_value->param);
|
||||
|
|
@ -407,8 +382,8 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a
|
|||
} else if (u_args[i].type == UBUS_Obj_Obj) {
|
||||
struct cwmp_param_value *param_value;
|
||||
json_object *input_json_obj = json_object_new_object();
|
||||
list_for_each_entry(param_value, u_args[i].val.param_value_list, list) {
|
||||
if(!param_value->param)
|
||||
list_for_each_entry (param_value, u_args[i].val.param_value_list, list) {
|
||||
if (!param_value->param)
|
||||
break;
|
||||
json_object_object_add(input_json_obj, param_value->param, json_object_new_string(param_value->value));
|
||||
}
|
||||
|
|
@ -422,7 +397,7 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a
|
|||
else
|
||||
rc = -1;
|
||||
|
||||
*json_ret = json_res;
|
||||
*json_ret = json_res;
|
||||
|
||||
if (ubus_ctx) {
|
||||
ubus_free(ubus_ctx);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue