Skip to content

Commit

Permalink
fix(NCM): set default NCM mode is connect, add notify judgement
Browse files Browse the repository at this point in the history
1. Set default network state is connected, in case not actively call tud_network_connect
2. The application layer can get the call result
  • Loading branch information
ESP-Coco committed Sep 14, 2023
1 parent 7d2b899 commit ef9422c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
33 changes: 28 additions & 5 deletions src/class/net/ncm_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ tu_static ncm_interface_t ncm_interface;

static void ncm_report(void);

uint8_t network_state;
// default network state is connected, in case not actively call tud_network_connect
static uint8_t network_state = NETWORK_CONNECTED;

/*
* Set up the NTB state in ncm_interface to be ready to add datagrams.
Expand Down Expand Up @@ -250,18 +251,40 @@ void tud_network_recv_renew(void)
tud_network_recv_cb(receive_ntb + ndp->datagram[i].wDatagramIndex, ndp->datagram[i].wDatagramLength);
}

void tud_network_disconnect(void)
bool tud_network_disconnect(void)
{
network_state = NETWORK_DISCONNECT;
// already disconnected
if (network_state == NETWORK_DISCONNECT) {
return true;
}

if (!ncm_interface.report_pending) {
ncm_interface.report_state = REPORT_CONNECTED;
network_state = NETWORK_DISCONNECT;
ncm_report();
} else {
// busy...
return false;
}
return true;
}

void tud_network_connect(void)
bool tud_network_connect(void)
{
network_state = NETWORK_CONNECTED;
// already connected
if (network_state == NETWORK_CONNECTED) {
return true;
}

if (!ncm_interface.report_pending) {
ncm_interface.report_state = REPORT_CONNECTED;
network_state = NETWORK_CONNECTED;
ncm_report();
return true;
} else {
// busy...
return false;
}
}

//--------------------------------------------------------------------+
Expand Down
12 changes: 6 additions & 6 deletions src/class/net/net_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ bool tud_network_can_xmit(uint16_t size);
// if network_can_xmit() returns true, network_xmit() can be called once
void tud_network_xmit(void *ref, uint16_t arg);

// indicate to network disconnect
void tud_network_disconnect(void);

// indicate to network connect
void tud_network_connect(void);

//--------------------------------------------------------------------+
// Application Callbacks (WEAK is optional)
//--------------------------------------------------------------------+
Expand All @@ -107,6 +101,12 @@ extern uint8_t tud_network_mac_address[6];
// callback to client providing optional indication of internal state of network driver
void tud_network_link_state_cb(bool state);

// indicate to network disconnect, only work in NCM
bool tud_network_disconnect(void);

// indicate to network connect, only work in NCM
bool tud_network_connect(void);

//--------------------------------------------------------------------+
// INTERNAL USBD-CLASS DRIVER API
//--------------------------------------------------------------------+
Expand Down

0 comments on commit ef9422c

Please sign in to comment.