Skip to content

Feature lwip broadcast #3491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions features/FEATURE_LWIP/lwip-interface/lwip_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,18 @@ static nsapi_error_t mbed_lwip_setsockopt(nsapi_stack_t *stack, nsapi_socket_t h
}
return 0;

case NSAPI_BROADCAST:
if (optlen != sizeof(int) || (s->conn->type != NETCONN_UDP && s->conn->type != NETCONN_RAW)) {
return NSAPI_ERROR_UNSUPPORTED;
}

if (*(int *)optval) {
s->conn->pcb.udp->so_options |= SOF_BROADCAST;
} else {
s->conn->pcb.udp->so_options &= SOF_BROADCAST;
}
return 0;

default:
return NSAPI_ERROR_UNSUPPORTED;
}
Expand Down
6 changes: 6 additions & 0 deletions features/netsocket/UDPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ nsapi_size_or_error_t UDPSocket::recvfrom(SocketAddress *address, void *buffer,
return ret;
}

nsapi_error_t UDPSocket::set_broadcast(bool broadcast)
{
int _broadcast = broadcast ? 1 : 0;
return setsockopt(NSAPI_SOCKET, NSAPI_BROADCAST, &_broadcast, sizeof(int));
}

void UDPSocket::event()
{
int32_t wcount = _write_sem.wait(0);
Expand Down
11 changes: 11 additions & 0 deletions features/netsocket/UDPSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ class UDPSocket : public Socket {
nsapi_size_or_error_t recvfrom(SocketAddress *address,
void *data, nsapi_size_t size);

/** Set broadcast packet behaviour
*
* Initially all sockets ignore broadcast packets.
* Setting broadcast to true enable the reception of broadcast packets.
*
* @param broadcast true to enable or false to disable broadcast
* packets reception
* @return nsapi_error_t on error or 0 if sucessfull
*/
nsapi_error_t set_broadcast(bool broadcast);
Copy link
Contributor

@geky geky Dec 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to add the appropriate doxygen documentation to this function? You can use the neighboring function's documentation as a template
https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/Socket.h#L109-L120

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, I'll add the documentation.


protected:
virtual nsapi_protocol_t get_proto();
virtual void event();
Expand Down
1 change: 1 addition & 0 deletions features/netsocket/nsapi_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ typedef enum nsapi_option {
NSAPI_LINGER, /*!< Keeps close from returning until queues empty */
NSAPI_SNDBUF, /*!< Sets send buffer size */
NSAPI_RCVBUF, /*!< Sets recv buffer size */
NSAPI_BROADCAST, /*!< Receive broadcast packets */
} nsapi_option_t;

/** nsapi_wifi_ap structure
Expand Down