1#include "main-header.h"
6 nir->status = nir->status | (1 << bit);
9 nir->status = nir->status & ~(1 << bit);
13 return (nir->status & (1 << bit)) ? 1 : 0;
17void print_all_nics() {
21 printf(
"Network interfaces:\r\n");
30 if (nic_get_status_bit(nir, STATUS_PROBED)) {
33 printf(
"NOT PROBED |");
35 if (nic_get_status_bit(nir, STATUS_PROBE_SUCCESS)) {
36 printf(
"PROBE_SUCCESS |");
38 printf(
"NOT PROBE_SUCCESS |");
40 if (nic_get_status_bit(nir, STATUS_INITIALISED)) {
41 printf(
"INITIALISED |");
43 printf(
"NOT INITIALISED |");
45 if (nic_get_status_bit(nir, STATUS_READY_TO_TRANSMIT)) {
46 printf(
"READY_TO_TRANSMIT");
48 printf(
"NOT READY_TO_TRANSMIT");
52 if (nir->nif->info == NULL) {
53 printf(
" no info available\r\n");
62 if (config_get_ti1101disable()) {
63 printf(
"NICs disabled\r\n");
74 printf(
"Probing network device %i (%s) (handle %i)\r\n", nir->source,
command_get_source_name(nir->source), nir->mculib_handle);
75 if (nir->nif->probe == NULL) {
79 int p = nir->nif->probe(nir);
80 nic_set_status_bit(nir, STATUS_PROBED);
81 release_irq_by_handle(nir->mculib_handle);
82 mculib_release_by_handle(nir->mculib_handle);
83 mculib_print_mappings(&printf);
85 printf(
"Skipping network device %i (%s) - probe() failed, code=%i\r\n", nir->source,
command_get_source_name(nir->source), p);
88 nic_set_status_bit(nir, STATUS_PROBE_SUCCESS);
97 if (nic_get_status_bit(nir, STATUS_PROBE_SUCCESS) == 0) {
98 printf(
"Skipping network device %i (%s) - probe did not detect it\r\n", nir->source,
command_get_source_name(nir->source));
102 if (nir->nif->init == NULL) {
108 int p = nir->nif->init(nir);
110 printf(
"Initialisation of network device %i (%s) failed with code %i\r\n", nir->source,
command_get_source_name(nir->source), p);
113 nic_set_status_bit(nir, STATUS_INITIALISED);
118int stop_nic_by_type(
int source) {
121 if (!nic_get_status_bit(nc, STATUS_INITIALISED)) {
124 if ((nc != NULL) && (nc->nif->stop != NULL)) {
129int start_nic_by_type(
int source) {
132 if ((nc != NULL) && (nc->nif->init != NULL)) {
134 if (nic_get_status_bit(nc, STATUS_INITIALISED)) {
136 int rc = nc->nif->init(nc);
138 nic_set_status_bit(nc, STATUS_INITIALISED);
140 nic_clr_status_bit(nc, STATUS_INITIALISED);
152 com->sourcedev = nctx->source;
155 com->target = 0xFFFFFFFF;
156 com->recipient = 0xFFFFFFFF;
157 com->flags = COMFLAGS_ACK | COMFLAGS_SUCCESS;
158 if (config_get_flag(CONFIG_FLAGS_POWER_SAVE)) {
159 com->flags |= COMFLAGS_POWERSAVE;
166 printf(
"nicmanager: failed to announce, reason: %i\r\n", r);
171int nic_is_busy(
int source) {
177 if ((nctx->status & (1 << STATUS_PROBE_SUCCESS)) == 0) {
181 if (nctx->nif->busy == NULL) {
185 return nctx->nif->busy(nctx);
191void nic_set_transmit_status(
struct network_context *nctx,
int status) {
193 if ((nctx->status & (1 << STATUS_PROBE_SUCCESS)) == 0) {
197 nctx->status = nctx->status | (1 << STATUS_READY_TO_TRANSMIT);
203 nctx->status = nctx->status & ~(1 << STATUS_READY_TO_TRANSMIT);
208int isready_by_type(
int source) {
214 return nctx->status & (1 << STATUS_READY_TO_TRANSMIT);
218int isonline_by_type(
int source) {
224 if ((nctx->status & (1 << STATUS_READY_TO_TRANSMIT)) || (nctx->status & (1 << STATUS_INITIALISED))) {
231void process_nic_event_loop() {
240 if ((nir->nif->loop != NULL) && (nir->status & (1 << STATUS_INITIALISED))) {
char * command_get_source_name(byte sourcedev)
returns a human readable text identifying a source device
int send_command(struct command *com)
send a command to another module (or broadcast)
void free_command(struct command *com)
free a command
void command_add_arg(struct command *com, const char *format,...)
adds an arg to a partially initialised command structure
long get_my_node_id()
get the id of my node
byte get_hops_to_server()
how many hops to the server?
struct command * alloc_command()
allocate a free command