From 46af03bd690cc85b037f219b60ee8453c6940eb9 Mon Sep 17 00:00:00 2001 From: Skylar Chang Date: Thu, 12 Sep 2019 13:34:10 -0700 Subject: ipacm: support dynamic switch sw/hw-path on APQ platform Change-Id: I7f920df8b3a3df42ce66502ad2c1abfb0d89e80e --- ipacm/inc/IPACM_Iface.h | 4 +- ipacm/src/IPACM_Iface.cpp | 212 +++++++++++++++++++++++++++++----------------- ipacm/src/IPACM_Lan.cpp | 8 +- ipacm/src/IPACM_Wan.cpp | 41 +++++++-- ipacm/src/IPACM_Wlan.cpp | 8 +- 5 files changed, 178 insertions(+), 95 deletions(-) diff --git a/ipacm/inc/IPACM_Iface.h b/ipacm/inc/IPACM_Iface.h index df192c9..55d9e99 100644 --- a/ipacm/inc/IPACM_Iface.h +++ b/ipacm/inc/IPACM_Iface.h @@ -142,10 +142,10 @@ public: void change_to_network_order(ipa_ip_type iptype, ipa_rule_attrib* attrib); /* software routing enable */ - virtual int handle_software_routing_enable(void); + virtual int handle_software_routing_enable(bool mhip); /* software routing disable */ - virtual int handle_software_routing_disable(void); + virtual int handle_software_routing_disable(bool mhip); void delete_iface(void); bool is_global_ipv6_addr(uint32_t* ipv6_addr); diff --git a/ipacm/src/IPACM_Iface.cpp b/ipacm/src/IPACM_Iface.cpp index 05dd6ca..ec4a9ea 100644 --- a/ipacm/src/IPACM_Iface.cpp +++ b/ipacm/src/IPACM_Iface.cpp @@ -88,12 +88,14 @@ IPACM_Iface::IPACM_Iface(int iface_index) } /* software routing enable */ -int IPACM_Iface::handle_software_routing_enable(void) +int IPACM_Iface::handle_software_routing_enable(bool mhip) { - + int fd =0; int res = IPACM_SUCCESS; struct ipa_flt_rule_add flt_rule_entry; ipa_ioc_add_flt_rule *m_pFilteringTable; + /* contruct filter rules to pcie modem */ + ipa_ioc_generate_flt_eq flt_eq; IPACMDBG("\n"); if (softwarerouting_act == true) @@ -121,11 +123,9 @@ int IPACM_Iface::handle_software_routing_enable(void) } m_pFilteringTable->commit = 1; - m_pFilteringTable->ep = rx_prop->rx[0].src_pipe; m_pFilteringTable->global = false; m_pFilteringTable->num_rules = (uint8_t)1; - /* Configuring Software-Routing Filtering Rule */ memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add)); @@ -139,20 +139,52 @@ int IPACM_Iface::handle_software_routing_enable(void) memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); - /* disble meta-data filtering skylar */ - if (IPACM_Wan::backhaul_mode == Q6_MHI_WAN) - { - flt_rule_entry.rule.attrib.attrib_mask &= ~((uint32_t)IPA_FLT_META_DATA); - IPACMDBG_H("disable meta-data filtering 0x%x\n", flt_rule_entry.rule.attrib.attrib_mask); - } memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); /* check iface is v4 or v6 or both*/ -// if (ip_type == IPA_IP_MAX) -// { + /* handle v4 */ m_pFilteringTable->ip = IPA_IP_v4; + + fd = open(IPA_DEVICE_NAME, O_RDWR); + if (fd < 0) + { + IPACMERR("Failed opening %s.\n", IPA_DEVICE_NAME); + free(m_pFilteringTable); + return IPACM_FAILURE; + } + + if (mhip) + { + /* generate eq */ + memset(&flt_eq, 0, sizeof(flt_eq)); + memcpy(&flt_eq.attrib, &flt_rule_entry.rule.attrib, sizeof(flt_eq.attrib)); + flt_eq.ip = IPA_IP_v4; + + + if(0 != ioctl(fd, IPA_IOC_GENERATE_FLT_EQ, &flt_eq)) //define and cpy attribute to this struct + { + IPACMERR("Failed to get eq_attrib\n"); + res = IPACM_FAILURE; + goto fail; + } + memcpy(&flt_rule_entry.rule.eq_attrib, + &flt_eq.eq_attrib, + sizeof(flt_rule_entry.rule.eq_attrib)); + memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); + + /* add rule */ + if(false == m_filtering.AddOffloadFilteringRule(m_pFilteringTable, IPACM_Iface::ipacmcfg->GetQmapId(), 1)) + { + IPACMERR("Failed to install WAN DL filtering table.\n"); + res = IPACM_FAILURE; + goto fail; + } + } + else + { + m_pFilteringTable->ep = rx_prop->rx[0].src_pipe; if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) { IPACMERR("Error Adding Filtering rule, aborting...\n"); @@ -165,46 +197,44 @@ int IPACM_Iface::handle_software_routing_enable(void) res = IPACM_FAILURE; goto fail; } - IPACM_Iface::ipacmcfg->increaseFltRuleCount(rx_prop->rx[0].src_pipe, IPA_IP_v4, 1); - IPACMDBG("soft-routing flt rule hdl0=0x%x\n", m_pFilteringTable->rules[0].flt_rule_hdl); + } + + IPACMDBG("soft-routing ipv4 flt rule hdl0=0x%x\n", m_pFilteringTable->rules[0].flt_rule_hdl); /* copy filter hdls */ software_routing_fl_rule_hdl[0] = m_pFilteringTable->rules[0].flt_rule_hdl; - /* handle v6*/ m_pFilteringTable->ip = IPA_IP_v6; - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) + if (mhip) + { + /* generate eq */ + memset(&flt_eq, 0, sizeof(flt_eq)); + memcpy(&flt_eq.attrib, &flt_rule_entry.rule.attrib, sizeof(flt_eq.attrib)); + flt_eq.ip = IPA_IP_v6; + + if(0 != ioctl(fd, IPA_IOC_GENERATE_FLT_EQ, &flt_eq)) //define and cpy attribute to this struct { - IPACMERR("Error Adding Filtering rule, aborting...\n"); + IPACMERR("Failed to get eq_attrib\n"); res = IPACM_FAILURE; goto fail; } - else if (m_pFilteringTable->rules[0].status) + memcpy(&flt_rule_entry.rule.eq_attrib, + &flt_eq.eq_attrib, + sizeof(flt_rule_entry.rule.eq_attrib)); + memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); + + /* add rule */ + if(false == m_filtering.AddOffloadFilteringRule(m_pFilteringTable, IPACM_Iface::ipacmcfg->GetQmapId(), 1)) { - IPACMDBG("adding flt rule failed status=0x%x\n", m_pFilteringTable->rules[0].status); + IPACMERR("Failed to install WAN DL filtering table.\n"); res = IPACM_FAILURE; goto fail; } - - IPACM_Iface::ipacmcfg->increaseFltRuleCount(rx_prop->rx[0].src_pipe, IPA_IP_v6, 1); - IPACMDBG("soft-routing flt rule hdl0=0x%x\n", m_pFilteringTable->rules[0].flt_rule_hdl); - /* copy filter hdls */ - software_routing_fl_rule_hdl[1] = m_pFilteringTable->rules[0].flt_rule_hdl; - softwarerouting_act = true; -#if 0 } else { - if (ip_type == IPA_IP_v4) - { - m_pFilteringTable->ip = IPA_IP_v4; - } - else - { - m_pFilteringTable->ip = IPA_IP_v6; - } - + m_pFilteringTable->ep = rx_prop->rx[0].src_pipe; if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) { IPACMERR("Error Adding Filtering rule, aborting...\n"); @@ -217,32 +247,29 @@ int IPACM_Iface::handle_software_routing_enable(void) res = IPACM_FAILURE; goto fail; } + IPACM_Iface::ipacmcfg->increaseFltRuleCount(rx_prop->rx[0].src_pipe, IPA_IP_v6, 1); + } - IPACM_Iface::ipacmcfg->increaseFltRuleCount(rx_prop->rx[0].src_pipe, ip_type, 1); - IPACMDBG("soft-routing flt rule hdl0=0x%x\n", m_pFilteringTable->rules[0].flt_rule_hdl); + IPACMDBG("soft-routing ipv6 flt rule hdl0=0x%x\n", m_pFilteringTable->rules[0].flt_rule_hdl); /* copy filter hdls */ - if (ip_type == IPA_IP_v4) - { - software_routing_fl_rule_hdl[0] = m_pFilteringTable->rules[0].flt_rule_hdl; - } - else - { software_routing_fl_rule_hdl[1] = m_pFilteringTable->rules[0].flt_rule_hdl; - } softwarerouting_act = true; - } -#endif fail: + close(fd); + if(m_pFilteringTable != NULL) + { free(m_pFilteringTable); - + } return res; } /* software routing disable */ -int IPACM_Iface::handle_software_routing_disable(void) +int IPACM_Iface::handle_software_routing_disable(bool mhip) { - int res = IPACM_SUCCESS; + int len, res = IPACM_SUCCESS; + ipa_ioc_del_flt_rule *pFilteringTable = NULL; + struct ipa_flt_rule_del flt_rule_entry; if (rx_prop == NULL) { @@ -256,63 +283,96 @@ int IPACM_Iface::handle_software_routing_disable(void) return IPACM_SUCCESS; } -// if (ip_type == IPA_IP_MAX) -// { - /* ipv4 case */ - if (m_filtering.DeleteFilteringHdls(&software_routing_fl_rule_hdl[0], - IPA_IP_v4, 1) == false) + if(mhip) + { + len = sizeof(struct ipa_ioc_del_flt_rule) + sizeof(struct ipa_flt_rule_del); + pFilteringTable = (struct ipa_ioc_del_flt_rule*)malloc(len); + if (pFilteringTable == NULL) { - IPACMERR("Error Adding Filtering rule, aborting...\n"); + IPACMERR("Error Locate ipa_ioc_del_flt_rule memory...\n"); + return IPACM_FAILURE; + } + memset(pFilteringTable, 0, len); + + pFilteringTable->commit = 1; + pFilteringTable->ip = IPA_IP_v4; + pFilteringTable->num_hdls = (uint8_t)1; + + if (software_routing_fl_rule_hdl[0] == 0) + { + IPACMERR("invalid ipv4_exception_hdl.\n"); res = IPACM_FAILURE; goto fail; } - IPACM_Iface::ipacmcfg->decreaseFltRuleCount(rx_prop->rx[0].src_pipe, IPA_IP_v4, 1); - /* ipv6 case */ - if (m_filtering.DeleteFilteringHdls(&software_routing_fl_rule_hdl[1], - IPA_IP_v6, 1) == false) + memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_del)); + flt_rule_entry.hdl = software_routing_fl_rule_hdl[0]; + + memcpy(&(pFilteringTable->hdl[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_del)); + + if(false == m_filtering.DelOffloadFilteringRule(pFilteringTable)) { - IPACMERR("Error Adding Filtering rule, aborting...\n"); + IPACMERR("Failed to delete MHI ipv4 exception rule.\n"); res = IPACM_FAILURE; goto fail; } - IPACM_Iface::ipacmcfg->decreaseFltRuleCount(rx_prop->rx[0].src_pipe, IPA_IP_v6, 1); - softwarerouting_act = false; -#if 0 + software_routing_fl_rule_hdl[0] = 0; } else { - if (ip_type == IPA_IP_v4) + /* ipv4 case */ + if (m_filtering.DeleteFilteringHdls(&software_routing_fl_rule_hdl[0], + IPA_IP_v4, 1) == false) { - ip = IPA_IP_v4; + IPACMERR("Error Adding Filtering rule, aborting...\n"); + res = IPACM_FAILURE; + goto fail; } - else + } + IPACM_Iface::ipacmcfg->decreaseFltRuleCount(rx_prop->rx[0].src_pipe, IPA_IP_v4, 1); + + if(mhip) + { + pFilteringTable->ip = IPA_IP_v6; + if (software_routing_fl_rule_hdl[1] == 0) { - ip = IPA_IP_v6; + IPACMERR("invalid ipv6_exception_hdl.\n"); + res = IPACM_FAILURE; + goto fail; } + memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_del)); + flt_rule_entry.hdl = software_routing_fl_rule_hdl[1]; - if (ip_type == IPA_IP_v4) + memcpy(&(pFilteringTable->hdl[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_del)); + + if(false == m_filtering.DelOffloadFilteringRule(pFilteringTable)) { - flt_hdl = software_routing_fl_rule_hdl[0]; + IPACMERR("Failed to delete MHI ipv6 exception rule.\n"); + res = IPACM_FAILURE; + goto fail; + } + software_routing_fl_rule_hdl[1] = 0; } else { - flt_hdl = software_routing_fl_rule_hdl[1]; - } - - if (m_filtering.DeleteFilteringHdls(&flt_hdl, ip, 1) == false) + /* ipv6 case */ + if (m_filtering.DeleteFilteringHdls(&software_routing_fl_rule_hdl[1], + IPA_IP_v6, 1) == false) { IPACMERR("Error Adding Filtering rule, aborting...\n"); res = IPACM_FAILURE; goto fail; } - IPACM_Iface::ipacmcfg->decreaseFltRuleCount(rx_prop->rx[0].src_pipe, ip, 1); - softwarerouting_act = false; } -#endif + IPACM_Iface::ipacmcfg->decreaseFltRuleCount(rx_prop->rx[0].src_pipe, IPA_IP_v6, 1); + softwarerouting_act = false; fail: + if(pFilteringTable != NULL) + { + free(pFilteringTable); + } return res; } diff --git a/ipacm/src/IPACM_Lan.cpp b/ipacm/src/IPACM_Lan.cpp index fd67ea4..fff1783 100644 --- a/ipacm/src/IPACM_Lan.cpp +++ b/ipacm/src/IPACM_Lan.cpp @@ -511,7 +511,7 @@ void IPACM_Lan::event_callback(ipa_cm_event_id event, void *param) { /* handle software routing enable event*/ IPACMDBG_H("IPA_SW_ROUTING_ENABLE for iface: %s \n",IPACM_Iface::ipacmcfg->iface_table[ipa_if_num].iface_name); - handle_software_routing_enable(); + handle_software_routing_enable(false); } } @@ -1066,13 +1066,13 @@ void IPACM_Lan::event_callback(ipa_cm_event_id event, void *param) case IPA_SW_ROUTING_ENABLE: IPACMDBG_H("Received IPA_SW_ROUTING_ENABLE\n"); /* handle software routing enable event*/ - handle_software_routing_enable(); + handle_software_routing_enable(false); break; case IPA_SW_ROUTING_DISABLE: IPACMDBG_H("Received IPA_SW_ROUTING_DISABLE\n"); /* handle software routing disable event*/ - handle_software_routing_disable(); + handle_software_routing_disable(false); break; case IPA_CRADLE_WAN_MODE_SWITCH: @@ -3223,7 +3223,7 @@ fail: /* check software routing fl rule hdl */ if (softwarerouting_act == true && rx_prop != NULL) { - handle_software_routing_disable(); + handle_software_routing_disable(false); } if (odu_route_rule_v4_hdl != NULL) diff --git a/ipacm/src/IPACM_Wan.cpp b/ipacm/src/IPACM_Wan.cpp index 7638765..140be24 100644 --- a/ipacm/src/IPACM_Wan.cpp +++ b/ipacm/src/IPACM_Wan.cpp @@ -1179,7 +1179,15 @@ void IPACM_Wan::event_callback(ipa_cm_event_id event, void *param) { /* handle software routing enable event*/ IPACMDBG_H("IPA_SW_ROUTING_ENABLE for iface: %s \n",IPACM_Iface::ipacmcfg->iface_table[ipa_if_num].iface_name); - handle_software_routing_enable(); + + if(m_is_sta_mode == Q6_MHI_WAN) + { + handle_software_routing_enable(true); + } + else + { + handle_software_routing_enable(false); + } } } @@ -1632,9 +1640,13 @@ void IPACM_Wan::event_callback(ipa_cm_event_id event, void *param) { install_wan_filtering_rule(true); } + else if(m_is_sta_mode == Q6_MHI_WAN) + { + handle_software_routing_enable(true); + } else { - handle_software_routing_enable(); + handle_software_routing_enable(false); } break; @@ -1647,9 +1659,13 @@ void IPACM_Wan::event_callback(ipa_cm_event_id event, void *param) install_wan_filtering_rule(false); softwarerouting_act = false; } + else if(m_is_sta_mode == Q6_MHI_WAN) + { + handle_software_routing_disable(true); + } else { - handle_software_routing_disable(); + handle_software_routing_disable(false); } break; @@ -5381,7 +5397,14 @@ int IPACM_Wan::handle_down_evt() /* check software routing fl rule hdl */ if (softwarerouting_act == true) { - handle_software_routing_disable(); + if(m_is_sta_mode == Q6_MHI_WAN) + { + handle_software_routing_disable(true); + } + else + { + handle_software_routing_disable(false); + } } /* free dft ipv4 filter rule handlers if any */ if (ip_type != IPA_IP_v6 && rx_prop != NULL) @@ -5770,11 +5793,11 @@ int IPACM_Wan::handle_down_evt_ex() } } - /* check software routing fl rule hdl */ - if (softwarerouting_act == true) - { - handle_software_routing_disable(); - } +// /* check software routing fl rule hdl */ +// if (softwarerouting_act == true) +// { +// handle_software_routing_disable(); +// } fail: if (tx_prop != NULL) diff --git a/ipacm/src/IPACM_Wlan.cpp b/ipacm/src/IPACM_Wlan.cpp index f86dd1d..48fcc7e 100644 --- a/ipacm/src/IPACM_Wlan.cpp +++ b/ipacm/src/IPACM_Wlan.cpp @@ -350,7 +350,7 @@ void IPACM_Wlan::event_callback(ipa_cm_event_id event, void *param) { /* handle software routing enable event*/ IPACMDBG_H("IPA_SW_ROUTING_ENABLE for iface: %s \n",IPACM_Iface::ipacmcfg->iface_table[ipa_if_num].iface_name); - handle_software_routing_enable(); + handle_software_routing_enable(false); } } } @@ -860,13 +860,13 @@ void IPACM_Wlan::event_callback(ipa_cm_event_id event, void *param) /* handle software routing enable event, iface will update softwarerouting_act to true*/ case IPA_SW_ROUTING_ENABLE: IPACMDBG_H("Received IPA_SW_ROUTING_ENABLE\n"); - IPACM_Iface::handle_software_routing_enable(); + IPACM_Iface::handle_software_routing_enable(false); break; /* handle software routing disable event, iface will update softwarerouting_act to false*/ case IPA_SW_ROUTING_DISABLE: IPACMDBG_H("Received IPA_SW_ROUTING_DISABLE\n"); - IPACM_Iface::handle_software_routing_disable(); + IPACM_Iface::handle_software_routing_disable(false); break; case IPA_WLAN_SWITCH_TO_SCC: @@ -2119,7 +2119,7 @@ fail: if (softwarerouting_act == true && rx_prop != NULL ) { IPACMDBG_H("Delete sw routing filtering rules\n"); - IPACM_Iface::handle_software_routing_disable(); + IPACM_Iface::handle_software_routing_disable(false); } IPACMDBG_H("finished delete software-routing filtering rules\n "); -- cgit v1.2.3