ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/BeOS/ether_beos.cpp
(Generate patch)

Comparing BasiliskII/src/BeOS/ether_beos.cpp (file contents):
Revision 1.1 by cebix, 1999-10-03T14:16:25Z vs.
Revision 1.7 by cebix, 2001-07-13T15:39:22Z

# Line 1 | Line 1
1   /*
2   *  ether_beos.cpp - Ethernet device driver, BeOS specific stuff
3   *
4 < *  Basilisk II (C) 1997-1999 Christian Bauer
4 > *  Basilisk II (C) 1997-2001 Christian Bauer
5   *  Portions (C) 1997-1999 Marc Hellwig
6   *
7   *  This program is free software; you can redistribute it and/or modify
# Line 90 | Line 90 | static NetProtocol *find_protocol(uint16
90  
91  
92   /*
93 + *  Remove all protocols
94 + */
95 +
96 + static void remove_all_protocols(void)
97 + {
98 +        NetProtocol *p;
99 +        while ((p = (NetProtocol *)prot_list.RemoveItem((long)0)) != NULL)
100 +                delete p;
101 + }
102 +
103 +
104 + /*
105   *  Initialization
106   */
107  
108 < void EtherInit(void)
108 > bool ether_init(void)
109   {
110          // Do nothing if no Ethernet device specified
111          if (PrefsFindString("ether") == NULL)
112 <                return;
112 >                return false;
113  
114          // Find net_server team
115   i_wanna_try_that_again:
# Line 136 | Line 148 | i_wanna_try_that_again:
148                  // It was found, so something else must be wrong
149                  if (sheep_net_found) {
150                          WarningAlert(GetString(STR_NO_NET_ADDON_WARN));
151 <                        return;
151 >                        return false;
152                  }
153  
154                  // Not found, inform the user
155                  if (!ChoiceAlert(GetString(STR_NET_CONFIG_MODIFY_WARN), GetString(STR_OK_BUTTON), GetString(STR_CANCEL_BUTTON)))
156 <                        return;
156 >                        return false;
157  
158                  // Change the network config file and restart the network
159                  fin = fopen("/boot/home/config/settings/network", "r");
# Line 196 | Line 208 | i_wanna_try_that_again:
208          area_id handler_buffer;
209          if ((handler_buffer = find_area("packet buffer")) < B_NO_ERROR) {
210                  WarningAlert(GetString(STR_NET_ADDON_INIT_FAILED));
211 <                return;
211 >                return false;
212          }
213          if ((buffer_area = clone_area("local packet buffer", (void **)&net_buffer_ptr, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, handler_buffer)) < B_NO_ERROR) {
214                  D(bug("EtherInit: couldn't clone packet area\n"));
215                  WarningAlert(GetString(STR_NET_ADDON_CLONE_FAILED));
216 <                return;
216 >                return false;
217          }
218          if ((read_sem = create_sem(0, "ether read")) < B_NO_ERROR) {
219                  printf("FATAL: can't create Ethernet semaphore\n");
220 <                return;
220 >                return false;
221          }
222          net_buffer_ptr->read_sem = read_sem;
223          write_sem = net_buffer_ptr->write_sem;
# Line 221 | Line 233 | i_wanna_try_that_again:
233          D(bug("Ethernet address %02x %02x %02x %02x %02x %02x\n", ether_addr[0], ether_addr[1], ether_addr[2], ether_addr[3], ether_addr[4], ether_addr[5]));
234  
235          // Everything OK
236 <        net_open = true;
236 >        return true;
237   }
238  
239  
# Line 229 | Line 241 | i_wanna_try_that_again:
241   *  Deinitialization
242   */
243  
244 < void EtherExit(void)
244 > void ether_exit(void)
245   {
246 <        if (net_open) {
246 >        // Close communications with add-on
247 >        for (int i=0; i<WRITE_PACKET_COUNT; i++)
248 >                net_buffer_ptr->write[i].cmd = IN_USE | (DEACTIVATE_SHEEP_NET << 8);
249 >        release_sem(write_sem);
250  
251 <                // Close communications with add-on
252 <                for (int i=0; i<WRITE_PACKET_COUNT; i++)
253 <                        net_buffer_ptr->write[i].cmd = IN_USE | (DEACTIVATE_SHEEP_NET << 8);
254 <                release_sem(write_sem);
251 >        // Quit reception thread
252 >        ether_thread_active = false;
253 >        status_t result;
254 >        release_sem(read_sem);
255 >        wait_for_thread(read_thread, &result);
256  
257 <                // Quit reception thread
258 <                ether_thread_active = false;
259 <                status_t result;
260 <                release_sem(read_sem);
261 <                wait_for_thread(read_thread, &result);
246 <
247 <                delete_sem(read_sem);
248 <                delete_area(buffer_area);
249 <
250 <                // Remove all protocols
251 <                NetProtocol *p;
252 <                while ((p = (NetProtocol *)prot_list.RemoveItem((long)0)) != NULL)
253 <                        delete p;
254 <        }
257 >        delete_sem(read_sem);
258 >        delete_area(buffer_area);
259 >
260 >        // Remove all protocols
261 >        remove_all_protocols();
262   }
263  
264  
# Line 259 | Line 266 | void EtherExit(void)
266   *  Reset
267   */
268  
269 < void EtherReset(void)
269 > void ether_reset(void)
270   {
271 <        // Remove all protocols
265 <        NetProtocol *p;
266 <        while ((p = (NetProtocol *)prot_list.RemoveItem((long)0)) != NULL)
267 <                delete p;
271 >        remove_all_protocols();
272   }
273  
274  
# Line 274 | Line 278 | void EtherReset(void)
278  
279   int16 ether_add_multicast(uint32 pb)
280   {
277        uint8 *addr = Mac2HostAddr(pb + eMultiAddr);
281          net_packet *p = &net_buffer_ptr->write[wr_pos];
282          if (p->cmd & IN_USE) {
283                  D(bug("WARNING: Couldn't enable multicast address\n"));
284          } else {
285 <                memcpy(p->data, addr, 6);
285 >                Mac2Host_memcpy(p->data, pb + eMultiAddr, 6);
286                  p->length = 6;
287                  p->cmd = IN_USE | (ADD_MULTICAST << 8);
288                  wr_pos = (wr_pos + 1) % WRITE_PACKET_COUNT;
# Line 295 | Line 298 | int16 ether_add_multicast(uint32 pb)
298  
299   int16 ether_del_multicast(uint32 pb)
300   {
298        uint8 *addr = Mac2HostAddr(pb + eMultiAddr);
301          net_packet *p = &net_buffer_ptr->write[wr_pos];
302          if (p->cmd & IN_USE) {
303                  D(bug("WARNING: Couldn't enable multicast address\n"));
304          } else {
305 <                memcpy(p->data, addr, 6);
305 >                Mac2Host_memcpy(p->data, pb + eMultiAddr, 6);
306                  p->length = 6;
307                  p->cmd = IN_USE | (REMOVE_MULTICAST << 8);
308                  wr_pos = (wr_pos + 1) % WRITE_PACKET_COUNT;
# Line 359 | Line 361 | int16 ether_write(uint32 wds)
361          } else {
362  
363                  // Copy packet to buffer
364 <                uint8 *start;
363 <                uint8 *bp = start = p->data;
364 <                for (;;) {
365 <                        int len = ReadMacInt16(wds);
366 <                        if (len == 0)
367 <                                break;
368 <                        memcpy(bp, Mac2HostAddr(ReadMacInt32(wds + 2)), len);
369 <                        bp += len;
370 <                        wds += 6;
371 <                }
364 >                int len = ether_wds_to_buffer(wds, p->data);
365  
366                  // Set source address
367 <                memcpy(start + 6, ether_addr, 6);
367 >                memcpy(p->data + 6, ether_addr, 6);
368  
369   #if MONITOR
370                  bug("Sending Ethernet packet:\n");
371 <                for (int i=0; i<(uint32)(bp-start); i++) {
372 <                        bug("%02x ", start[i]);
371 >                for (int i=0; i<len; i++) {
372 >                        bug("%02x ", p->data[i]);
373                  }
374                  bug("\n");
375   #endif
376  
377                  // Notify add-on
378 <                p->length = (uint32)(bp - start);
378 >                p->length = len;
379                  p->cmd = IN_USE | (SHEEP_PACKET << 8);
380                  wr_pos = (wr_pos + 1) % WRITE_PACKET_COUNT;
381                  release_sem(write_sem);
# Line 441 | Line 434 | void EtherInterrupt(void)
434                                  goto next;
435  
436                          // Copy header to RHA
437 <                        memcpy(Mac2HostAddr(ether_data + ed_RHA), p->data, 14);
437 >                        Host2Mac_memcpy(ether_data + ed_RHA, p->data, 14);
438                          D(bug(" header %08lx%04lx %08lx%04lx %04lx\n", ReadMacInt32(ether_data + ed_RHA), ReadMacInt16(ether_data + ed_RHA + 4), ReadMacInt32(ether_data + ed_RHA + 6), ReadMacInt16(ether_data + ed_RHA + 10), ReadMacInt16(ether_data + ed_RHA + 12)));
439  
440                          // Call protocol handler

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines