Esempio n. 1
0
        public virtual int sceNetGetLocalEtherAddr(TPointer etherAddr)
        {
            // Return WLAN MAC address
            pspNetMacAddress macAddress = new pspNetMacAddress();

            macAddress.MacAddress = Wlan.MacAddress;
            macAddress.write(etherAddr);

            return(0);
        }
Esempio n. 2
0
 public virtual void sceNetEtherStrton(PspString str, TPointer etherAddr)
 {
     // This syscall is only doing something when both parameters are not 0.
     if (str.NotNull && etherAddr.NotNull)
     {
         // Convert string Mac address string representation (XX:XX:XX:XX:XX:XX)
         // into 6-byte representation.
         pspNetMacAddress macAddress = new pspNetMacAddress();
         macAddress.MacAddress = convertStringToMacAddress(str.String);
         macAddress.write(etherAddr);
     }
 }
Esempio n. 3
0
        public virtual bool inputLoop()
        {
            if (socket == null || !started)
            {
                return(false);
            }

            // Execute all the pending callback events
            while (pendingCallbackEvents.Count > 0)
            {
                CallbackEvent    callbackEvent = pendingCallbackEvents.RemoveFirst();
                pspNetMacAddress macAddress    = callbackEvent.MacAddress;
                macAddress.write(Memory.Instance, buffer.addr);
                notifyCallbackEvent(callbackEvent.Event, macAddress.BaseAddress, callbackEvent.OptLen, callbackEvent.OptData);
            }

            try
            {
                sbyte[] bytes  = new sbyte[BufSize + MAX_HEADER_SIZE];
                int     Length = socket.receive(bytes, bytes.Length);
                if (Length > 0)
                {
                    int         receivedPort    = socket.ReceivedPort;
                    InetAddress receivedAddress = socket.ReceivedAddress;
                    AdhocMatchingEventMessage adhocMatchingEventMessage = createMessage(bytes, Length);
                    if (isForMe(adhocMatchingEventMessage, receivedPort, receivedAddress))
                    {
                        int @event  = adhocMatchingEventMessage.Event;
                        int macAddr = buffer.addr;
                        int optData = buffer.addr + 8;
                        int optLen  = adhocMatchingEventMessage.DataLength;
                        adhocMatchingEventMessage.writeDataToMemory(optData);
                        pspNetMacAddress macAddress = new pspNetMacAddress();
                        macAddress.MacAddress = adhocMatchingEventMessage.FromMacAddress;
                        macAddress.write(Memory.Instance, macAddr);

                        //if (log.DebugEnabled)
                        {
                            Console.WriteLine(string.Format("Received message Length={0:D}, event={1:D}, fromMac={2}, port={3:D}: {4}", adhocMatchingEventMessage.DataLength, @event, macAddress, socket.ReceivedPort, adhocMatchingEventMessage));
                            if (log.TraceEnabled && optLen > 0)
                            {
                                log.trace(string.Format("Message data: {0}", Utilities.getMemoryDump(optData, optLen)));
                            }
                        }

                        // Keep track that we received a new message from this MAC address
                        Modules.sceNetAdhocctlModule.hleNetAdhocctlPeerUpdateTimestamp(adhocMatchingEventMessage.FromMacAddress);

                        if (@event == PSP_ADHOC_MATCHING_EVENT_JOIN)
                        {
                            pendingJoinRequest = adhocMatchingEventMessage.FromMacAddress;
                            inConnection       = true;
                        }
                        adhocMatchingEventMessage.processOnReceive(macAddr, optData, optLen);

                        if (@event == PSP_ADHOC_MATCHING_EVENT_ACCEPT)
                        {
                            addMember(adhocMatchingEventMessage.FromMacAddress);
                            //if (log.DebugEnabled)
                            {
                                Console.WriteLine(string.Format("Sending complete to port {0:D}", Port));
                            }
                            adhocMatchingEventMessage = createMessage(PSP_ADHOC_MATCHING_EVENT_COMPLETE, optData, optLen, macAddress.macAddress);
                            send(adhocMatchingEventMessage);

                            pendingComplete = true;
                            connected       = true;
                            inConnection    = false;
                        }
                        else if (@event == PSP_ADHOC_MATCHING_EVENT_COMPLETE)
                        {
                            addMember(adhocMatchingEventMessage.FromMacAddress);
                            if (!pendingComplete)
                            {
                                //if (log.DebugEnabled)
                                {
                                    Console.WriteLine(string.Format("Sending complete to port {0:D}", Port));
                                }
                                adhocMatchingEventMessage = createMessage(PSP_ADHOC_MATCHING_EVENT_COMPLETE, optData, optLen, macAddress.macAddress);
                                send(adhocMatchingEventMessage);
                            }
                            connected    = true;
                            inConnection = false;
                        }
                        else if (@event == PSP_ADHOC_MATCHING_EVENT_DATA)
                        {
                            //if (log.DebugEnabled)
                            {
                                Console.WriteLine(string.Format("Sending data confirm to port {0:D}", Port));
                            }
                            adhocMatchingEventMessage = createMessage(PSP_ADHOC_MATCHING_EVENT_DATA_CONFIRM, 0, 0, macAddress.macAddress);
                            send(adhocMatchingEventMessage);
                        }
                        else if (@event == PSP_ADHOC_MATCHING_EVENT_DISCONNECT || @event == PSP_ADHOC_MATCHING_EVENT_LEFT)
                        {
                            //if (log.DebugEnabled)
                            {
                                Console.WriteLine(string.Format("Received disconnect/leave from {0}", macAddress));
                            }
                            removeMember(adhocMatchingEventMessage.FromMacAddress);
                            if (members.Count <= 1)
                            {
                                connected    = false;
                                inConnection = false;
                            }
                        }
                    }
                    else
                    {
                        //if (log.DebugEnabled)
                        {
                            Console.WriteLine(string.Format("Received message not for me: {0}", adhocMatchingEventMessage));
                        }
                    }
                }
            }
            catch (SocketTimeoutException)
            {
                // Nothing available
            }
            catch (IOException e)
            {
                Console.WriteLine("inputLoop", e);
            }

            return(true);
        }
Esempio n. 4
0
        protected internal override bool pollAccept(int peerMacAddr, int peerPortAddr, SceKernelThreadInfo thread)
        {
            bool   acceptCompleted = false;
            Memory mem             = Memory.Instance;

            try
            {
                // Process a previously received connect message, if available
                JpcspAdhocPtpMessage adhocPtpMessage = connectRequest;
                int adhocPtpMessagePort = connectRequestPort;
                if (adhocPtpMessage == null)
                {
                    sbyte[] bytes  = new sbyte[BufSize + MAX_HEADER_SIZE];
                    int     Length = socket.receive(bytes, bytes.Length);
                    if (Length > 0)
                    {
                        adhocPtpMessage     = new JpcspAdhocPtpMessage(bytes, Length);
                        adhocPtpMessagePort = socket.ReceivedPort;

                        //if (log.DebugEnabled)
                        {
                            Console.WriteLine(string.Format("pollAccept: received message {0}", adhocPtpMessage));
                        }
                    }
                }
                else
                {
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("pollAccept: processing pending message {0}", adhocPtpMessage));
                    }
                }

                if (adhocPtpMessage != null && adhocPtpMessage.ForMe)
                {
                    switch (adhocPtpMessage.Type)
                    {
                    case PTP_MESSAGE_TYPE_CONNECT:
                        int acceptedId = adhocPtpMessage.DataInt32;
                        if (acceptedIds.Contains(acceptedId))
                        {
                            //if (log.DebugEnabled)
                            {
                                Console.WriteLine(string.Format("Connect message received for an id={0:D} already accepted. Dropping message.", acceptedId));
                            }
                        }
                        else
                        {
                            pspNetMacAddress peerMacAddress = new pspNetMacAddress();
                            peerMacAddress.MacAddress = adhocPtpMessage.FromMacAddress;
                            int peerPort = Modules.sceNetAdhocModule.getClientPortFromRealPort(adhocPtpMessage.FromMacAddress, adhocPtpMessagePort);

                            if (peerMacAddr != 0)
                            {
                                peerMacAddress.write(mem, peerMacAddr);
                            }
                            if (peerPortAddr != 0)
                            {
                                mem.write16(peerPortAddr, (short)peerPort);
                            }

                            // As a result of the "accept" call, create a new PTP Object
                            PtpObject ptpObject = new JpcspPtpObject(this);
                            ptpObject.DestMacAddress = peerMacAddress;
                            ptpObject.DestPort       = peerPort;
                            ptpObject.Port           = 0;
                            Modules.sceNetAdhocModule.hleAddPtpObject(ptpObject);

                            // Return the ID of the new PTP Object
                            setReturnValue(thread, ptpObject.Id);

                            // Remember that we have already accepted this Id.
                            acceptedIds.Add(acceptedId);

                            // Get a new free port
                            ptpObject.Port = 0;
                            ptpObject.openSocket();

                            // Send a connect confirmation message including the new port
                            JpcspAdhocPtpMessage confirmMessage = new JpcspAdhocPtpMessage(PTP_MESSAGE_TYPE_CONNECT_CONFIRM);
                            confirmMessage.DataInt32 = ptpObject.Port;
                            ptpObject.send(confirmMessage);

                            //if (log.DebugEnabled)
                            {
                                Console.WriteLine(string.Format("accept completed, creating new Ptp object {0}", ptpObject));
                            }

                            acceptCompleted = true;
                            connectRequest  = null;
                        }
                        break;
                    }
                }
                else
                {
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("pollAccept: received a message not for me: {0}", adhocPtpMessage));
                    }
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("pollAccept", e);
            }
            catch (SocketTimeoutException)
            {
                // Ignore exception
            }
            catch (IOException e)
            {
                Console.WriteLine("pollAccept", e);
            }

            return(acceptCompleted);
        }