Skip to content

Commit

Permalink
RDKTV-30016 - [miracast] Connection fails with "ENT-32203/ENT-32102/E…
Browse files Browse the repository at this point in the history
…NT-32103" after Thunder restart

Signed-off-by: yuvaramachandran_gurusamy <[email protected]>
  • Loading branch information
yuvaramachandran-gurusamy committed May 2, 2024
1 parent 6296082 commit a9bc034
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
52 changes: 51 additions & 1 deletion Miracast/MiracastService/MiracastController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,53 @@ std::string MiracastController::parse_p2p_event_data(const char *tmpBuff, const
return std::string(" ");
}

std::string MiracastController::getifNameByIPv4(std::string ip_address)
{
struct ifaddrs *ifaddrList = nullptr, *currentifa = nullptr;
int family, s;
char host[MAX_IFACE_NAME_LEN];
std::string ifaceName = "";

// Get list of all network interfaces
if ( -1 == getifaddrs(&ifaddrList))
{
MIRACASTLOG_ERROR("getifaddrs failed[%s]",strerror(errno));
}
else
{
// Iterate through the list of network interfaces
for ( currentifa = ifaddrList; nullptr != currentifa; currentifa = currentifa->ifa_next)
{
if ( nullptr == currentifa->ifa_addr )
{
continue;
}
family = currentifa->ifa_addr->sa_family;
// Check for IPv4 address
if ( AF_INET == family )
{
s = getnameinfo(currentifa->ifa_addr, sizeof(struct sockaddr_in), host, MAX_IFACE_NAME_LEN, NULL, 0, NI_NUMERICHOST);
if (s != 0)
{
MIRACASTLOG_ERROR("getnameinfo failed[%s]",strerror(errno));
break;
}
// Compare IP address with the given IP
if ( 0 == strcmp(host, ip_address.c_str()))
{
ifaceName = currentifa->ifa_name;
}
}
}
if ( nullptr != ifaddrList )
{
freeifaddrs(ifaddrList);
ifaddrList = nullptr;
}
}
return ifaceName;
}

std::string MiracastController::start_DHCPClient(std::string interface, std::string &default_gw_ip_addr)
{
MIRACASTLOG_TRACE("Entering...");
Expand Down Expand Up @@ -484,7 +531,10 @@ MiracastError MiracastController::set_WFDParameters(void)
{
MIRACASTLOG_TRACE("Entering...");
MiracastError ret = MIRACAST_FAIL;
if (nullptr != m_p2p_ctrl_obj){
if (nullptr != m_p2p_ctrl_obj)
{
std::string ifName = getifNameByIPv4("192.168.59.1");
m_p2p_ctrl_obj->remove_GroupInterface(ifName);
ret = m_p2p_ctrl_obj->set_WFDParameters();
}
MIRACASTLOG_TRACE("Exiting...");
Expand Down
7 changes: 7 additions & 0 deletions Miracast/RTSP/MiracastRtspMsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,13 @@ MiracastError MiracastRTSPMsg::initiate_TCP(std::string goIP)
MIRACASTLOG_ERROR("TCP Socket creation error %s", strerror(errno));
continue;
}
// Set SO_REUSEADDR option
int optval = 1;
if (setsockopt(m_tcpSockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1)
{
MIRACASTLOG_ERROR("Failed to set SO_REUSEADDR: %s", strerror(errno));
continue;
}
#if 0
/* Bind socket */
if (bind(m_tcpSockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
Expand Down
4 changes: 4 additions & 0 deletions Miracast/include/MiracastController.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <arpa/inet.h>
#include <sys/epoll.h>
#include <fstream>
#include <ifaddrs.h>
#include <netdb.h>
#include <MiracastCommon.h>
#include "MiracastP2P.h"
#include "MiracastLogger.h"
Expand All @@ -41,6 +43,7 @@ using namespace std;
using namespace MIRACAST;

#define THUNDER_REQ_THREAD_CLIENT_CONNECTION_WAITTIME (30)
#define MAX_IFACE_NAME_LEN 16

class MiracastController
{
Expand Down Expand Up @@ -124,6 +127,7 @@ class MiracastController
MiracastError create_ControllerFramework(std::string p2p_ctrl_iface);
MiracastError destroy_ControllerFramework(void);
void checkAndInitiateP2PBackendDiscovery(void);
std::string getifNameByIPv4(std::string ip_address);

void set_localIp(std::string ipAddr);

Expand Down

0 comments on commit a9bc034

Please sign in to comment.