Esempio n. 1
0
/* /// "usbReleaseInterfaceBinding()" */
void usbReleaseInterfaceBinding(struct NepHidBase *nh, struct NepClassHid *nch)
{
    struct Library *ps;
    struct PsdConfig *pc;
    struct PsdDevice *pd;
    STRPTR devname;

    KPRINTF(1, ("nepHidReleaseInterfaceBinding(%08lx)\n", nch));
    if((ps = OpenLibrary("poseidon.library", 4)))
    {
        Forbid();
        nch->nch_ReadySignal = SIGB_SINGLE;
        nch->nch_ReadySigTask = FindTask(NULL);
        if(nch->nch_GUITask)
        {
            Signal(nch->nch_GUITask, SIGBREAKF_CTRL_C);
        }
        Permit();
        while(nch->nch_GUITask)
        {
            Wait(1L<<nch->nch_ReadySignal);
        }

        Forbid();
        if(nch->nch_Task)
        {
            Signal(nch->nch_Task, SIGBREAKF_CTRL_C);
        }
        Permit();
        while(nch->nch_Task)
        {
            Wait(1L<<nch->nch_ReadySignal);
        }
        //FreeSignal(nch->nch_ReadySignal);
        psdGetAttrs(PGA_INTERFACE, nch->nch_Interface, IFA_Config, &pc, TAG_END);
        psdGetAttrs(PGA_CONFIG, pc, CA_Device, &pd, TAG_END);
        psdGetAttrs(PGA_DEVICE, pd, DA_ProductName, &devname, TAG_END);
        psdAddErrorMsg(RETURN_OK, (STRPTR) libname,
                       "A cat ate my mouse '%s'!",
                       devname);
        Forbid();
        Remove(&nch->nch_Node);
        Permit();
        psdFreeVec(nch->nch_CDC);
        psdFreeVec(nch);
        CloseLibrary(ps);
    }
}
Esempio n. 2
0
/* /// "nHIDCtrlGUITaskCleanup()" */
void GM_UNIQUENAME(nHIDCtrlGUITaskCleanup)(struct NepClassHid *nch)
{
    struct NepHidGItem *nhgi;
    if(nch->nch_HCApp)
    {
        MUI_DisposeObject(nch->nch_HCApp);
        nch->nch_HCApp = NULL;
        nch->nch_HCActionObj = NULL;
    }

    nhgi = (struct NepHidGItem *) nch->nch_HCGUIItems.lh_Head;
    while(nhgi->nhgi_Node.ln_Succ)
    {
        Remove(&nhgi->nhgi_Node);
        psdFreeVec(nhgi->nhgi_Name);
        psdFreeVec(nhgi);
        nhgi = (struct NepHidGItem *) nch->nch_HCGUIItems.lh_Head;
    }
    if(nch->nch_HCActionClass)
    {
        MUI_DeleteCustomClass(nch->nch_HCActionClass);
        nch->nch_HCActionClass = NULL;
    }

    if(MUIMasterBase)
    {
        CloseLibrary(MUIMasterBase);
        MUIMasterBase = NULL;
    }
    if(IntuitionBase)
    {
        CloseLibrary(IntuitionBase);
        IntuitionBase = NULL;
    }
    if(ps)
    {
        CloseLibrary(ps);
        ps = NULL;
    }
    Forbid();
    nch->nch_HCGUITask = NULL;
    if(nch->nch_ReadySigTask)
    {
        Signal(nch->nch_ReadySigTask, 1L<<nch->nch_ReadySignal);
    }
    --nch->nch_ClsBase->nh_Library.lib_OpenCnt;
}
Esempio n. 3
0
struct NepClassUPS * SetupUPS(void)
{
    struct NepClassUPS *nch;
    struct PsdDevice *pd = NULL;
    struct PsdAppBinding *pab;
    ULONG unit;

    if(ArgsArray[ARGS_UNIT])
    {
        unit = *((ULONG *) ArgsArray[ARGS_UNIT]);
    } else {
        unit = 0;
    }
    do
    {
        do
        {
            pd = psdFindDevice(pd,
                               DA_VendorID, 0x04b4,
                               DA_ProductID, 0xfd11,
                               TAG_END);

        } while(pd && (unit--));

        if(!pd)
        {
            PutStr("No GemBird PowerManager found!\n");
            return(NULL);
        }
        if((nch = psdAllocVec(sizeof(struct NepClassUPS))))
        {
            nch->nch_Device = pd;
            nch->nch_ReleaseHook.h_Entry = (APTR) releasehook;

            pab = psdClaimAppBinding(ABA_Device, pd,
                                     ABA_ReleaseHook, &nch->nch_ReleaseHook,
                                     ABA_UserData, nch,
                                     ABA_ForceRelease, TRUE,
                                     TAG_END);
            if(pab)
            {
                if(AllocUPS(nch))
                {
                    return(nch);
                } else {
                    PutStr("Couldn't allocate PowerManager...\n");
                }
                psdReleaseAppBinding(pab);
            } else {
                PutStr("Couldn't claim binding!\n");
            }
            psdFreeVec(nch);
        }
        PutStr("Hohum...\n");
    } while(TRUE);
    return(NULL);
}
Esempio n. 4
0
struct urndis_comp_hdr *
urndis_ctrl_recv(struct NepClassEth *ncp)
{

    struct urndis_comp_hdr  *hdr;
    char            *buf;
    LONG         err;
    LONG sc_ifaceno_ctl=0;


    buf = psdAllocVec(RNDIS_RESPONSE_LEN);
    if (buf == NULL) {
        bug("%s: out of memory\n", DEVNAME);
        return NULL;
    }

    err = urndis_ctrl_msg(ncp, UT_READ_CLASS_INTERFACE, UR_CLEAR_FEATURE,
        sc_ifaceno_ctl, 0, buf, RNDIS_RESPONSE_LEN);

    if (err != 0) {
        bug("%s: urndis_comp_hdr error\n", DEVNAME);
        psdFreeVec(buf);
        return NULL;
    }

    hdr = (struct urndis_comp_hdr *)buf;
    bug("%s: urndis_ctrl_recv: type 0x%x len %u\n",
        DEVNAME,
        hdr->rm_type,
        letoh32(hdr->rm_len));

    //dumpmem(buf,hdr->rm_len);

    if (letoh32(hdr->rm_len) > RNDIS_RESPONSE_LEN) {
        bug("%s: ctrl message error: wrong size %u > %u\n",
            DEVNAME,
            letoh32(hdr->rm_len),
            RNDIS_RESPONSE_LEN);
        psdFreeVec(buf);
        return NULL;
    }

    return hdr;
}
Esempio n. 5
0
struct NepClassDRadio * SetupDRadio(void)
{
    struct NepClassDRadio *nch;
    struct PsdDevice *pd = NULL;
    struct PsdAppBinding *pab;
    ULONG unit;

    if(ArgsArray[ARGS_UNIT])
    {
        unit = *((ULONG *) ArgsArray[ARGS_UNIT]);
    } else {
        unit = 0;
    }
    do
    {
        do
        {
            pd = psdFindDevice(pd,
                               DA_VendorID, 0x04b4,
                               DA_ProductID, 0x1002,
                               TAG_END);
        } while(pd && (unit--));

        if(!pd)
        {
            PutStr("No D-Link/GemTek Radio found!\n");
            return(NULL);
        }
        if((nch = psdAllocVec(sizeof(struct NepClassDRadio))))
        {
            nch->nch_Device = pd;
            nch->nch_ReleaseHook.h_Entry = (APTR) releasehook;

            pab = psdClaimAppBinding(ABA_Device, pd,
                                     ABA_ReleaseHook, &nch->nch_ReleaseHook,
                                     ABA_UserData, nch,
                                     TAG_END);
            if(pab)
            {
                if(AllocDRadio(nch))
                {
                    return(nch);
                } else {
                    PutStr("Couldn't allocate DRadio...\n");
                }
                psdReleaseAppBinding(pab);
            } else {
                PutStr("Couldn't claim binding!\n");
            }
            psdFreeVec(nch);
        }
        PutStr("Hohum...\n");
    } while(TRUE);
    return(NULL);
}
Esempio n. 6
0
void
urndis_attach(struct NepClassEth *ncp)
{

    uint8_t              eaddr[ETHER_ADDR_SIZE];
    void                *buf;
    size_t               bufsz;
    uint32_t             filter;

    urndis_ctrl_init(ncp);

    if (urndis_ctrl_query(ncp, OID_802_3_PERMANENT_ADDRESS, NULL, 0,
        &buf, &bufsz) != RNDIS_STATUS_SUCCESS) {
        bug("%s: unable to get hardware address\n", DEVNAME);
        return;
    }
    if (bufsz == ETHER_ADDR_SIZE) {
        memcpy(eaddr, buf, ETHER_ADDR_SIZE);
        bug("%s: address %x:%x:%x:%x:%x:%x\n", DEVNAME, eaddr[0],eaddr[1],eaddr[2],eaddr[3],eaddr[4],eaddr[5]);
        psdFreeVec(buf);
    } else {
        bug("%s: invalid address\n", DEVNAME);
        psdFreeVec(buf);
        return;
    }

    /* Initialize packet filter */
    ncp->sc_filter = RNDIS_PACKET_TYPE_BROADCAST;
    ncp->sc_filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
    filter = htole32(ncp->sc_filter);
    if (urndis_ctrl_set(ncp, OID_GEN_CURRENT_PACKET_FILTER, &filter,
        sizeof(filter)) != RNDIS_STATUS_SUCCESS) {
        bug("%s: unable to set data filters\n", DEVNAME);
        return;
    }

    bug("%s: urndis_attach OK!\n", DEVNAME);

    CopyMem(eaddr, ncp->ncp_MacAddress, ETHER_ADDR_SIZE);
    CopyMem(eaddr, ncp->ncp_ROMAddress, ETHER_ADDR_SIZE);

}
Esempio n. 7
0
uint32_t
urndis_ctrl_query(struct NepClassEth *ncp, uint32_t oid,
    void *qbuf, size_t qlen,
    void **rbuf, size_t *rbufsz)
{
    struct urndis_query_req *msg;
    uint32_t         rval;
    struct urndis_comp_hdr  *hdr;

    msg = psdAllocVec(sizeof(*msg) + qlen);
    if (msg == NULL) {
        bug("%s: out of memory\n", DEVNAME);
        return RNDIS_STATUS_FAILURE;
    }

    msg->rm_type = htole32(REMOTE_NDIS_QUERY_MSG);
    msg->rm_len = htole32(sizeof(*msg) + qlen);
    msg->rm_rid = 0; /* XXX */
    msg->rm_oid = htole32(oid);
    msg->rm_infobuflen = htole32(qlen);
    if (qlen != 0) {
        msg->rm_infobufoffset = htole32(20);
        memcpy((char*)msg + 20, qbuf, qlen);
    } else
        msg->rm_infobufoffset = 0;
    msg->rm_devicevchdl = 0;

    bug("%s: urndis_ctrl_query send: type %u len %u rid %u oid 0x%x "
        "infobuflen %u infobufoffset %u devicevchdl %u\n",
        DEVNAME,
        letoh32(msg->rm_type),
        letoh32(msg->rm_len),
        letoh32(msg->rm_rid),
        letoh32(msg->rm_oid),
        letoh32(msg->rm_infobuflen),
        letoh32(msg->rm_infobufoffset),
        letoh32(msg->rm_devicevchdl));

    rval = urndis_ctrl_send(ncp, msg, sizeof(*msg));
    psdFreeVec(msg);

    if (rval != RNDIS_STATUS_SUCCESS) {
        bug("%s: query failed\n", DEVNAME);
        return rval;
    }

    if ((hdr = urndis_ctrl_recv(ncp)) == NULL) {
        bug("%s: unable to get query response\n", DEVNAME);
        return RNDIS_STATUS_FAILURE;
    }
    rval = urndis_ctrl_handle(ncp, hdr, rbuf, rbufsz);

    return rval;
}
Esempio n. 8
0
void FreeRocket(struct NepClassRocket *nch)
{
    APTR pab;

    psdGetAttrs(PGA_DEVICE, nch->nch_Device,
                DA_Binding, &pab,
                TAG_END);
    psdReleaseAppBinding(pab);
    psdFreePipe(nch->nch_EP0Pipe);
    DeleteMsgPort(nch->nch_TaskMsgPort);
    psdFreeVec(nch);
}
Esempio n. 9
0
/* /// "usbForceInterfaceBinding()" */
struct NepClassHid * usbForceInterfaceBinding(struct NepHidBase *nh, struct PsdInterface *pif)
{
    struct Library *ps;
    struct NepClassHid *nch;
    struct PsdConfig *pc;
    struct PsdDevice *pd;
    STRPTR devname;
    UBYTE buf[64];
    struct Task *tmptask;

    KPRINTF(1, ("nepHidAttemptInterfaceBinding(%08lx)\n", pif));
    if((ps = OpenLibrary("poseidon.library", 4)))
    {
        if((nch = psdAllocVec(sizeof(struct NepClassHid))))
        {
            nch->nch_ClsBase = nh;
            nch->nch_Device = NULL;
            nch->nch_Interface = pif;

            nLoadClassConfig(nh);

            psdSafeRawDoFmt(buf, 64, "simplemidi.class<%08lx>", nch);
            nch->nch_ReadySignal = SIGB_SINGLE;
            nch->nch_ReadySigTask = FindTask(NULL);
            SetSignal(0, SIGF_SINGLE);
            if((tmptask = psdSpawnSubTask(buf, nHidTask, nch)))
            {
                psdBorrowLocksWait(tmptask, 1UL<<nch->nch_ReadySignal);
                if(nch->nch_Task)
                {
                    nch->nch_ReadySigTask = NULL;
                    //FreeSignal(nch->nch_ReadySignal);
                    psdGetAttrs(PGA_INTERFACE, pif, IFA_Config, &pc, TAG_END);
                    psdGetAttrs(PGA_CONFIG, pc, CA_Device, &pd, TAG_END);
                    psdGetAttrs(PGA_DEVICE, pd, DA_ProductName, &devname, TAG_END);
                    psdAddErrorMsg(RETURN_OK, (STRPTR) libname,
                                   "Play it again, '%s'!",
                                   devname);

                    CloseLibrary(ps);
                    return(nch);
                }
            }
            nch->nch_ReadySigTask = NULL;
            //FreeSignal(nch->nch_ReadySignal);
            psdFreeVec(nch);
        }
        CloseLibrary(ps);
    }
    return(NULL);
}
Esempio n. 10
0
uint32_t urndis_ctrl_init(struct NepClassEth *ncp)
{
    struct urndis_init_req  *msg;
    uint32_t         rval;
    struct urndis_comp_hdr  *hdr;

    msg =  psdAllocVec(sizeof(*msg));
    if (msg == NULL) {
        bug("out of memory\n");
        return RNDIS_STATUS_FAILURE;
    }

    msg->rm_type = htole32(REMOTE_NDIS_INITIALIZE_MSG);
    msg->rm_len = htole32(sizeof(*msg));
    msg->rm_rid = htole32(0);
    msg->rm_ver_major = htole32(1);
    msg->rm_ver_minor = htole32(1);
    msg->rm_max_xfersz = htole32(RNDIS_BUFSZ);

    bug("%s: urndis_ctrl_init send: type %u len %u rid %u ver_major %u "
        "ver_minor %u max_xfersz %u\n",
        DEVNAME,
        letoh32(msg->rm_type),
        letoh32(msg->rm_len),
        letoh32(msg->rm_rid),
        letoh32(msg->rm_ver_major),
        letoh32(msg->rm_ver_minor),
        letoh32(msg->rm_max_xfersz));

    //Delay(50);

    rval = urndis_ctrl_send(ncp, msg, sizeof(*msg));
    psdFreeVec(msg);

    if (rval != 0 ) {
        bug("%s: init failed\n", DEVNAME);
        return rval;
    }

    if ((hdr = urndis_ctrl_recv(ncp)) == NULL) {
        bug("%s: unable to get init response\n", DEVNAME);
        return RNDIS_STATUS_FAILURE;
    }
    rval = urndis_ctrl_handle(ncp, hdr, NULL, NULL);

    return rval;
}
Esempio n. 11
0
uint32_t urndis_ctrl_handle(struct NepClassEth *ncp, struct urndis_comp_hdr *hdr,void **buf, size_t *bufsz)
{
    uint32_t rval;

    bug("%s: urndis_ctrl_handle\n", DEVNAME);

    if (buf && bufsz) {
        *buf = NULL;
        *bufsz = 0;
    }

    switch (letoh32(hdr->rm_type)) {
        case REMOTE_NDIS_INITIALIZE_CMPLT:
            rval = urndis_ctrl_handle_init(ncp, hdr);
            break;

        case REMOTE_NDIS_QUERY_CMPLT:
            rval = urndis_ctrl_handle_query(ncp, hdr, buf, bufsz);
            break;

        case REMOTE_NDIS_RESET_CMPLT:
            rval = urndis_ctrl_handle_reset(ncp, hdr);
            break;

        case REMOTE_NDIS_KEEPALIVE_CMPLT:
        case REMOTE_NDIS_SET_CMPLT:
            rval = letoh32(hdr->rm_status);
            break;

        default:
            bug("%s: ctrl message error: unknown event 0x%x\n",
                DEVNAME, letoh32(hdr->rm_type));
            rval = RNDIS_STATUS_FAILURE;
    }

     psdFreeVec(hdr);

    return rval;
}
Esempio n. 12
0
struct FELSunxiDevice * ForceDeviceBinding(LIBBASETYPEPTR LIBBASE, struct PsdDevice *pd) {
    mybug(-1,("FELSunxi ForceDeviceBinding\n"));

    struct FELSunxiDevice *FELSunxiDevice;
    struct Library *ps;

    if((ps = OpenLibrary("poseidon.library", 4))) {
        FELSunxiDevice = psdAllocVec(sizeof(struct FELSunxiDevice));
        if(FELSunxiDevice) {
            FELSunxiDevice->ps = ps;
            FELSunxiDevice->pd = pd;
            /* Open MUI for FELSunxiTask, don't bother to continue if it fails */
            FELSunxiDevice->MUIMasterBase = OpenLibrary("muimaster.library", 0);
            if(FELSunxiDevice->MUIMasterBase) {
                mybug(-1,("Creating FELSunxiTask\n"));
                FELSunxiDevice->readysignal = SIGB_SINGLE;
                FELSunxiDevice->readysigtask = FindTask(NULL);
                SetSignal(0, SIGF_SINGLE);

                FELSunxiDevice->felsunxitask = psdSpawnSubTask("FELSunxi task", FELSunxiTask, FELSunxiDevice);
                if(FELSunxiDevice->felsunxitask) {
                /* Wait for FELSunxiTask to be ready */
                    psdBorrowLocksWait(FELSunxiDevice->felsunxitask, 1UL<<FELSunxiDevice->readysignal);
                    return FELSunxiDevice;
                } else {
                    mybug(-1,("Failed to spawn the task\n"));
                }
                CloseLibrary(FELSunxiDevice->MUIMasterBase);
            }
            psdFreeVec(FELSunxiDevice);
        }
        CloseLibrary(ps);
    }

    return NULL;
}
Esempio n. 13
0
/* /// "usbForceInterfaceBinding()" */
struct NepClassHid * usbForceInterfaceBinding(struct NepHidBase *nh, struct PsdInterface *pif)
{
    struct Library *ps;
    struct NepClassHid *nch;
    struct PsdConfig *pc;
    struct PsdDevice *pd;
    STRPTR devname;
    STRPTR ifidstr;
    STRPTR devidstr;
    UBYTE buf[64];
    struct Task *tmptask;

    KPRINTF(1, ("nepHidForceInterfaceBinding(%08lx)\n", pif));
    if((ps = OpenLibrary("poseidon.library", 4)))
    {
        psdGetAttrs(PGA_INTERFACE, pif,
                    IFA_Config, &pc,
                    IFA_IDString, &ifidstr,
                    TAG_DONE);
        psdGetAttrs(PGA_CONFIG, pc,
                    CA_Device, &pd,
                    TAG_END);
        psdGetAttrs(PGA_DEVICE, pd,
                    DA_ProductName, &devname,
                    DA_IDString, &devidstr,
                    TAG_END);
        if((nch = psdAllocVec(sizeof(struct NepClassHid))))
        {
            nch->nch_ClsBase = nh;
            nch->nch_CDC = psdAllocVec(sizeof(struct ClsDevCfg));
            if(!nch->nch_CDC)
            {
                psdFreeVec(nch);
                CloseLibrary(ps);
                return(NULL);
            }

            nch->nch_Device = pd;
            nch->nch_Interface = pif;
            nch->nch_DevIDString = devidstr;
            nch->nch_IfIDString = ifidstr;

            nLoadBindingConfig(nch);

            psdSafeRawDoFmt(buf, 64, "bootmouse.class<%08lx>", nch);
            nch->nch_ReadySignal = SIGB_SINGLE;
            nch->nch_ReadySigTask = FindTask(NULL);
            SetSignal(0, SIGF_SINGLE);
            if((tmptask = psdSpawnSubTask(buf, nHidTask, nch)))
            {
                psdBorrowLocksWait(tmptask, 1UL<<nch->nch_ReadySignal);
                if(nch->nch_Task)
                {
                    nch->nch_ReadySigTask = NULL;
                    //FreeSignal(nch->nch_ReadySignal);
                    psdAddErrorMsg(RETURN_OK, (STRPTR) libname,
                                   "I'm pleased to introduce a mouse alliance to '%s'!",
                                   devname);

                    Forbid();
                    AddTail(&nh->nh_Bindings, &nch->nch_Node);
                    Permit();
                    CloseLibrary(ps);
                    return(nch);
                }
            }
            nch->nch_ReadySigTask = NULL;
            //FreeSignal(nch->nch_ReadySignal);
            psdFreeVec(nch->nch_CDC);
            psdFreeVec(nch);
        }
        CloseLibrary(ps);
    }
    return(NULL);

}
Esempio n. 14
0
/* /// "usbForceInterfaceBinding()" */
struct NepClassHid * usbForceInterfaceBinding(struct NepHidBase *nh, struct PsdInterface *pif)
{
    struct Library *ps;
    struct Library *DOSBase;
    struct NepClassHid *nch;
    struct PsdConfig *pc;
    struct PsdDevice *pd;
    STRPTR devname;
    UBYTE buf[64];
    struct Task *tmptask;

    KPRINTF(1, ("nepHidAttemptInterfaceBinding(%08lx)\n", pif));
    if((ps = OpenLibrary("poseidon.library", 4)))
    {
        if((nch = psdAllocVec(sizeof(struct NepClassHid))))
        {
            STRPTR srcpos;
            STRPTR tarpos;
            UWORD cnt;

            psdGetAttrs(PGA_INTERFACE, pif, IFA_Config, &pc, TAG_END);
            psdGetAttrs(PGA_CONFIG, pc, CA_Device, &pd, TAG_END);
            psdGetAttrs(PGA_DEVICE, pd, DA_ProductName, &devname, TAG_END);

            // generate ID
            srcpos = devname;
            tarpos = nch->nch_ShortID;
            cnt = 31;
            while(*srcpos && cnt)
            {
                if(((*srcpos >= 'A') && (*srcpos <= 'Z')) ||
                   ((*srcpos >= 'a') && (*srcpos <= 'z')) ||
                   ((*srcpos >= '0') && (*srcpos <= '9')))
                {
                    *tarpos++ = *srcpos;
                    cnt--;
                }
                srcpos++;
            }
            *tarpos = 0;

            nch->nch_ClsBase = nh;
            nch->nch_Device = NULL;
            nch->nch_Interface = pif;

            nLoadClassConfig(nh);

            psdSafeRawDoFmt(buf, 64, "camdusbmidi.class<%08lx>", nch);
            nch->nch_ReadySignal = SIGB_SINGLE;
            nch->nch_ReadySigTask = FindTask(NULL);
            SetSignal(0, SIGF_SINGLE);
            if((tmptask = psdSpawnSubTask(buf, nHidTask, nch)))
            {
                psdBorrowLocksWait(tmptask, 1UL<<nch->nch_ReadySignal);
                if(nch->nch_Task)
                {
                    nch->nch_ReadySigTask = NULL;
                    //FreeSignal(nch->nch_ReadySignal);
                    Forbid();
                    AddTail(&nh->nh_Bindings, &nch->nch_Node);
                    Permit();

                    psdAddErrorMsg(RETURN_OK, (STRPTR) libname,
                                   "Play it again, '%s'!",
                                   devname);
                    if((DOSBase = OpenLibrary("dos.library", 37)))
                    {
                        BPTR fh;
                        BPTR lock;

                        psdSafeRawDoFmt(buf, 64, "%s/%s", (STRPTR) "DEVS:Midi", nch->nch_ShortID);
                        fh = Open(buf, MODE_OLDFILE);
                        if(!fh)
                        {
                            fh = Open(buf, MODE_NEWFILE);
                            if(!fh)
                            {
                                lock = CreateDir("DEVS:Midi");
                                if(lock)
                                {
                                    UnLock(lock);
                                    psdAddErrorMsg(RETURN_OK, (STRPTR) libname,
                                                   "Created directory '%s'!",
                                                   (STRPTR) "DEVS:Midi");
                                }
                                fh = Open(buf, MODE_NEWFILE);
                            }
                            if(!fh)
                            {
                                psdAddErrorMsg(RETURN_ERROR, (STRPTR) libname,
                                               "Couldn't generate CAMD MIDI driver '%s'!",
                                               buf);
                            } else {
                                UBYTE *tmpmem = psdAllocVec(sizeof(CAMDDriver));
                                if(tmpmem)
                                {
                                    CopyMemQuick(CAMDDriver, tmpmem, sizeof(CAMDDriver));
                                    // fix name of driver -- position is hardcoded, but unlikely to move
                                    strcpy(&tmpmem[0x46], nch->nch_ShortID);
                                    Write(fh, tmpmem, sizeof(CAMDDriver));
                                    psdFreeVec(tmpmem);
                                    psdAddErrorMsg(RETURN_OK, (STRPTR) libname,
                                                   "Generated CAMD MIDI driver '%s'!",
                                                   buf);
                                }
                                Close(fh);
                            }

                        } else {
                            Close(fh);
                        }
                        CloseLibrary(DOSBase);
                    }
                    CloseLibrary(ps);
                    return(nch);
                }
            }
            nch->nch_ReadySigTask = NULL;
            //FreeSignal(nch->nch_ReadySignal);
            psdFreeVec(nch);
        }
        CloseLibrary(ps);
    }
    return(NULL);
}
Esempio n. 15
0
/* /// "ApplyDragAction()" */
BOOL ApplyDragAction(Object *obj, LONG targetentry)
{
    struct PrefsListEntry *targetplnode = NULL;
    struct PrefsListEntry *sourceplnode = NULL;
    ULONG sourceid, targetid;
    IPTR sourceentry = -1;
    LONG result;
    APTR pic, spic, tpic;
    APTR form;

    get(obj, MUIA_List_Active, &sourceentry);
    if((((LONG) sourceentry) < 0) || (targetentry < 0))
    {
        return(FALSE);
    }
    DoMethod(obj, MUIM_List_GetEntry, sourceentry, &sourceplnode);
    DoMethod(obj, MUIM_List_GetEntry, targetentry, &targetplnode);
    if((!(sourceplnode && targetplnode)) || (sourceplnode == targetplnode))
    {
        return(FALSE);
    }
    sourceid = sourceplnode->chunkid;
    targetid = targetplnode->chunkid;

    switch(sourceid)
    {
        case IFFFORM_DEVICECFG:
            if(targetid == IFFFORM_DEVICECFG)
            {
                result = MUI_Request(_app(obj), _win(obj), 0, NULL, "Replace|Merge|Cancel",
                                     "Do you want to \33breplace\33n or \33bmerge\33n the prefs of\n"
                                     "\33b%s\33n\n"
                                     "with the contents from\n"
                                     "\33b%s\33n?", targetplnode->id, sourceplnode->id);
                if(result < 1)
                {
                    return(FALSE);
                }
                tpic = NULL;
                spic = NULL;
                pic = psdFindCfgForm(NULL, IFFFORM_DEVICECFG);
                while(pic)
                {
                    if(psdMatchStringChunk(pic, IFFCHNK_DEVID, targetplnode->devid))
                    {
                        tpic = pic;
                    }
                    if(psdMatchStringChunk(pic, IFFCHNK_DEVID, sourceplnode->devid))
                    {
                        spic = pic;
                    }
                    pic = psdNextCfgForm(pic);
                }
                if(!(tpic && spic))
                {
                    return(FALSE);
                }
                // delete old contents
                if(result == 1)
                {
                    while((pic = psdFindCfgForm(tpic, IFFFORM_DEVCFGDATA)))
                    {
                        psdRemCfgForm(pic);
                    }
                    while((pic = psdFindCfgForm(tpic, IFFFORM_IFCFGDATA)))
                    {
                        psdRemCfgForm(pic);
                    }
                }

                // copy device cfg data
                pic = psdFindCfgForm(spic, IFFFORM_DEVCFGDATA);
                while(pic)
                {
                    form = psdWriteCfg(pic);
                    if(form)
                    {
                        psdAddCfgEntry(tpic, form);
                        psdFreeVec(form);
                    }
                    pic = psdNextCfgForm(pic);
                }
                // copy interface cfg data
                pic = psdFindCfgForm(spic, IFFFORM_IFCFGDATA);
                while(pic)
                {
                    form = psdWriteCfg(pic);
                    if(form)
                    {
                        psdAddCfgEntry(tpic, form);
                        psdFreeVec(form);
                    }
                    pic = psdNextCfgForm(pic);
                }
                return(TRUE);
            }
            break;

        case IFFFORM_IFCFGDATA:
        case IFFFORM_DEVCFGDATA:
            if((targetid == IFFFORM_DEVCFGDATA) || (targetid == IFFFORM_IFCFGDATA))
            {
                if(strcmp(sourceplnode->owner, targetplnode->owner))
                {
                    result = MUI_RequestA(_app(obj), _win(obj), 0, NULL, "Add to device|Cancel",
                                          "Sorry, but only prefs of the same owner can\n"
                                          "be replaced.\n\n"
                                          "Do you wish to add this prefs\n"
                                          "to the device instead?", NULL);
                    if(result < 1)
                    {
                        return(FALSE);
                    }
                    targetid = IFFFORM_DEVICECFG;
                } else {
                    result = MUI_Request(_app(obj), _win(obj), 0, NULL, "Replace|Cancel",
                                         "Do you want to \33breplace\33n the prefs of\n"
                                         "\33b%s\33n\n"
                                         "by those of\n"
                                         "\33b%s\33n?", targetplnode->id, sourceplnode->id);

                    if(result < 1)
                    {
                        return(FALSE);
                    }
                    pic = psdGetUsbDevCfg(sourceplnode->owner, sourceplnode->devid, sourceplnode->ifid);
                    if(pic)
                    {
                        form = psdWriteCfg(pic);
                        if(form)
                        {
                            psdSetUsbDevCfg(sourceplnode->owner, targetplnode->devid, targetplnode->ifid, form);
                            psdFreeVec(form);
                        }
                    }
                    return(TRUE);
                }
            }
            if(targetid == IFFFORM_DEVICECFG)
            {
                pic = psdGetUsbDevCfg(sourceplnode->owner, targetplnode->devid, sourceplnode->ifid);
                if(pic)
                {
                    result = MUI_Request(_app(obj), _win(obj), 0, NULL, "Replace|Cancel",
                                         "Do you want to \33breplace\33n the prefs of\n"
                                         "\33b%s\33n\n"
                                         "by the one in\n"
                                         "\33b%s\33n?", targetplnode->id, sourceplnode->id);
                } else {
                    result = MUI_Request(_app(obj), _win(obj), 0, NULL, "Add|Cancel",
                                         "Do you want to \33badd\33n the prefs of\n"
                                         "\33b%s\33n\n"
                                         "to the device\n"
                                         "\33b%s\33n?", sourceplnode->id, targetplnode->id);
                }
                if(result < 1)
                {
                    return(FALSE);
                }
                pic = psdGetUsbDevCfg(sourceplnode->owner, sourceplnode->devid, sourceplnode->ifid);
                if(pic)
                {
                    form = psdWriteCfg(pic);
                    if(form)
                    {
                        psdSetUsbDevCfg(sourceplnode->owner, targetplnode->devid, sourceplnode->ifid, form);
                        psdFreeVec(form);
                    }
                }
                return(TRUE);
            }
            break;

        case IFFCHNK_FORCEDBIND:
            if((targetid == IFFFORM_DEVICECFG) ||
               (targetid == IFFFORM_DEVCFGDATA) ||
               (targetid == IFFFORM_IFCFGDATA) ||
               (targetid == IFFCHNK_FORCEDBIND))
            {
                psdSetForcedBinding(sourceplnode->owner, targetplnode->devid, targetplnode->ifid);
                return(TRUE);
            }
            break;
    }
    return(FALSE);
}