Combined the interface set into the datalink_init for all the datalink layers. Changed all the demo programs to use datalink_init instead of specific datalink functions.
This commit is contained in:
@@ -178,7 +178,10 @@ static int arcnet_bind(char *interface_name)
|
||||
|
||||
bool arcnet_init(char *interface_name)
|
||||
{
|
||||
ARCNET_Sock_FD = arcnet_bind(interface_name);
|
||||
if (interface_name)
|
||||
ARCNET_Sock_FD = arcnet_bind(interface_name);
|
||||
else
|
||||
ARCNET_Sock_FD = arcnet_bind("arc0");
|
||||
|
||||
return arcnet_valid();
|
||||
}
|
||||
|
||||
@@ -71,7 +71,9 @@ static int get_local_address_ioctl(char *ifname,
|
||||
return rv;
|
||||
}
|
||||
|
||||
void bip_set_interface(char *ifname)
|
||||
|
||||
/* on Linux, ifname is eth0, ath0, arc0, and others. */
|
||||
static void bip_set_interface(char *ifname)
|
||||
{
|
||||
struct in_addr local_address;
|
||||
struct in_addr broadcast_address;
|
||||
@@ -91,13 +93,15 @@ void bip_set_interface(char *ifname)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool bip_init(void)
|
||||
bool bip_init(char *ifname)
|
||||
{
|
||||
int status = 0; /* return from socket lib calls */
|
||||
struct sockaddr_in sin;
|
||||
int sockopt = 0;
|
||||
int sock_fd = -1;
|
||||
|
||||
if (ifname)
|
||||
bip_set_interface(ifname);
|
||||
/* assumes that the driver has already been initialized */
|
||||
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
bip_set_socket(sock_fd);
|
||||
|
||||
@@ -170,8 +170,13 @@ static int get_local_hwaddr(const char *ifname, unsigned char *mac)
|
||||
|
||||
bool ethernet_init(char *interface_name)
|
||||
{
|
||||
get_local_hwaddr(interface_name, Ethernet_MAC_Address);
|
||||
eth802_sockfd = ethernet_bind(ð_addr, interface_name);
|
||||
if (interface_name) {
|
||||
get_local_hwaddr(interface_name, Ethernet_MAC_Address);
|
||||
eth802_sockfd = ethernet_bind(ð_addr, interface_name);
|
||||
} else {
|
||||
get_local_hwaddr("eth0", Ethernet_MAC_Address);
|
||||
eth802_sockfd = ethernet_bind(ð_addr, "eth0");
|
||||
}
|
||||
|
||||
return ethernet_valid();
|
||||
}
|
||||
|
||||
@@ -39,12 +39,6 @@
|
||||
|
||||
static int interface = SOCKET_ERROR; /* SOCKET_ERROR means no open interface */
|
||||
|
||||
void bip_set_interface(char *ifname)
|
||||
{
|
||||
/*dummy function - to make the demos compile easier */
|
||||
(void) ifname;
|
||||
}
|
||||
|
||||
/*-----------------------------------*/
|
||||
static void Error(const char *Msg)
|
||||
{
|
||||
@@ -244,7 +238,7 @@ static void set_broadcast_address(uint32_t net_address)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool bip_init(void)
|
||||
bool bip_init(char *ifname)
|
||||
{
|
||||
int rv = 0; /* return from socket lib calls */
|
||||
struct sockaddr_in sin = { -1 };
|
||||
@@ -252,6 +246,8 @@ bool bip_init(void)
|
||||
int sock_fd = -1;
|
||||
struct in_addr my_addr;
|
||||
|
||||
(void)ifname;
|
||||
|
||||
NetInitialize();
|
||||
|
||||
RTIP_To_Network_Address(TargetIP, &my_addr);
|
||||
|
||||
@@ -42,8 +42,9 @@ static uint8_t PDU_Buffer[MAX_MPDU];
|
||||
/* local MS/TP port data */
|
||||
static volatile struct mstp_port_struct_t MSTP_Port;
|
||||
|
||||
void dlmstp_init(void)
|
||||
{
|
||||
void dlmstp_init(char *ifname)
|
||||
{
|
||||
(void)ifname;
|
||||
/* initialize buffer */
|
||||
Receive_Buffer.ready = false;
|
||||
Receive_Buffer.pdu_len = 0;
|
||||
|
||||
@@ -140,18 +140,10 @@ int main(int argc, char *argv[])
|
||||
Init_Service_Handlers();
|
||||
RTOS_Initialize();
|
||||
/* init the physical layer */
|
||||
#ifdef BACDL_BIP
|
||||
if (!bip_init())
|
||||
return 1;
|
||||
#endif
|
||||
#ifdef BACDL_ETHERNET
|
||||
if (!ethernet_init(NULL))
|
||||
return 1;
|
||||
#endif
|
||||
#ifdef BACDL_MSTP
|
||||
dlmstp_set_my_address(0x05);
|
||||
dlmstp_init();
|
||||
#endif
|
||||
datalink_init(NULL);
|
||||
iam_send(&Handler_Transmit_Buffer[0]);
|
||||
/* loop forever */
|
||||
for (;;) {
|
||||
|
||||
@@ -99,13 +99,32 @@ static void cleanup(void)
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
|
||||
/* on Windows, ifname is the dotted ip address of the interface */
|
||||
void bip_set_interface(char *ifname)
|
||||
{
|
||||
(void) ifname;
|
||||
/* dummy function */
|
||||
struct in_addr address;
|
||||
|
||||
/* setup local address */
|
||||
if (bip_get_addr() == 0) {
|
||||
bip_set_addr(inet_addr(ifname));
|
||||
}
|
||||
#ifdef BIP_DEBUG
|
||||
fprintf(stderr, "IP Address: %s\n", inet_ntoa(address));
|
||||
#endif
|
||||
/* setup local broadcast address */
|
||||
if (bip_get_broadcast_addr() == 0) {
|
||||
address.s_addr = htonl(bip_get_addr());
|
||||
set_broadcast_address(address.s_addr);
|
||||
}
|
||||
#ifdef BIP_DEBUG
|
||||
address.s_addr = htonl(bip_get_broadcast_addr());
|
||||
fprintf(stderr, "Broadcast Address: %s\n",
|
||||
inet_ntoa(address));
|
||||
#endif
|
||||
}
|
||||
|
||||
bool bip_init(void)
|
||||
bool bip_init(char *ifname)
|
||||
{
|
||||
int rv = 0; /* return from socket lib calls */
|
||||
struct sockaddr_in sin = { -1 };
|
||||
@@ -126,7 +145,9 @@ bool bip_init(void)
|
||||
exit(1);
|
||||
}
|
||||
atexit(cleanup);
|
||||
|
||||
|
||||
if (ifname)
|
||||
bip_set_interface(ifname);
|
||||
/* has address been set? */
|
||||
address.s_addr = htonl(bip_get_addr());
|
||||
if (address.s_addr == 0) {
|
||||
|
||||
@@ -214,11 +214,8 @@ int main(int argc, char *argv[])
|
||||
Device_Set_Object_Instance_Number(124);
|
||||
Init_Service_Handlers();
|
||||
/* init the data link layer */
|
||||
/* configure standard BACnet/IP port */
|
||||
bip_set_port(0xBAC0);
|
||||
if (!bip_init())
|
||||
if (!datalink_init(NULL))
|
||||
return 1;
|
||||
|
||||
datalink_get_broadcast_address(&broadcast_address);
|
||||
print_address("Broadcast", &broadcast_address);
|
||||
datalink_get_my_address(&my_address);
|
||||
@@ -230,10 +227,8 @@ int main(int argc, char *argv[])
|
||||
/* input */
|
||||
|
||||
/* returns 0 bytes on timeout */
|
||||
pdu_len = bip_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||
|
||||
pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||
/* process */
|
||||
|
||||
if (pdu_len) {
|
||||
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user