123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- #include <unistd.h>
- #include <sys/ioctl.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <cstring>
- #include "HeaderInsertion.h"
- #include "TestsUtils.h"
- #define LOG_IOCTL_RETURN_VALUE(nRetVal) \
- printf("%s()- %s\n", __func__, \
- (-1 == nRetVal) ? "Fail" : "Success");
- bool HeaderInsertion::AddHeader(struct ipa_ioc_add_hdr *pHeaderTableToAdd)
- {
- int nRetVal = 0;
-
- nRetVal = ioctl(m_fd, IPA_IOC_ADD_HDR, pHeaderTableToAdd);
- LOG_IOCTL_RETURN_VALUE(nRetVal);
- return (-1 != nRetVal);
- }
- bool HeaderInsertion::addHeaderHpc(const string& name, uint8_t* header, const size_t headerLen, bool isPartial, enum ipa_client_type ipaClient){
- if(name.empty() || name.size() >= IPA_RESOURCE_NAME_MAX){
- return false;
- }
- int fd = open(CONFIGURATION_NODE_PATH, O_RDONLY);
- if (fd < 0) {
- cout << "failed to open " << CONFIGURATION_NODE_PATH << endl;
- return false;
- }
- struct ipa_ioc_add_hdr *iocH = static_cast<struct ipa_ioc_add_hdr*>(calloc(1, sizeof(*iocH) + sizeof(struct ipa_hdr_add)));
- if(!iocH){
- return false;
- }
- iocH->commit = 1;
- iocH->num_hdrs = 1;
- struct ipa_hdr_add *h = &iocH->hdr[0];
- strlcpy(h->name, name.c_str(), IPA_RESOURCE_NAME_MAX);
- memcpy(h->hdr, header, headerLen);
- h->hdr_len = headerLen;
- h->hdr_hdl = -1;
- h->status = -1;
- h->is_partial = isPartial;
- cout << "h->name=" << h->name << ", h->is_partial=" << h->is_partial << endl;
- int result = ioctl(fd, IPA_TEST_IOC_ADD_HDR_HPC, iocH);
- if(result || h->status){
- free(iocH);
- close(fd);
- return false;
- }
- cout << "result=" << result << ", status=" << h->status << ", ipaClient=" << ipaClient << endl;
- struct ipa_pkt_init_ex_hdr_ofst_set lookup;
- lookup.ep = ipaClient;
- strlcpy(lookup.name, name.c_str(), IPA_RESOURCE_NAME_MAX);
- result = ioctl(fd, IPA_TEST_IOC_PKT_INIT_EX_SET_HDR_OFST , &lookup);
- if (result) {
- free(iocH);
- close(fd);
- return false;
- }
- free(iocH);
- close(fd);
- return true;
- }
- bool HeaderInsertion::DeleteHeader(struct ipa_ioc_del_hdr *pHeaderTableToDelete)
- {
- int nRetVal = 0;
-
- nRetVal = ioctl(m_fd, IPA_IOC_DEL_HDR , pHeaderTableToDelete);
- LOG_IOCTL_RETURN_VALUE(nRetVal);
- return (-1 != nRetVal);
- }
- bool HeaderInsertion::DeleteHeader(const string& name){
- if(name.empty() || name.size() >= IPA_RESOURCE_NAME_MAX){
- return false;
- }
- int hdl = GetHeaderHandle(name);
- if(hdl == -1){
- return false;
- }
- struct ipa_ioc_del_hdr *iocD = static_cast<struct ipa_ioc_del_hdr*>(calloc(1, sizeof(*iocD) + sizeof(struct ipa_hdr_del)));
- if(!iocD){
- return false;
- }
- iocD->commit = 1;
- iocD->num_hdls = 1;
- struct ipa_hdr_del *h = &iocD->hdl[0];
- h->hdl = hdl;
- h->status = -1;
- cout << "h->hdl=" << h->hdl << endl;
- if(!DeleteHeader(iocD)){
- free(iocD);
- return false;
- }
- free(iocD);
- return true;
- }
- bool HeaderInsertion::AddProcCtx(struct ipa_ioc_add_hdr_proc_ctx *procCtxTable)
- {
- int retval = 0;
- retval = ioctl(m_fd, IPA_IOC_ADD_HDR_PROC_CTX, procCtxTable);
- if (retval) {
- printf("%s(), failed adding ProcCtx rule table %p\n", __FUNCTION__, procCtxTable);
- return false;
- }
- printf("%s(), Added ProcCtx rule to table %p\n", __FUNCTION__, procCtxTable);
- return true;
- }
- bool HeaderInsertion::DeleteProcCtx(struct ipa_ioc_del_hdr_proc_ctx *procCtxTable)
- {
- int retval = 0;
- retval = ioctl(m_fd, IPA_IOC_DEL_HDR_PROC_CTX, procCtxTable);
- if (retval) {
- printf("%s(), failed deleting ProcCtx rule in table %p\n", __FUNCTION__, procCtxTable);
- return false;
- }
- printf("%s(), Deleted ProcCtx rule in table %p\n", __FUNCTION__, procCtxTable);
- return true;
- }
- bool HeaderInsertion::Commit()
- {
- int nRetVal = 0;
- nRetVal = ioctl(m_fd, IPA_IOC_COMMIT_HDR);
- LOG_IOCTL_RETURN_VALUE(nRetVal);
- return true;
- }
- bool HeaderInsertion::Reset()
- {
- int nRetVal = 0;
- nRetVal = ioctl(m_fd, IPA_IOC_RESET_HDR);
- nRetVal |= ioctl(m_fd, IPA_IOC_COMMIT_HDR);
- LOG_IOCTL_RETURN_VALUE(nRetVal);
- return true;
- }
- bool HeaderInsertion::GetHeaderHandle(struct ipa_ioc_get_hdr *pHeaderStruct)
- {
- int retval = 0;
- if (!DeviceNodeIsOpened())
- return false;
- retval = ioctl(m_fd, IPA_IOC_GET_HDR, pHeaderStruct);
- if (retval) {
- printf(
- "%s(), IPA_IOC_GET_HDR ioctl failed, routingTable =0x%p, retval=0x%x.\n"
- , __func__,
- pHeaderStruct,
- retval);
- return false;
- }
- printf(
- "%s(), IPA_IOC_GET_HDR ioctl issued to IPA header insertion block.\n",
- __func__);
- return true;
- }
- int HeaderInsertion::GetHeaderHandle(const string& name){
- if(name.empty() || name.size() >= IPA_RESOURCE_NAME_MAX){
- return false;
- }
- struct ipa_ioc_get_hdr retHeader;
- memset(&retHeader, 0, sizeof(retHeader));
- strlcpy(retHeader.name, name.c_str(), IPA_RESOURCE_NAME_MAX);
- retHeader.hdl = -1;
- printf("retHeader.name=%s\n", retHeader.name);
- if(!GetHeaderHandle(&retHeader)){
- cout << "GetHeaderHandle(&retHeader) Failed" << endl;
- return -1;
- }
- cout << "retHeader.hdl=" << retHeader.hdl << endl;
- return retHeader.hdl;
- }
- bool HeaderInsertion::CopyHeader(struct ipa_ioc_copy_hdr *pCopyHeaderStruct)
- {
- int retval = 0;
- if (!DeviceNodeIsOpened())
- return false;
- retval = ioctl(m_fd, IPA_IOC_COPY_HDR, pCopyHeaderStruct);
- if (retval) {
- printf(
- "%s(), IPA_IOC_COPY_HDR ioctl failed, retval=0x%x.\n",
- __func__,
- retval);
- return false;
- }
- printf(
- "%s(), IPA_IOC_COPY_HDR ioctl issued to IPA header insertion block.\n",
- __func__);
- return true;
- }
|