initial commit (with submodule)
This commit is contained in:
commit
740ef1bfbf
33 changed files with 11760 additions and 0 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "pjproject"]
|
||||
path = pjproject
|
||||
url = https://github.com/pjsip/pjproject
|
339
COPYING
Normal file
339
COPYING
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
26
Makefile
Normal file
26
Makefile
Normal file
|
@ -0,0 +1,26 @@
|
|||
PJSIP_DIR=pjproject-2.11.1
|
||||
PKG_CONFIG_PATH=pjsip.install/lib/pkgconfig
|
||||
|
||||
all: d-modem slmodemd
|
||||
|
||||
$(PKG_CONFIG_PATH)/libpjproject.pc:
|
||||
(cd $(PJSIP_DIR); [ -f ./config.status ] || ./configure --prefix=`pwd`/../pjsip.install --disable-video)
|
||||
$(MAKE) -C $(PJSIP_DIR) && \
|
||||
$(MAKE) -C $(PJSIP_DIR) install
|
||||
|
||||
d-modem: d-modem.c $(PKG_CONFIG_PATH)/libpjproject.pc
|
||||
$(CC) -o $@ $< `PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --static --cflags --libs libpjproject`
|
||||
|
||||
slmodemd:
|
||||
$(MAKE) -C slmodemd
|
||||
|
||||
clean:
|
||||
rm -f d-modem.o d-modem
|
||||
$(MAKE) -C slmodemd clean
|
||||
|
||||
realclean: clean
|
||||
$(MAKE) -C $(PJSIP_DIR) realclean
|
||||
rm -rf pjsip.install/*
|
||||
|
||||
|
||||
.PHONY: all clean realclean slmodemd
|
71
README.md
Normal file
71
README.md
Normal file
|
@ -0,0 +1,71 @@
|
|||
# D-Modem
|
||||
Connect to dialup modems over VoIP using SIP, no modem hardware required.
|
||||
|
||||
https://www.aon.com/cyber-solutions/aon_cyber_labs/introducing-d-modem-a-software-sip-modem/
|
||||
|
||||
## Building
|
||||
You'll need Linux and a working 32-bit development environment (gcc -m32 needs to work, Debian-based systems can install libc6-dev-i386), along with PJSIP's dependencies (OpenSSL). Then run 'make' from the top-level directory.
|
||||
|
||||
## How it Works
|
||||
Traditional “controller-based” modems generally used a microcontroller and a DSP to handle all aspects of modem communication on the device itself. Later, so-called “Winmodems” were introduced that allowed for field-programmable DSPs and moved the controller and other functionality into software running on the host PC. This was followed by “pure software” modems that moved DSP functionality to the host as well. The physical hardware of these softmodems was only used to connect to the phone network, and all processing was done in software.
|
||||
|
||||
D-Modem replaces a softmodem’s physical hardware with a SIP stack. Instead of passing audio to and from the software DSP over an analog phone line, audio travels via the RTP (or SRTP) media streams of a SIP VoIP call.
|
||||
|
||||
## Usage
|
||||
The repository contains two applications:
|
||||
|
||||
slmodemd – A stripped down and patched version of Debian’s sl-modem-daemon package. All kernel driver code has been replaced with socket-based communication, allowing external applications to manage audio streams.
|
||||
|
||||
d-modem – External application that interfaces with slmodemd to manage SIP calls and their associated audio streams.
|
||||
|
||||
After they have been built, you will need to configure SIP account information in the SIP_LOGIN environment variable:
|
||||
|
||||
# export SIP_LOGIN=username:password@sip.example.com
|
||||
Next, run slmodemd, passing the path to d-modem in the -e option. Use -d<level> for debug logging.
|
||||
|
||||
# ./slmodemd/slmodemd -d9 -e ./d-modem
|
||||
SmartLink Soft Modem: version 2.9.11 Oct 28 2021 16:51:30
|
||||
symbolic link `/dev/ttySL0' -> `/dev/pts/3' created.
|
||||
modem `slamr0' created. TTY is `/dev/pts/3'
|
||||
Use `/dev/ttySL0' as modem device, Ctrl+C for termination.
|
||||
|
||||
In another terminal, connect to the newly created serial device at 115200 bps:
|
||||
|
||||
# screen /dev/ttySL0 115200
|
||||
|
||||
You can now interact with this terminal (almost) as you would with a normal modem using standard AT commands. A similar modem’s manual provides a more complete list.
|
||||
|
||||
Because there isn’t any dial tone on our SIP connection, you’ll need to disable dial tone detection:
|
||||
|
||||
atx3
|
||||
OK
|
||||
|
||||
To successfully connect, you will likely need to manually select a modulation and data rate. In our testing, V.32bis (14.4kbps) and below appears to be the most reliable, though V.34 (33.6kbps) connections are sometimes successful. For example, the following command selects V.32bis with a data rate of 4800 – 9600 bps. Refer to the manual for further details.
|
||||
|
||||
at+ms=132,0,4800,9600
|
||||
OK
|
||||
|
||||
Finally, dial the number of the target system. Below shows a connection to the NIST atomic clock:
|
||||
|
||||
atd303-494-4774
|
||||
CONNECT 9600
|
||||
National Institute of Standards and Technology
|
||||
Telephone Time Service, Generator 1b
|
||||
Enter the question mark character for HELP
|
||||
D L
|
||||
MJD YR MO DA HH MM SS ST S UT1 msADV <OTM>
|
||||
59515 21-10-28 21:40:18 11 0 -.1 045.0 UTC(NIST) *
|
||||
59515 21-10-28 21:40:19 11 0 -.1 045.0 UTC(NIST) *
|
||||
59515 21-10-28 21:40:20 11 0 -.1 045.0 UTC(NIST) *
|
||||
59515 21-10-28 21:40:21 11 0 -.1 045.0 UTC(NIST) *
|
||||
59515 21-10-28 21:40:22 11 0 -.1 045.0 UTC(NIST) *
|
||||
59515 21-10-28 21:40:23 11 0 -.1 045.0 UTC(NIST) *
|
||||
|
||||
## Known Issues / Future Work
|
||||
- Connections are unreliable, and it is currently difficult to connect at speeds higher than 14.4kbps or so. It might be possible to improve this by disabling/reconfiguring PJSIP’s jitter buffer.
|
||||
- Additional logging/error handling is needed
|
||||
- The serial interface could be replaced with stdio or a socket, and common AT configuration options could be exposed as command line options
|
||||
- There is currently no support for receiving calls
|
||||
|
||||
|
||||
Copyright 2021 Aon plc
|
262
d-modem.c
Normal file
262
d-modem.c
Normal file
|
@ -0,0 +1,262 @@
|
|||
/*
|
||||
* Copyright (C) 2021 Aon plc
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <pjsua-lib/pjsua.h>
|
||||
|
||||
#define SIGNATURE PJMEDIA_SIG_CLASS_PORT_AUD('D','M')
|
||||
|
||||
struct dmodem {
|
||||
pjmedia_port base;
|
||||
pj_timestamp timestamp;
|
||||
pj_sock_t sock;
|
||||
};
|
||||
|
||||
static struct dmodem port;
|
||||
static bool destroying = false;
|
||||
static pj_pool_t *pool;
|
||||
|
||||
static void error_exit(const char *title, pj_status_t status) {
|
||||
pjsua_perror(__FILE__, title, status);
|
||||
if (!destroying) {
|
||||
destroying = true;
|
||||
pjsua_destroy();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static pj_status_t dmodem_put_frame(pjmedia_port *this_port, pjmedia_frame *frame) {
|
||||
struct dmodem *sm = (struct dmodem *)this_port;
|
||||
int len;
|
||||
|
||||
if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO) {
|
||||
if ((len=write(sm->sock, frame->buf, frame->size)) != frame->size) {
|
||||
error_exit("error writing frame",0);
|
||||
}
|
||||
}
|
||||
|
||||
return PJ_SUCCESS;
|
||||
}
|
||||
|
||||
static pj_status_t dmodem_get_frame(pjmedia_port *this_port, pjmedia_frame *frame) {
|
||||
struct dmodem *sm = (struct dmodem *)this_port;
|
||||
frame->size = PJMEDIA_PIA_AVG_FSZ(&this_port->info); // MAX? what is
|
||||
|
||||
int len;
|
||||
if ((len=read(sm->sock, frame->buf, frame->size)) != frame->size) {
|
||||
error_exit("error reading frame",0);
|
||||
}
|
||||
|
||||
frame->timestamp.u64 = sm->timestamp.u64;
|
||||
frame->type = PJMEDIA_FRAME_TYPE_AUDIO;
|
||||
sm->timestamp.u64 += PJMEDIA_PIA_SPF(&this_port->info);
|
||||
|
||||
return PJ_SUCCESS;
|
||||
}
|
||||
|
||||
static pj_status_t dmodem_on_destroy(pjmedia_port *this_port) {
|
||||
printf("destroy\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Callback called by the library when call's state has changed */
|
||||
static void on_call_state(pjsua_call_id call_id, pjsip_event *e) {
|
||||
pjsua_call_info ci;
|
||||
|
||||
PJ_UNUSED_ARG(e);
|
||||
|
||||
pjsua_call_get_info(call_id, &ci);
|
||||
PJ_LOG(3,(__FILE__, "Call %d state=%.*s", call_id,
|
||||
(int)ci.state_text.slen,
|
||||
ci.state_text.ptr));
|
||||
|
||||
if (ci.state == PJSIP_INV_STATE_DISCONNECTED) {
|
||||
close(port.sock);
|
||||
if (!destroying) {
|
||||
destroying = true;
|
||||
pjsua_destroy();
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Callback called by the library when call's media state has changed */
|
||||
static void on_call_media_state(pjsua_call_id call_id) {
|
||||
pjsua_call_info ci;
|
||||
pjsua_conf_port_id port_id;
|
||||
static int done=0;
|
||||
|
||||
pjsua_call_get_info(call_id, &ci);
|
||||
|
||||
// printf("media_status %d media_cnt %d ci.conf_slot %d aud.conf_slot %d\n",ci.media_status,ci.media_cnt,ci.conf_slot,ci.media[0].stream.aud.conf_slot);
|
||||
if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) {
|
||||
if (!done) {
|
||||
pjsua_conf_add_port(pool, &port.base, &port_id);
|
||||
pjsua_conf_connect(ci.conf_slot, port_id);
|
||||
pjsua_conf_connect(port_id, ci.conf_slot);
|
||||
done = 1;
|
||||
}
|
||||
} else {
|
||||
done = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
pjsua_acc_id acc_id;
|
||||
pj_status_t status;
|
||||
|
||||
if (argc != 3) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
signal(SIGPIPE,SIG_IGN);
|
||||
|
||||
char *dialstr = argv[1];
|
||||
|
||||
char *sip_user = getenv("SIP_LOGIN");
|
||||
if (!sip_user) {
|
||||
return -1;
|
||||
}
|
||||
char *sip_domain = strchr(sip_user,'@');
|
||||
if (!sip_domain) {
|
||||
return -1;
|
||||
}
|
||||
*sip_domain++ = '\0';
|
||||
char *sip_pass = strchr(sip_user,':');
|
||||
if (!sip_pass) {
|
||||
return -1;
|
||||
}
|
||||
*sip_pass++ = '\0';
|
||||
|
||||
status = pjsua_create();
|
||||
if (status != PJ_SUCCESS) error_exit("Error in pjsua_create()", status);
|
||||
|
||||
/* Init pjsua */
|
||||
{
|
||||
pjsua_config cfg;
|
||||
pjsua_logging_config log_cfg;
|
||||
pjsua_media_config med_cfg;
|
||||
|
||||
pjsua_config_default(&cfg);
|
||||
cfg.cb.on_call_media_state = &on_call_media_state;
|
||||
cfg.cb.on_call_state = &on_call_state;
|
||||
|
||||
pjsua_logging_config_default(&log_cfg);
|
||||
log_cfg.console_level = 4;
|
||||
|
||||
pjsua_media_config_default(&med_cfg);
|
||||
med_cfg.no_vad = true;
|
||||
med_cfg.ec_tail_len = 0;
|
||||
med_cfg.jb_max = 2000;
|
||||
// med_cfg.jb_init = 200;
|
||||
med_cfg.audio_frame_ptime = 5;
|
||||
|
||||
status = pjsua_init(&cfg, &log_cfg, &med_cfg);
|
||||
if (status != PJ_SUCCESS) error_exit("Error in pjsua_init()", status);
|
||||
}
|
||||
|
||||
pjsua_set_ec(0,0); // maybe?
|
||||
pjsua_set_null_snd_dev();
|
||||
|
||||
/* g711 only */
|
||||
pjsua_codec_info codecs[32];
|
||||
unsigned count = sizeof(codecs)/sizeof(*codecs);
|
||||
pjsua_enum_codecs(codecs,&count);
|
||||
for (int i=0; i<count; i++) {
|
||||
int pri = 0;
|
||||
if (pj_strcmp2(&codecs[i].codec_id,"PCMU/8000/1") == 0) {
|
||||
pri = 1;
|
||||
} else if (pj_strcmp2(&codecs[i].codec_id,"PCMA/8000/1") == 0) {
|
||||
pri = 2;
|
||||
}
|
||||
pjsua_codec_set_priority(&codecs[i].codec_id, pri);
|
||||
// printf("codec: %s %d\n",pj_strbuf(&codecs[i].codec_id),pri);
|
||||
}
|
||||
|
||||
/* Add UDP transport. */
|
||||
{
|
||||
pjsua_transport_config cfg;
|
||||
|
||||
pjsua_transport_config_default(&cfg);
|
||||
cfg.port = 5060;
|
||||
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
|
||||
if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
|
||||
}
|
||||
|
||||
pj_caching_pool cp;
|
||||
pj_caching_pool_init(&cp, NULL, 1024*1024);
|
||||
pool = pj_pool_create(&cp.factory, "pool1", 4000, 4000, NULL);
|
||||
|
||||
pj_str_t name = pj_str("dmodem");
|
||||
|
||||
memset(&port,0,sizeof(port));
|
||||
port.sock = atoi(argv[2]); // inherited from parent
|
||||
pjmedia_port_info_init(&port.base.info, &name, SIGNATURE, 9600, 1, 16, 192);
|
||||
port.base.put_frame = dmodem_put_frame;
|
||||
port.base.get_frame = dmodem_get_frame;
|
||||
port.base.on_destroy = dmodem_on_destroy;
|
||||
|
||||
char buf[384];
|
||||
memset(buf,0,sizeof(buf));
|
||||
write(port.sock, buf, sizeof(buf));
|
||||
|
||||
/* Initialization is done, now start pjsua */
|
||||
status = pjsua_start();
|
||||
if (status != PJ_SUCCESS) error_exit("Error starting pjsua", status);
|
||||
|
||||
{
|
||||
pjsua_acc_config cfg;
|
||||
pjsua_acc_config_default(&cfg);
|
||||
snprintf(buf,sizeof(buf),"sip:%s@%s",sip_user,sip_domain);
|
||||
pj_strdup2(pool,&cfg.id,buf);
|
||||
snprintf(buf,sizeof(buf),"sip:%s",sip_domain);
|
||||
pj_strdup2(pool,&cfg.reg_uri,buf);
|
||||
cfg.register_on_acc_add = false;
|
||||
cfg.cred_count = 1;
|
||||
cfg.cred_info[0].realm = pj_str("*");
|
||||
cfg.cred_info[0].scheme = pj_str("digest");
|
||||
cfg.cred_info[0].username = pj_str(sip_user);
|
||||
cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
|
||||
cfg.cred_info[0].data = pj_str(sip_pass);
|
||||
|
||||
status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id);
|
||||
if (status != PJ_SUCCESS) error_exit("Error adding account", status);
|
||||
}
|
||||
|
||||
snprintf(buf,sizeof(buf),"sip:%s@%s",dialstr,sip_domain);
|
||||
printf("calling %s\n",buf);
|
||||
pj_str_t uri = pj_str(buf);
|
||||
|
||||
pjsua_call_id callid;
|
||||
status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, &callid);
|
||||
if (status != PJ_SUCCESS) error_exit("Error making call", status);
|
||||
|
||||
struct timespec ts = {100, 0};
|
||||
while(1) {
|
||||
nanosleep(&ts,NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
1
pjproject
Submodule
1
pjproject
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 43c745789d291496fe1c3ed8a2c0dd6305260b32
|
34
slmodemd/COPYING
Normal file
34
slmodemd/COPYING
Normal file
|
@ -0,0 +1,34 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
92
slmodemd/Makefile
Normal file
92
slmodemd/Makefile
Normal file
|
@ -0,0 +1,92 @@
|
|||
###########################################################################
|
||||
#
|
||||
#
|
||||
# Makefile -- modem application Makefile.
|
||||
#
|
||||
# Copyright(c) 2003, Smart Link Ltd. (www.smlink.com)
|
||||
# All rights reserved.
|
||||
#
|
||||
# Author: Sasha K (sashak@smlink.com)
|
||||
#
|
||||
#
|
||||
###########################################################################
|
||||
#
|
||||
###########################################################################
|
||||
|
||||
ARCH64:=$(shell uname -m | sed -e '/amd64/s//x86_64/' | grep -c x86_64)
|
||||
|
||||
ifeq ($(ARCH64), 0)
|
||||
CC:= gcc
|
||||
else
|
||||
# SUPPORT_ALSA:=1
|
||||
CC:= gcc -m32
|
||||
endif
|
||||
|
||||
RM:= rm -f
|
||||
|
||||
CFLAGS+= -Wall -g -O -I. -DCONFIG_DEBUG_MODEM
|
||||
|
||||
modem-objs:= \
|
||||
modem.o modem_datafile.o modem_at.o modem_timer.o \
|
||||
modem_pack.o modem_ec.o modem_comp.o \
|
||||
modem_param.o modem_debug.o homolog_data.o
|
||||
dp-objs:= dp_sinus.o dp_dummy.o
|
||||
sysdep-objs:= sysdep_common.o
|
||||
all-objs:= modem_cmdline.o $(modem-objs) $(dp-objs) dsplibs.o $(sysdep-objs)
|
||||
|
||||
all: slmodemd modem_test
|
||||
|
||||
slmodemd: modem_main.o $(all-objs)
|
||||
modem_test: modem_test.o $(all-objs)
|
||||
|
||||
ifdef SUPPORT_ALSA
|
||||
CFLAGS+= -DSUPPORT_ALSA=1
|
||||
ifeq ($(ARCH64), 0)
|
||||
LFLAGS+= /usr/lib/libasound.so
|
||||
else
|
||||
# LFLAGS+= /usr/lib32/libasound.so , replaced by -l commands search for asound
|
||||
LFLAGS+= -lasound
|
||||
endif
|
||||
endif
|
||||
|
||||
slmodemd:
|
||||
$(CC) -o slmodemd modem_main.o $(all-objs) $(LFLAGS)
|
||||
|
||||
modem_test:
|
||||
$(CC) -o modem_test modem_test.o $(all-objs) $(LFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) slmodemd modem_test modem_main.o modem_cmdline.o modem_test.o $(modem-objs) $(dp-objs) $(sysdep-objs)
|
||||
$(RM) *~ *.orig *.rej
|
||||
|
||||
.PHONY: all dep generic-dep clean clean-build-profile
|
||||
|
||||
|
||||
#
|
||||
# rules
|
||||
#
|
||||
|
||||
%.o: %.c .build_profile
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -o $@ -c $<
|
||||
|
||||
dep: generic-dep
|
||||
generic-dep:
|
||||
$(RM) .depend
|
||||
$(foreach src,$(wildcard *.c),$(CC) -M $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(src:.c=.o)) -c $(src) >> .depend ;)
|
||||
|
||||
-include .depend
|
||||
|
||||
# build_profile
|
||||
-include .build_profile
|
||||
|
||||
.build_profile::
|
||||
ifneq ($(CFLAGS),$(PROFILE_CFLAGS))
|
||||
@if [ "$(CFLAGS) $(EXTRA_CFLAGS)" != "$(PROFILE_CFLAGS)" ] ; then \
|
||||
echo "rebuild profile..." ; \
|
||||
echo "PROFILE_CFLAGS=$(CFLAGS) $(EXTRA_CFLAGS)" > $(@) ; fi
|
||||
endif
|
||||
|
||||
clean: clean-build-profile
|
||||
clean-build-profile:
|
||||
@$(RM) -f .build_profile
|
||||
|
92
slmodemd/Makefile.20080401
Normal file
92
slmodemd/Makefile.20080401
Normal file
|
@ -0,0 +1,92 @@
|
|||
###########################################################################
|
||||
#
|
||||
#
|
||||
# Makefile -- modem application Makefile.
|
||||
#
|
||||
# Copyright(c) 2003, Smart Link Ltd. (www.smlink.com)
|
||||
# All rights reserved.
|
||||
#
|
||||
# Author: Sasha K (sashak@smlink.com)
|
||||
#
|
||||
#
|
||||
###########################################################################
|
||||
#
|
||||
###########################################################################
|
||||
|
||||
ARCH64:=$(shell uname -m | sed -e '/amd64/s//x86_64/' | grep -c x86_64)
|
||||
|
||||
ifeq ($(ARCH64), 0)
|
||||
CC:= gcc
|
||||
else
|
||||
# SUPPORT_ALSA:=1
|
||||
CC:= gcc -m32
|
||||
endif
|
||||
|
||||
RM:= rm -f
|
||||
|
||||
CFLAGS+= -Wall -g -O -I. -DCONFIG_DEBUG_MODEM
|
||||
|
||||
modem-objs:= \
|
||||
modem.o modem_datafile.o modem_at.o modem_timer.o \
|
||||
modem_pack.o modem_ec.o modem_comp.o \
|
||||
modem_param.o modem_debug.o homolog_data.o
|
||||
dp-objs:= dp_sinus.o dp_dummy.o
|
||||
sysdep-objs:= sysdep_common.o
|
||||
all-objs:= modem_cmdline.o $(modem-objs) $(dp-objs) dsplibs.o $(sysdep-objs)
|
||||
|
||||
all: slmodemd modem_test
|
||||
|
||||
slmodemd: modem_main.o $(all-objs)
|
||||
modem_test: modem_test.o $(all-objs)
|
||||
|
||||
ifdef SUPPORT_ALSA
|
||||
CFLAGS+= -DSUPPORT_ALSA=1
|
||||
ifeq ($(ARCH64), 0)
|
||||
LFLAGS+= /usr/lib/libasound.so
|
||||
else
|
||||
# LFLAGS+= /usr/lib32/libasound.so , replaced by -l commands search for asound
|
||||
LFLAGS+= -lasound
|
||||
endif
|
||||
endif
|
||||
|
||||
slmodemd:
|
||||
$(CC) -o slmodemd modem_main.o $(all-objs) $(LFLAGS)
|
||||
|
||||
modem_test:
|
||||
$(CC) -o modem_test modem_test.o $(all-objs) $(LFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) slmodemd modem_test modem_main.o modem_cmdline.o modem_test.o $(modem-objs) $(dp-objs) $(sysdep-objs)
|
||||
$(RM) *~ *.orig *.rej
|
||||
|
||||
.PHONY: all dep generic-dep clean clean-build-profile
|
||||
|
||||
|
||||
#
|
||||
# rules
|
||||
#
|
||||
|
||||
%.o: %.c .build_profile
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -o $@ -c $<
|
||||
|
||||
dep: generic-dep
|
||||
generic-dep:
|
||||
$(RM) .depend
|
||||
$(foreach src,$(wildcard *.c),$(CC) -M $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(src:.c=.o)) -c $(src) >> .depend ;)
|
||||
|
||||
-include .depend
|
||||
|
||||
# build_profile
|
||||
-include .build_profile
|
||||
|
||||
.build_profile::
|
||||
ifneq ($(CFLAGS),$(PROFILE_CFLAGS))
|
||||
@if [ "$(CFLAGS) $(EXTRA_CFLAGS)" != "$(PROFILE_CFLAGS)" ] ; then \
|
||||
echo "rebuild profile..." ; \
|
||||
echo "PROFILE_CFLAGS=$(CFLAGS) $(EXTRA_CFLAGS)" > $(@) ; fi
|
||||
endif
|
||||
|
||||
clean: clean-build-profile
|
||||
clean-build-profile:
|
||||
@$(RM) -f .build_profile
|
||||
|
153
slmodemd/dp_dummy.c
Normal file
153
slmodemd/dp_dummy.c
Normal file
|
@ -0,0 +1,153 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* dp_dummy.c -- dummy data pump (very stupid simulator).
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <modem.h>
|
||||
#include <modem_debug.h>
|
||||
|
||||
|
||||
#define DUMMY_SKIP 100
|
||||
#define DUMMY_TIMEOUT 300
|
||||
|
||||
#define DUMMY_A1 0xff
|
||||
|
||||
|
||||
struct dummy_dp {
|
||||
struct dp dp;
|
||||
unsigned long count;
|
||||
unsigned long linked;
|
||||
u8 buf[1024];
|
||||
void *dcr;
|
||||
};
|
||||
|
||||
static struct dp *dummy_create(struct modem *m, enum DP_ID id,
|
||||
int caller, int srate, int max_frag,
|
||||
struct dp_operations *op)
|
||||
{
|
||||
struct dummy_dp *d;
|
||||
dprintf("dummy_create...\n");
|
||||
d = malloc(sizeof(*d));
|
||||
memset(d,0,sizeof(*d));
|
||||
d->dp.id = id;
|
||||
d->dp.modem = m;
|
||||
d->dp.op = op;
|
||||
d->dp.dp_data = d;
|
||||
d->dcr = m->dcr;
|
||||
m->dcr = NULL;
|
||||
return (struct dp *)d;
|
||||
}
|
||||
|
||||
static int dummy_delete(struct dp *dp)
|
||||
{
|
||||
struct dummy_dp *d = (struct dummy_dp *)dp;
|
||||
dprintf("dummy_delete...\n");
|
||||
dp->modem->dcr = d->dcr;
|
||||
free(d);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dummy_process(struct dp *dp, void *in, void *out, int cnt)
|
||||
{
|
||||
struct dummy_dp *d = (struct dummy_dp *)dp;
|
||||
int n = cnt << MFMT_SHIFT(dp->modem->format);
|
||||
s16 *s;
|
||||
int i;
|
||||
d->count++;
|
||||
if (!d->linked) {
|
||||
if (d->count < DUMMY_SKIP) {
|
||||
memset(out,0,n);
|
||||
return DPSTAT_OK;
|
||||
}
|
||||
else if(d->count > DUMMY_TIMEOUT)
|
||||
return DPSTAT_ERROR;
|
||||
s = out;
|
||||
for(i = 0 ; i < cnt ; i++) {
|
||||
*s = (1-2*(i&1))*('A');
|
||||
s++;
|
||||
}
|
||||
s = in;
|
||||
for(i = 0 ; i < cnt ; i++) {
|
||||
if(abs(*s) == 'A') {
|
||||
d->linked = 1;
|
||||
return DPSTAT_CONNECT;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
s = in;
|
||||
for(i = 0 ; i < cnt ; i++) {
|
||||
d->buf[i] = *s&0x1;
|
||||
s++;
|
||||
}
|
||||
modem_put_bits(dp->modem,1,d->buf,cnt);
|
||||
s = out;
|
||||
modem_get_bits(dp->modem,1,d->buf,cnt);
|
||||
for(i = 0 ; i < cnt ; i++) {
|
||||
*s = d->buf[i]&1 ;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
return DPSTAT_OK;
|
||||
}
|
||||
|
||||
|
||||
static struct dp_operations dummy_operations = {
|
||||
name : "Dummy DataPump driver",
|
||||
create: dummy_create,
|
||||
delete: dummy_delete,
|
||||
process:dummy_process
|
||||
};
|
||||
|
||||
|
||||
|
||||
int dp_dummy_init(void)
|
||||
{
|
||||
return modem_dp_register(DP_DUMMY,&dummy_operations);
|
||||
}
|
||||
|
||||
void dp_dummy_exit(void)
|
||||
{
|
||||
modem_dp_deregister(DP_DUMMY,&dummy_operations);
|
||||
}
|
||||
|
||||
|
133
slmodemd/dp_sinus.c
Normal file
133
slmodemd/dp_sinus.c
Normal file
|
@ -0,0 +1,133 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* sinus.c -- sinus data pump.
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <modem.h>
|
||||
#include <modem_debug.h>
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#define malloc(size) kmalloc(size,GFP_KERNEL)
|
||||
#define free(mem) kfree(mem)
|
||||
#endif
|
||||
|
||||
#define SIN_AMPLITUDE 16384
|
||||
#define SIN_PERIOD (sizeof(sintab)/sizeof(sintab[0]))
|
||||
static
|
||||
const s16 sintab[] = {
|
||||
0, 3196, 6269, 9102, 11585, 13622, 15136, 16069,
|
||||
16384, 16069, 15136, 13622, 11585, 9102, 6269, 3196,
|
||||
0, -3196, -6269, -9102, -11585, -13622, -15136, -16069,
|
||||
-16384, -16069, -15136, -13622, -11585, -9102, -6269, -3196};
|
||||
|
||||
#define SIN_DBG(fmt,arg...) dprintf("sin: " fmt , ##arg)
|
||||
|
||||
struct sin_state {
|
||||
struct dp dp;
|
||||
int count;
|
||||
int linked;
|
||||
u8 buf[1024];
|
||||
int amp;
|
||||
unsigned period;
|
||||
unsigned phase;
|
||||
};
|
||||
|
||||
static struct dp *sin_create(struct modem *m, enum DP_ID id,
|
||||
int caller, int srate, int max_frag,
|
||||
struct dp_operations *op)
|
||||
{
|
||||
struct sin_state *s;
|
||||
SIN_DBG("create...\n");
|
||||
s = malloc(sizeof(*s));
|
||||
if (!s) return NULL;
|
||||
memset(s,0,sizeof(*s));
|
||||
s->dp.id = id;
|
||||
s->dp.modem = m;
|
||||
s->dp.op = op;
|
||||
s->dp.dp_data = s;
|
||||
s->phase = 0;
|
||||
s->amp = SIN_AMPLITUDE;
|
||||
s->period= SIN_PERIOD;
|
||||
return &s->dp;
|
||||
}
|
||||
|
||||
static int sin_delete(struct dp *dp)
|
||||
{
|
||||
struct sin_state *s = dp->dp_data;
|
||||
SIN_DBG("delete...\n");
|
||||
free(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sin_run(struct dp *dp, void *in, void *out, int cnt)
|
||||
{
|
||||
struct sin_state *s = dp->dp_data;
|
||||
s16 *smpl = out;
|
||||
int i;
|
||||
//SIN_DBG("run...\n");
|
||||
for (i=0;i<cnt;i++) {
|
||||
smpl[i] = sintab[s->phase%SIN_PERIOD];
|
||||
s->phase = s->phase+1;
|
||||
}
|
||||
return DPSTAT_OK;
|
||||
}
|
||||
|
||||
|
||||
static struct dp_operations sin_operations = {
|
||||
name : "Sinus DP driver",
|
||||
create: sin_create,
|
||||
delete: sin_delete,
|
||||
process:sin_run
|
||||
};
|
||||
|
||||
|
||||
|
||||
int dp_sinus_init(void)
|
||||
{
|
||||
return modem_dp_register(DP_SINUS,&sin_operations);
|
||||
}
|
||||
|
||||
void dp_sinus_exit(void)
|
||||
{
|
||||
modem_dp_deregister(DP_SINUS,&sin_operations);
|
||||
}
|
||||
|
||||
|
BIN
slmodemd/dsplibs.o
Normal file
BIN
slmodemd/dsplibs.o
Normal file
Binary file not shown.
131
slmodemd/homolog_data.c
Normal file
131
slmodemd/homolog_data.c
Normal file
|
@ -0,0 +1,131 @@
|
|||
/* generated at Jun 1 2004 19:11:22 */
|
||||
|
||||
#include <modem.h>
|
||||
#include <modem_homolog.h>
|
||||
|
||||
static const struct homolog_params params000 = {0x22,0x43,0x01,0x08,0x5a,0x28,0x3f,0x02,0x25,0x3f,0x00,0x1b,0x02,0x09,0x01,0x10,0x02,0x01,0x2b,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params001 = {0x24,0x40,0x01,0x06,0x64,0x12,0x3c,0x04,0x12,0x3c,0x00,0x32,0x02,0x0a,0x00,0x19,0x02,0x05,0x2b,0x00,0xff,0x06,0x50,0x02,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params002 = {0x21,0x43,0x01,0x08,0x5a,0x23,0x27,0x04,0x23,0x27,0x00,0x09,0x02,0x09,0x00,0x19,0x02,0x01,0x2b,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params003 = {0x28,0x3c,0x01,0x08,0x5a,0x00,0x00,0x02,0x00,0x00,0x00,0x09,0x04,0x09,0x01,0x08,0x02,0x06,0x2d,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params005 = {0x21,0x43,0x01,0x08,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x0c,0x04,0x09,0x01,0x07,0x02,0x04,0x2b,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params006 = {0x24,0x40,0x01,0x06,0x64,0x12,0x50,0x04,0x12,0x50,0x00,0x32,0x02,0x0a,0x00,0x19,0x02,0x05,0x2b,0x00,0xff,0x00,0x50,0x02,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params007 = {0x21,0x43,0x01,0x06,0x69,0x2a,0x50,0x04,0x2a,0x50,0x00,0x3c,0x02,0x0a,0x00,0x19,0x02,0x01,0x2b,0x00,0x1e,0x00,0x50,0x03,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params008 = {0x28,0x3c,0x01,0x08,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x07,0x04,0x09,0x00,0x02,0x02,0x03,0x2d,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params011 = {0x24,0x40,0x01,0x06,0x64,0x00,0x00,0x04,0x00,0x00,0x00,0x32,0x02,0x0a,0x00,0x19,0x02,0x01,0x2b,0x00,0x1e,0x00,0x50,0x02,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params012 = {0x21,0x43,0x01,0x08,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x07,0x04,0x09,0x00,0x02,0x02,0x03,0x2d,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params013 = {0x21,0x43,0x01,0x08,0x5a,0x2a,0x50,0x04,0x2a,0x50,0x00,0x07,0x04,0x09,0x00,0x02,0x02,0x03,0x2d,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params014 = {0x28,0x3c,0x01,0x06,0x5a,0x06,0x2a,0x08,0x0d,0x3c,0x01,0x0a,0x04,0x09,0x01,0x0e,0x02,0x00,0x22,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params015 = {0x24,0x40,0x01,0x08,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x09,0x02,0x09,0x01,0x19,0x02,0x00,0x26,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params016 = {0x21,0x43,0x01,0x09,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x07,0x04,0x09,0x00,0x02,0x02,0x03,0x2d,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params018 = {0x28,0x3c,0x01,0x08,0x5a,0x0a,0x42,0x04,0x0a,0x41,0x00,0x09,0x04,0x09,0x01,0x19,0x02,0x01,0x2b,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params020 = {0x29,0x3c,0x01,0x08,0x5a,0x0f,0x3c,0x04,0x23,0x3c,0x00,0x12,0x04,0x09,0x01,0x19,0x02,0x05,0x2b,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params022 = {0x24,0x40,0x01,0x06,0x64,0x00,0x00,0x04,0x00,0x00,0x00,0x32,0x02,0x0a,0x00,0x19,0x02,0x01,0x2b,0x00,0x1e,0x06,0x50,0x02,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params023 = {0x21,0x43,0x01,0x06,0x5a,0x0b,0x3c,0x02,0x0b,0x3c,0x00,0x09,0x04,0x09,0x01,0x08,0x02,0x06,0x2d,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params025 = {0x24,0x40,0x01,0x06,0x64,0x41,0x55,0x04,0x41,0x55,0x00,0x32,0x02,0x0a,0x00,0x19,0x02,0x01,0x2b,0x00,0x2e,0x00,0x50,0x02,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params027 = {0x22,0x43,0x01,0x08,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x07,0x04,0x09,0x00,0x19,0x02,0x02,0x2b,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params028 = {0x24,0x40,0x01,0x06,0x64,0x12,0x3c,0x04,0x12,0x3c,0x00,0x32,0x02,0x0a,0x00,0x19,0x02,0x05,0x2b,0x00,0xff,0x00,0x50,0x02,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params029 = {0x29,0x41,0x01,0x08,0x5a,0x00,0x00,0x02,0x00,0x00,0x00,0x0b,0x02,0x09,0x01,0x0f,0x02,0x04,0x28,0x00,0x1e,0x00,0x50,0x06,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params030 = {0x22,0x42,0x01,0x08,0x64,0x00,0x00,0x04,0x00,0x00,0x00,0x32,0x02,0x0e,0x00,0x19,0x02,0x01,0x2b,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params032 = {0x22,0x42,0x01,0x06,0x64,0x00,0x00,0x04,0x00,0x00,0x00,0x32,0x02,0x08,0x00,0x19,0x02,0x01,0x2b,0x00,0x1e,0x06,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params033 = {0x24,0x40,0x01,0x06,0x64,0x00,0x00,0x04,0x00,0x00,0x00,0x32,0x02,0x0a,0x00,0x19,0x02,0x00,0x2b,0x00,0xff,0x00,0x50,0x02,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params035 = {0x21,0x43,0x01,0x08,0x5a,0x21,0x30,0x04,0x0e,0x19,0x00,0x07,0x04,0x09,0x00,0x02,0x02,0x03,0x2d,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params036 = {0x28,0x3c,0x01,0x06,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x04,0x09,0x01,0x19,0x02,0x05,0x2b,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params038 = {0x21,0x43,0x01,0x06,0x64,0x00,0x00,0x04,0x00,0x00,0x00,0x32,0x02,0x0a,0x00,0x19,0x02,0x01,0x2b,0x00,0x1e,0x00,0x50,0x03,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params039 = {0x21,0x43,0x01,0x08,0x5a,0x21,0x3c,0x04,0x21,0x3c,0x00,0x07,0x04,0x09,0x00,0x02,0x02,0x03,0x2d,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params040 = {0x24,0x40,0x01,0x06,0x64,0x00,0x00,0x04,0x00,0x00,0x00,0x32,0x02,0x0a,0x00,0x19,0x02,0x01,0x2b,0x00,0x2e,0x00,0x50,0x02,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params041 = {0x21,0x43,0x01,0x06,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x07,0x04,0x09,0x00,0x02,0x02,0x03,0x2d,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params042 = {0x28,0x3c,0x01,0x08,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x0b,0x02,0x09,0x01,0x0f,0x02,0x07,0x20,0x00,0x1e,0x00,0x50,0x05,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params043 = {0x21,0x43,0x03,0x07,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x46,0x04,0x09,0x00,0x19,0x01,0x01,0x2b,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params044 = {0x24,0x40,0x01,0x08,0x5a,0x0a,0x42,0x02,0x0a,0x41,0x00,0x0a,0x04,0x09,0x01,0x0f,0x02,0x00,0x27,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params045 = {0x21,0x43,0x01,0x08,0x69,0x00,0x00,0x04,0x00,0x00,0x00,0x09,0x02,0x0a,0x00,0x19,0x02,0x01,0x2b,0x00,0x1e,0x00,0x50,0x03,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params049 = {0x21,0x43,0x01,0x06,0x5a,0x0b,0x3c,0x02,0x0b,0x3c,0x00,0x09,0x04,0x09,0x01,0x08,0x02,0x05,0x2d,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params050 = {0x21,0x43,0x01,0x08,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x14,0x02,0x09,0x01,0x19,0x02,0x03,0x23,0x01,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params051 = {0x28,0x3c,0x01,0x07,0x5a,0x0c,0x16,0x04,0x0c,0x16,0x00,0x12,0x04,0x09,0x01,0x19,0x02,0x05,0x2b,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params052 = {0x26,0x3e,0x01,0x04,0x69,0x22,0x2e,0x04,0x22,0x2e,0x00,0x09,0x02,0x0a,0x00,0x19,0x03,0x01,0x2b,0x00,0x1e,0x00,0x32,0x03,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params054 = {0x21,0x43,0x01,0x07,0x69,0x48,0x4e,0x04,0x48,0x4e,0x00,0x09,0x02,0x0a,0x00,0x19,0x02,0x01,0x2b,0x00,0x1e,0x00,0x50,0x03,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params055 = {0x28,0x3c,0x01,0x07,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x0a,0x04,0x09,0x01,0x19,0x02,0x05,0x2b,0x00,0x1e,0x00,0x55,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params056 = {0x28,0x3c,0x01,0x07,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x04,0x09,0x01,0x19,0x02,0x05,0x2b,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params057 = {0x28,0x3c,0x01,0x09,0x5a,0x2a,0x50,0x04,0x2a,0x50,0x00,0x07,0x04,0x09,0x00,0x02,0x02,0x03,0x2d,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params059 = {0x21,0x43,0x01,0x08,0x5a,0x05,0x3c,0x04,0x05,0x3c,0x00,0x0a,0x05,0x09,0x01,0x0c,0x02,0x05,0x29,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params061 = {0x28,0x3c,0x02,0x08,0x5a,0x14,0x1e,0x04,0x14,0x55,0x00,0x09,0x04,0x09,0x01,0x0f,0x02,0x00,0x1f,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params062 = {0x28,0x3c,0x01,0x08,0x5a,0x08,0x50,0x02,0x08,0x50,0x00,0x0c,0x04,0x09,0x01,0x0f,0x02,0x00,0x25,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x01,};
|
||||
static const struct homolog_params params063 = {0x21,0x43,0x01,0x06,0x64,0x14,0x3c,0x04,0x14,0x3c,0x00,0x32,0x02,0x0a,0x00,0x0a,0x02,0x01,0x2b,0x00,0x1e,0x06,0x50,0x03,0x00,0x00,0x00,0x012c,0x00,};
|
||||
static const struct homolog_params params064 = {0x28,0x3c,0x01,0x06,0x64,0x00,0x00,0x04,0x00,0x00,0x00,0x09,0x02,0x0a,0x00,0x19,0x02,0x01,0x23,0x00,0x1e,0x00,0x50,0x02,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params067 = {0x21,0x43,0x01,0x07,0x5a,0x00,0x00,0x04,0x00,0x00,0x00,0x07,0x04,0x09,0x00,0x02,0x02,0x03,0x2d,0x00,0x1e,0x00,0x15,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
static const struct homolog_params params068 = {0x22,0x48,0x01,0x08,0x5a,0x23,0x27,0x04,0x23,0x27,0x00,0x07,0x04,0x09,0x00,0x19,0x02,0x01,0x2b,0x00,0x1e,0x00,0x50,0x04,0x00,0x00,0x00,0x029a,0x00,};
|
||||
|
||||
const struct homolog_set homolog_set[] = {
|
||||
{0x0002,"ALGERIA",¶ms000},
|
||||
{0x0007,"ARGENTINA",¶ms001},
|
||||
{0x0009,"AUSTRALIA",¶ms002},
|
||||
{0x000a,"AUSTRIA",¶ms003},
|
||||
{0x000c,"BAHREIN",¶ms001},
|
||||
{0x000f,"BELGIUM",¶ms005},
|
||||
{0x0016,"BRAZIL",¶ms006},
|
||||
{0x001a,"BRUNEI",¶ms007},
|
||||
{0x001b,"BULGARIA",¶ms008},
|
||||
{0x0020,"CANADA",¶ms001},
|
||||
{0x0025,"CHILE",¶ms001},
|
||||
{0x0026,"CHINA",¶ms011},
|
||||
{0x0100,"CTR21EUROPE",¶ms012},
|
||||
{0x002d,"CYPRUS",¶ms013},
|
||||
{0x002e,"CZECH_REPUBLIC",¶ms014},
|
||||
{0x0031,"DENMARK",¶ms015},
|
||||
{0x0036,"EGYPT",¶ms016},
|
||||
{0x0101,"ESTONIA",¶ms012},
|
||||
{0x003c,"FINLAND",¶ms018},
|
||||
{0x003d,"FRANCE",¶ms000},
|
||||
{0x0042,"GERMANY",¶ms020},
|
||||
{0x0046,"GREECE",¶ms012},
|
||||
{0x0050,"HONG_KONG",¶ms022},
|
||||
{0x0051,"HUNGARY",¶ms023},
|
||||
{0x0052,"ICELAND",¶ms012},
|
||||
{0x0053,"INDIA",¶ms025},
|
||||
{0x0054,"INDONESIA",¶ms011},
|
||||
{0x0057,"IRELAND",¶ms027},
|
||||
{0x0058,"ISRAEL",¶ms028},
|
||||
{0x0059,"ITALY",¶ms029},
|
||||
{0x0000,"JAPAN",¶ms030},
|
||||
{0x005e,"JORDAN",¶ms013},
|
||||
{0x0061,"KOREA",¶ms032},
|
||||
{0x0062,"KUWAIT",¶ms033},
|
||||
{0x0103,"LATVIA",¶ms008},
|
||||
{0x0064,"LEBANON",¶ms035},
|
||||
{0x0104,"LITHUANIA",¶ms036},
|
||||
{0x0069,"LUXEMBOURG",¶ms012},
|
||||
{0x006c,"MALAYSIA",¶ms038},
|
||||
{0x0070,"MALTA",¶ms039},
|
||||
{0x0073,"MEXICO",¶ms040},
|
||||
{0x0077,"MOROCCO",¶ms041},
|
||||
{0x007b,"NETHERLANDS",¶ms042},
|
||||
{0x007e,"NEW_ZEALAND",¶ms043},
|
||||
{0x0082,"NORWAY",¶ms044},
|
||||
{0x0083,"OMAN",¶ms045},
|
||||
{0x0084,"PAKISTAN",¶ms040},
|
||||
{0x0088,"PERU",¶ms001},
|
||||
{0x0089,"PHILIPPINES",¶ms040},
|
||||
{0x008a,"POLAND",¶ms049},
|
||||
{0x008b,"PORTUGAL",¶ms050},
|
||||
{0x008e,"ROMANIA",¶ms051},
|
||||
{0x00b8,"RUSSIA",¶ms052},
|
||||
{0x0098,"SAUDIARABIA",¶ms001},
|
||||
{0x009c,"SINGAPORE",¶ms054},
|
||||
{0x00c5,"SLOVAKIA",¶ms055},
|
||||
{0x00c6,"SLOVENIA",¶ms056},
|
||||
{0x009f,"SOUTHAFRICA",¶ms057},
|
||||
{0x0107,"SOUTHKOREA",¶ms001},
|
||||
{0x00a0,"SPAIN",¶ms059},
|
||||
{0x00a1,"SRILANKA",¶ms054},
|
||||
{0x00a5,"SWEDEN",¶ms061},
|
||||
{0x00a6,"SWITZERLAND",¶ms062},
|
||||
{0x0108,"TAIWAN",¶ms063},
|
||||
{0x00a9,"THAILAND",¶ms064},
|
||||
{0x00ad,"TUNISIA",¶ms000},
|
||||
{0x00ae,"TURKEY",¶ms012},
|
||||
{0x00b3,"UAE",¶ms067},
|
||||
{0x00b4,"UK",¶ms068},
|
||||
{0x00b7,"URUGUAY",¶ms001},
|
||||
{0x00b5,"USA",¶ms001},
|
||||
{0x00bc,"VIETNAM",¶ms040},
|
||||
{}};
|
||||
|
1973
slmodemd/modem.c
Normal file
1973
slmodemd/modem.c
Normal file
File diff suppressed because it is too large
Load diff
460
slmodemd/modem.h
Normal file
460
slmodemd/modem.h
Normal file
|
@ -0,0 +1,460 @@
|
|||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem.h - modem definitions
|
||||
*
|
||||
* Author: sashak@smlink.com
|
||||
*/
|
||||
|
||||
#ifndef __MODEM_H__
|
||||
#define __MODEM_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include <modem_defs.h>
|
||||
#include <modem_homolog.h>
|
||||
#include <modem_dp.h>
|
||||
#include <modem_timer.h>
|
||||
|
||||
|
||||
/* modem modes */
|
||||
enum MODEM_MODE {
|
||||
MODEM_MODE_DATA = 0,
|
||||
MODEM_MODE_FAX = 1,
|
||||
MODEM_MODE_VOICE = 8
|
||||
};
|
||||
|
||||
|
||||
/* modem status */
|
||||
#define STATUS_OK 0x0
|
||||
#define STATUS_NOCARRIER 0x0002 // 3
|
||||
#define STATUS_ERROR 0x0004 // 4
|
||||
#define STATUS_NODIALTONE 0x0010 // 6
|
||||
#define STATUS_BUSY 0x0020 // 7
|
||||
#define STATUS_NOANSWER 0x0040 // 8
|
||||
#define STATUS_DP_LINK 0x0100 // 13
|
||||
#define STATUS_DP_ERROR 0x0200 // 14
|
||||
#define STATUS_PACK_LINK 0x0400 // 15
|
||||
#define STATUS_PACK_ERROR 0x0800 // 16
|
||||
#define STATUS_EC_LINK 0x1000 // 17
|
||||
#define STATUS_EC_RELEASE 0x2000 // 18
|
||||
#define STATUS_EC_ERROR 0x4000 // 19
|
||||
|
||||
|
||||
/*
|
||||
* parameters
|
||||
*
|
||||
*/
|
||||
|
||||
#define MODEM_FORMAT MFMT_S16_LE
|
||||
#define MODEM_RATE 9600 /* 8000 */
|
||||
#define MODEM_FRAG (MODEM_RATE/200)
|
||||
|
||||
|
||||
#define MODEM_MIN_RATE 300
|
||||
#define MODEM_MAX_RATE 56000
|
||||
|
||||
#define MODEM_DEFAULT_COUNTRY_CODE 0xb5 /* USA */
|
||||
|
||||
#define MODEM_CONFIG_CID 1
|
||||
#define MODEM_CONFIG_VOICE 1
|
||||
#define MODEM_CONFIG_FAX 1
|
||||
#define MODEM_CONFIG_FAX_CLASS1 1
|
||||
|
||||
#define MODEM_CONFIG_RING_DETECTOR 1
|
||||
|
||||
/*
|
||||
* type definitions
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* modem driver struct */
|
||||
struct modem_driver {
|
||||
const char *name;
|
||||
int (*start)(struct modem *m);
|
||||
int (*stop )(struct modem *m);
|
||||
int (*ioctl)(struct modem *m,unsigned cmd, unsigned long arg);
|
||||
};
|
||||
|
||||
/* modem data pumps driver struct */
|
||||
struct dp_driver {
|
||||
const enum DP_ID id;
|
||||
const char *name;
|
||||
const char *code;
|
||||
struct dp_operations *op;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* compressor definitions
|
||||
*
|
||||
*/
|
||||
|
||||
#define COMP_MAX_CODEWORDS 2048 /* dictionary size */
|
||||
#define COMP_MAX_STRING 34 /* max string length */
|
||||
|
||||
/* encoder and decoder states */
|
||||
struct comp_state {
|
||||
const char *name;
|
||||
enum COMP_MODE {TRANSPARENT,COMPRESSED} mode;
|
||||
int escape; /* escape state: decoder only */
|
||||
u16 update_at; /* update dict. at node */
|
||||
u16 next_free; /* next free dict entry */
|
||||
u16 last_matched; /* last matched dict entry */
|
||||
u16 last_added; /* last added dict entry */
|
||||
u16 cw_size; /* cw size */
|
||||
u16 threshold; /* cw size threshold */
|
||||
u8 escape_char; /* escape char value */
|
||||
int max_string; /* max string length */
|
||||
int dict_size; /* dictionary size */
|
||||
struct dict {
|
||||
u8 ch;
|
||||
u16 parent;
|
||||
u16 child;
|
||||
u16 next;
|
||||
} *dict; /* dictionary */
|
||||
/* fixme: union may be used? */
|
||||
int bit_len;
|
||||
u32 bit_data;
|
||||
int flushed_len; /* string length already sent */
|
||||
int str_len; /* string length */
|
||||
u8 str_data[COMP_MAX_STRING];
|
||||
/* test statistics info : encoder only */
|
||||
u16 cmp_last; /* compressed bits per last TEST_SLICE chars */
|
||||
u32 cmp_bits; /* total compressed bits */
|
||||
u32 raw_bits; /* total non-compressed bits */
|
||||
/* temporary */
|
||||
int olen;
|
||||
int ohead;
|
||||
char obuf[1024];
|
||||
};
|
||||
|
||||
|
||||
extern int modem_comp_init(struct modem *m);
|
||||
extern int modem_comp_config(struct modem *m, int dict_size, int max_str);
|
||||
extern void modem_comp_exit(struct modem *m);
|
||||
|
||||
extern int modem_comp_encode(struct modem *m, u8 ch, char *buf, int n);
|
||||
extern int modem_comp_decode(struct modem *m, u8 ch, char *buf, int n);
|
||||
extern int modem_comp_flush_encoder(struct modem *m, char *buf, int n);
|
||||
extern int modem_comp_flush_decoder(struct modem *m, char *buf, int n);
|
||||
|
||||
/*
|
||||
*
|
||||
* HDLC definitions
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct hdlc_frame {
|
||||
struct hdlc_frame *next;
|
||||
int count;
|
||||
int size;
|
||||
//u16 addr;
|
||||
//u16 ctrl;
|
||||
u16 fcs;
|
||||
u8 *buf;
|
||||
} frame_t;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* LAPM definitions
|
||||
*
|
||||
*/
|
||||
|
||||
#define LAPM_MAX_WIN_SIZE 15 /* max supported winsize */
|
||||
#define LAPM_MAX_INFO_SIZE 128 /* max supported infosize */
|
||||
|
||||
#define LAPM_INFO_FRAMES LAPM_MAX_WIN_SIZE + 1 /* number of info frames */
|
||||
#define LAPM_CTRL_FRAMES 8 /* number of ctrl frames */
|
||||
|
||||
/* lapm state */
|
||||
struct lapm_state {
|
||||
/* modem link */
|
||||
struct modem *modem;
|
||||
int state;
|
||||
/* sub-states: may be optimized */
|
||||
int config;
|
||||
/* those DATA sub-states may be optimized */
|
||||
int reject;
|
||||
int busy;
|
||||
int peer_busy;
|
||||
u8 cmd_addr;
|
||||
u8 rsp_addr;
|
||||
u8 vs;
|
||||
u8 va;
|
||||
u8 vr;
|
||||
int rtx_count; /* retransmission counter () */
|
||||
unsigned int tx_win_size;
|
||||
unsigned int rx_win_size;
|
||||
unsigned int tx_info_size;
|
||||
unsigned int rx_info_size;
|
||||
frame_t *sent_info;
|
||||
frame_t *tx_info;
|
||||
frame_t *info_list;
|
||||
frame_t *tx_ctrl;
|
||||
frame_t *ctrl_list;
|
||||
/* temporary: internal buffs */
|
||||
/* rx buf (used when enter busy state) */
|
||||
int rx_count;
|
||||
int rx_head;
|
||||
u8 rx_buf[LAPM_MAX_INFO_SIZE];
|
||||
/* temporary: frames bufs */
|
||||
struct {
|
||||
frame_t frame;
|
||||
u8 ctrl[4];
|
||||
u8 info[LAPM_MAX_INFO_SIZE];
|
||||
} info_buf[LAPM_INFO_FRAMES];
|
||||
struct {
|
||||
frame_t frame;
|
||||
u8 ctrl[4];
|
||||
u8 info[LAPM_MAX_INFO_SIZE];
|
||||
} ctrl_buf[LAPM_CTRL_FRAMES];
|
||||
/* temporary: debug counters: remove it */
|
||||
int info_count; // debug
|
||||
int tx_count; // debug
|
||||
int sent_count; // debug
|
||||
int ctrl_count; // debug
|
||||
};
|
||||
|
||||
|
||||
/* modem struct */
|
||||
struct modem {
|
||||
const char *name;
|
||||
int pty; /* pty descriptor */
|
||||
const char *dev_name, *pty_name; /* and names */
|
||||
struct termios termios;
|
||||
/* device driver */
|
||||
struct modem_driver driver;
|
||||
void *dev_data;
|
||||
/* modem states */
|
||||
unsigned modem_info;
|
||||
unsigned state;
|
||||
unsigned started;
|
||||
unsigned command;
|
||||
unsigned result_code;
|
||||
unsigned hook;
|
||||
unsigned caller;
|
||||
unsigned rx_rate;
|
||||
unsigned tx_rate;
|
||||
enum MODEM_MODE mode; /* data,fax,voice */
|
||||
/* modem events (ring,escape,waiting for connect,etc) */
|
||||
unsigned event;
|
||||
unsigned new_event;
|
||||
struct timer event_timer;
|
||||
/* modem parameters */
|
||||
unsigned min_rate;
|
||||
unsigned max_rate;
|
||||
unsigned char sregs[256]; /* s-registers */
|
||||
const struct homolog_set *homolog; /* homologation parameters */
|
||||
/* at processor */
|
||||
unsigned int at_count;
|
||||
char at_line[64];
|
||||
char at_cmd[64];
|
||||
/* ring detector */
|
||||
unsigned int ring_count;
|
||||
unsigned long ring_first;
|
||||
unsigned long ring_last;
|
||||
#ifdef MODEM_CONFIG_RING_DETECTOR
|
||||
void *rd_obj;
|
||||
#endif
|
||||
/* cid */
|
||||
#ifdef MODEM_CONFIG_CID
|
||||
unsigned cid_requested;
|
||||
void *cid;
|
||||
#endif
|
||||
/* dialer */
|
||||
char dial_string[128];
|
||||
/* escape counter */
|
||||
unsigned escape_count;
|
||||
unsigned long last_esc_check;
|
||||
/* xmit queue */
|
||||
struct xmit_queue {
|
||||
int count;
|
||||
unsigned int head;
|
||||
unsigned int tail;
|
||||
unsigned int size;
|
||||
unsigned char *buf;
|
||||
} xmit;
|
||||
/* run time configuration */
|
||||
struct modem_config {
|
||||
/* ec params */
|
||||
u8 ec;
|
||||
u8 ec_detector;
|
||||
u8 ec_tx_win_size;
|
||||
u8 ec_rx_win_size;
|
||||
u16 ec_tx_info_size;
|
||||
u16 ec_rx_info_size;
|
||||
/* compressor params */
|
||||
u8 comp;
|
||||
int comp_dict_size;
|
||||
int comp_max_string;
|
||||
} cfg;
|
||||
/* modem packer */
|
||||
int (*get_chars)(struct modem *m, char *buf, int n);
|
||||
int (*put_chars)(struct modem *m, const char *buf, int n);
|
||||
//int tx_window;
|
||||
//int rx_window;
|
||||
int bit_timer;
|
||||
void (*bit_timer_func)(struct modem *m);
|
||||
void (*packer_process)(struct modem *m, int bits);
|
||||
struct bits_state {
|
||||
int bit;
|
||||
u32 data;
|
||||
} pack,unpack;
|
||||
int (*get_bits)(struct modem *m, int nbits, u8 *buf, int n);
|
||||
int (*put_bits)(struct modem *m, int nbits, u8 *buf, int n);
|
||||
union packer_union {
|
||||
struct async_state {
|
||||
struct packer *packer;
|
||||
int data_bits;
|
||||
int stop_bits;
|
||||
int parity;
|
||||
int char_size;
|
||||
} async;
|
||||
struct detect_state {
|
||||
int tx_count;
|
||||
u8 tx_pattern[2];
|
||||
int rx_count;
|
||||
u8 rx_pattern[2];
|
||||
int ec_enable;
|
||||
} detector;
|
||||
struct hdlc_state {
|
||||
struct hdlc_frame *tx_frame;
|
||||
struct hdlc_frame *rx_frame;
|
||||
int rx_error;
|
||||
int rx_ones,tx_ones;
|
||||
/* framer interface */
|
||||
struct hdlc_frame *(*get_tx_frame)(void *framer);
|
||||
void (*tx_complete)(void *framer, frame_t *fr);
|
||||
void (*rx_complete)(void *framer, frame_t *fr);
|
||||
void *framer;
|
||||
/* temporary: internal bufs */
|
||||
struct hdlc_frame _rx_frame;
|
||||
u8 _rx_buf[512];
|
||||
} hdlc;
|
||||
} packer;
|
||||
/* error corrector */
|
||||
union {
|
||||
struct lapm_state lapm;
|
||||
} ec;
|
||||
/* compressor */
|
||||
struct comp_struct {
|
||||
// fixme: redo interface
|
||||
int head,count;
|
||||
char buf[256];
|
||||
struct comp_state encoder;
|
||||
struct comp_state decoder;
|
||||
} comp;
|
||||
/* modem data pump interface */
|
||||
unsigned srate;
|
||||
unsigned format;
|
||||
unsigned frag;
|
||||
unsigned dp_requested;
|
||||
unsigned automode_requested;
|
||||
int update_delay;
|
||||
void (*process)(struct modem *m,void *in,void *out,int cnt);
|
||||
/* process counter and sample timer */
|
||||
unsigned long count;
|
||||
unsigned long sample_timer;
|
||||
void (*sample_timer_func)(struct modem *);
|
||||
/* data pump */
|
||||
struct dp_operations **dp_ops;
|
||||
struct dp *dp;
|
||||
void *dp_runtime;
|
||||
/* dc evaluator and cleaner */
|
||||
void *dcr;
|
||||
/* dsp info data */
|
||||
struct dsp_info dsp_info;
|
||||
/* voice info */
|
||||
#ifdef MODEM_CONFIG_VOICE
|
||||
void *voice_obj;
|
||||
struct voice_info voice_info;
|
||||
#endif
|
||||
#ifdef MODEM_CONFIG_FAX
|
||||
void *fax_obj;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*
|
||||
*/
|
||||
|
||||
/* device driver --> modem */
|
||||
extern struct modem *modem_create(struct modem_driver *drv, const char *dev_name);
|
||||
extern void modem_delete(struct modem *m);
|
||||
extern int modem_write(struct modem *m, const char *buf, int n);
|
||||
extern void modem_hangup(struct modem *m);
|
||||
extern void modem_update_termios(struct modem *m, struct termios *tios);
|
||||
extern void modem_error (struct modem *m);
|
||||
extern void modem_ring (struct modem *m);
|
||||
extern void modem_event (struct modem *m);
|
||||
extern void modem_process(struct modem *m,void *in,void *out,int cnt);
|
||||
|
||||
/* packers && EC */ // FIXME: improve interface
|
||||
extern void modem_async_start(struct modem *m);
|
||||
extern int modem_async_get_bits(struct modem *m,int nbits,u8 *buf,int cnt);
|
||||
extern int modem_async_put_bits(struct modem *m,int nbits,u8 *buf,int cnt);
|
||||
extern void modem_detector_start(struct modem *m);
|
||||
extern int modem_detector_get_bits(struct modem *m,int nbits,u8 *buf,int cnt);
|
||||
extern int modem_detector_put_bits(struct modem *m,int nbits,u8 *buf,int cnt);
|
||||
extern void modem_hdlc_start(struct modem *m);
|
||||
extern int modem_hdlc_get_bits(struct modem *m,int nbits,u8 *buf,int cnt);
|
||||
extern int modem_hdlc_put_bits(struct modem *m,int nbits,u8 *buf,int cnt);
|
||||
|
||||
extern int modem_ec_init(struct modem *m);
|
||||
extern void modem_ec_exit(struct modem *m);
|
||||
extern void modem_ec_start(struct modem *m);
|
||||
extern void modem_ec_stop(struct modem *m);
|
||||
|
||||
/* status & config */
|
||||
extern void modem_update_status(struct modem *m, unsigned status);
|
||||
extern void modem_update_config(struct modem *m, struct modem_config *cfg);
|
||||
|
||||
/* modem parameters access macros */
|
||||
#define CRLF_CHARS(m) ((char *)((m)->sregs+SREG_CR_CHAR))
|
||||
#define MODEM_DP(m) ((m)->sregs[SREG_DP])
|
||||
#define MODEM_AUTOMODE(m) ((m)->sregs[SREG_AUTOMODE])
|
||||
|
||||
#endif /* __MODEM_H__ */
|
||||
|
1204
slmodemd/modem_at.c
Normal file
1204
slmodemd/modem_at.c
Normal file
File diff suppressed because it is too large
Load diff
296
slmodemd/modem_cmdline.c
Normal file
296
slmodemd/modem_cmdline.c
Normal file
|
@ -0,0 +1,296 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* Copyright (c) 2021, Aon plc
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_cmdline.c -- simple command line processor,
|
||||
* define config parameters.
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <modem.h>
|
||||
#include <modem_homolog.h>
|
||||
#include <modem_debug.h>
|
||||
|
||||
#define PR_INFO(fmt...) fprintf(stderr, fmt )
|
||||
|
||||
|
||||
/* global config data */
|
||||
|
||||
/* modem.c */
|
||||
extern const char *modem_default_country;
|
||||
|
||||
/* modem_debug.c */
|
||||
extern unsigned int modem_debug_level;
|
||||
extern unsigned int modem_debug_logging;
|
||||
|
||||
/* config parameters */
|
||||
const char *modem_dev_name = NULL;
|
||||
const char *modem_default_dev_name = "/dev/slamr0";
|
||||
const char *modem_alsa_dev_name = "modem:1";
|
||||
const char *modem_exec = NULL;
|
||||
unsigned int need_realtime = 1;
|
||||
#ifdef MODEM_CONFIG_RING_DETECTOR
|
||||
unsigned int ring_detector = 0;
|
||||
#endif
|
||||
unsigned int use_alsa = 0;
|
||||
const char *modem_group = "dialout";
|
||||
unsigned int use_short_buffer = 0;
|
||||
mode_t modem_perm = 0660;
|
||||
|
||||
|
||||
enum {
|
||||
OPT_HELP = 0,
|
||||
OPT_USAGE,
|
||||
OPT_VERSION,
|
||||
OPT_COUNTRY,
|
||||
OPT_COUNTRYLIST,
|
||||
OPT_ALSA,
|
||||
OPT_GROUP,
|
||||
OPT_PERM,
|
||||
#ifdef MODEM_CONFIG_RING_DETECTOR
|
||||
OPT_RINGDET,
|
||||
#endif
|
||||
OPT_USER,
|
||||
OPT_SHORTBUF,
|
||||
OPT_DEBUG,
|
||||
OPT_LOG,
|
||||
OPT_EXEC,
|
||||
OPT_LAST
|
||||
};
|
||||
|
||||
static struct opt {
|
||||
int ch;
|
||||
const char *name;
|
||||
const char *desc;
|
||||
enum {NONE=0,MANDATORY,OPTIONAL} arg;
|
||||
enum {INTEGER,STRING} arg_type;
|
||||
const char *arg_val;
|
||||
unsigned found;
|
||||
} opt_list[] = {
|
||||
{'h',"help","this usage"},
|
||||
{'u',"usage","this usage"},
|
||||
{'v',"version","show version and exit"},
|
||||
{'c',"country","default modem country name",MANDATORY,STRING,"USA"},
|
||||
{ 0 ,"countrylist","show list of supported countries"},
|
||||
{'a',"alsa","ALSA mode (see README for howto)"},
|
||||
{'g',"group","Modem TTY group",MANDATORY,STRING,"dialout"},
|
||||
{'p',"perm","Modem TTY permission",MANDATORY,INTEGER,"0660"},
|
||||
#ifdef MODEM_CONFIG_RING_DETECTOR
|
||||
{'r',"ringdetector","with internal ring detector (software)"},
|
||||
#endif
|
||||
{'n',"nortpriority","run with regular priority"},
|
||||
{'s',"shortbuffer","use short buffer (4 periods length)"},
|
||||
{'d',"debug","debug level (developers only, for ./sl...)",OPTIONAL,INTEGER,"0"},
|
||||
{'l',"log","logging mode",OPTIONAL,INTEGER,"5"},
|
||||
{'e',"exec","path to external application that transmits audio over the socket (required)"},
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void usage(const char *prog_name)
|
||||
{
|
||||
struct opt *opt;
|
||||
PR_INFO("Usage: %s [option...] <device>\n"
|
||||
"Where 'device' is name of modem device (default `%s')\n"
|
||||
" and 'option' may be:\n", prog_name, modem_default_dev_name);
|
||||
for (opt = opt_list ; opt->name ; opt++ ) {
|
||||
int n = 0;
|
||||
if(opt->ch)
|
||||
n = PR_INFO(" -%c, ",opt->ch);
|
||||
else
|
||||
n = PR_INFO(" ");
|
||||
n += PR_INFO("--%s%s ",opt->name,opt->arg?"=VAL":"");
|
||||
n += PR_INFO("%*s%s",24-n,"",opt->desc);
|
||||
if(opt->arg) {
|
||||
n+= PR_INFO(" (default `%s')",opt->arg_val);
|
||||
}
|
||||
PR_INFO("\n");
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
static void opt_parse(int argc, char *argv[])
|
||||
{
|
||||
const char *prog_name;
|
||||
const char *dev_name = NULL;
|
||||
struct opt *opt;
|
||||
char *p, *arg;
|
||||
int found, i;
|
||||
|
||||
prog_name = argv[0];
|
||||
|
||||
for( i = 1 ; i < argc ; i++ ) {
|
||||
p = argv[i];
|
||||
if(*p != '-') {
|
||||
if(dev_name)
|
||||
usage(prog_name);
|
||||
dev_name = p;
|
||||
continue;
|
||||
}
|
||||
found = 0;
|
||||
arg = NULL;
|
||||
do { p++; } while( *p == '-' );
|
||||
for (opt = opt_list ; opt->name ; opt++ ) {
|
||||
if(!strncmp(p,opt->name,strlen(opt->name)) ||
|
||||
(opt->ch && *p == opt->ch) ) {
|
||||
char *q;
|
||||
if(!strncmp(p,opt->name,strlen(opt->name)))
|
||||
q = p + strlen(opt->name);
|
||||
else
|
||||
q = p + 1;
|
||||
if( *q == '\0' )
|
||||
found = 1;
|
||||
else if (*q == '=' && opt->arg ) {
|
||||
arg = q + 1;
|
||||
found = 1;
|
||||
}
|
||||
else if(isdigit(*q) && opt->arg ) {
|
||||
arg = q;
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !found )
|
||||
continue;
|
||||
if ( arg && !opt->arg )
|
||||
usage(prog_name);
|
||||
|
||||
if (!arg && opt->arg &&
|
||||
(i < argc - 1 && *argv[i+1] != '-') &&
|
||||
(!opt->arg_type == INTEGER || isdigit(*argv[i+1])))
|
||||
arg = argv[++i];
|
||||
|
||||
if(!arg && opt->arg == MANDATORY)
|
||||
usage(prog_name);
|
||||
|
||||
opt->found++;
|
||||
if(opt->arg && arg)
|
||||
opt->arg_val = arg;
|
||||
break;
|
||||
}
|
||||
if(!found)
|
||||
usage(prog_name);
|
||||
}
|
||||
|
||||
if(dev_name)
|
||||
modem_dev_name = dev_name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void modem_cmdline(int argc, char *argv[])
|
||||
{
|
||||
const char *prog_name = argv[0];
|
||||
int val;
|
||||
|
||||
opt_parse(argc,argv);
|
||||
|
||||
if(opt_list[OPT_HELP].found ||
|
||||
opt_list[OPT_USAGE].found )
|
||||
usage(prog_name);
|
||||
|
||||
if(opt_list[OPT_VERSION].found) {
|
||||
extern void modem_print_version();
|
||||
modem_print_version();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if(opt_list[OPT_COUNTRYLIST].found) {
|
||||
const struct homolog_set *s ;
|
||||
for( s = homolog_set; s->name ; s++ ) {
|
||||
PR_INFO("%02x: %s\n",s->id,s->name);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
if(opt_list[OPT_COUNTRY].found)
|
||||
modem_default_country = opt_list[OPT_COUNTRY].arg_val;
|
||||
if(opt_list[OPT_ALSA].found) {
|
||||
#ifndef SUPPORT_ALSA
|
||||
PR_INFO("ALSA support is not compiled in (see README for howto).\n");
|
||||
exit(1);
|
||||
#endif
|
||||
use_alsa = 1;
|
||||
}
|
||||
if(opt_list[OPT_GROUP].found)
|
||||
modem_group = opt_list[OPT_GROUP].arg_val;
|
||||
if(opt_list[OPT_PERM].found) {
|
||||
val = strtol(opt_list[OPT_PERM].arg_val,NULL,8);
|
||||
if (val <= 0)
|
||||
usage(prog_name);
|
||||
modem_perm = val;
|
||||
}
|
||||
#ifdef MODEM_CONFIG_RING_DETECTOR
|
||||
if(opt_list[OPT_RINGDET].found)
|
||||
ring_detector = 1;
|
||||
#endif
|
||||
if(opt_list[OPT_USER].found)
|
||||
need_realtime = 0;
|
||||
if(opt_list[OPT_SHORTBUF].found)
|
||||
use_short_buffer = 1;
|
||||
if(opt_list[OPT_DEBUG].found) {
|
||||
modem_debug_level = 1 ;
|
||||
if(opt_list[OPT_DEBUG].arg_val &&
|
||||
(val= strtol(opt_list[OPT_DEBUG].arg_val,NULL,0)) > 0 )
|
||||
modem_debug_level = val;
|
||||
}
|
||||
if(opt_list[OPT_LOG].found) {
|
||||
modem_debug_logging = 5;
|
||||
if(opt_list[OPT_LOG].arg_val &&
|
||||
(val= strtol(opt_list[OPT_LOG].arg_val,NULL,0)) > 0 )
|
||||
modem_debug_logging = val;
|
||||
}
|
||||
if(opt_list[OPT_EXEC].found) {
|
||||
modem_exec = opt_list[OPT_EXEC].arg_val;
|
||||
} else {
|
||||
usage(prog_name);
|
||||
}
|
||||
if(!modem_dev_name) {
|
||||
modem_dev_name = use_alsa ? modem_alsa_dev_name : modem_default_dev_name;
|
||||
}
|
||||
}
|
||||
|
887
slmodemd/modem_comp.c
Normal file
887
slmodemd/modem_comp.c
Normal file
|
@ -0,0 +1,887 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_comp.c -- modem compressor module.
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <modem.h>
|
||||
#include <modem_debug.h>
|
||||
|
||||
|
||||
/*
|
||||
* TODO list:
|
||||
* - modify interface: clean temporary out buffs
|
||||
* - char char encoding/decoding
|
||||
* - simplify and clean code:
|
||||
* - decoder
|
||||
* - encoder test compression case, do it after string finishing
|
||||
* - preformance trace and optimize
|
||||
*
|
||||
*/
|
||||
|
||||
//#define COMP_TEST 1
|
||||
//#define COMP_DEBUG 1
|
||||
|
||||
/* V42bis parameters limitation */
|
||||
#define MIN_DICT_SIZE 512 /* min dictionary size enabled by protocol */
|
||||
#define MIN_STR_SIZE 6 /* min string size enabled by protocol */
|
||||
#define MAX_STR_SIZE 250 /* max string size enabled by protocol */
|
||||
|
||||
/* V42bis constants */
|
||||
#define CHAR_SIZE 8 /* char size (bits) N3 */
|
||||
#define TOTAL_CHARS 256 /* number of chars N4 */
|
||||
#define TOTAL_CTRLS 3 /* number of control cw N6 */
|
||||
#define FIRST_ENTRY TOTAL_CTRLS /* first dictionary entry */
|
||||
#define FIRST_FREE TOTAL_CHARS+FIRST_ENTRY /* initial val of free entry N5 */
|
||||
|
||||
/* control codewords */
|
||||
#define CCW_ETM 0 /* Enter transparent mode */
|
||||
#define CCW_FLUSH 1 /* Flash data */
|
||||
#define CCW_STEPUP 2 /* Step up codeword size */
|
||||
/* command codes */
|
||||
#define CC_ECM 0 /* Enter compression mode */
|
||||
#define CC_EID 1 /* Escape charactrer in data */
|
||||
#define CC_RESET 2 /* Force reinitialization */
|
||||
|
||||
#define ESCAPE_STEP 51 /* escape char value step */
|
||||
#define TEST_SLICE 256 /* compression test slice (bytes) */
|
||||
|
||||
|
||||
/* fixme: use get pages */
|
||||
#define COMP_ALLOC(size) malloc(size)
|
||||
#define COMP_FREE(mem) free(mem)
|
||||
|
||||
/* debug stuff */
|
||||
#if COMP_DEBUG
|
||||
#define INLINE_FUNC static
|
||||
#define COMP_DBG(fmt,arg...) dprintf("comp %d/%d: " fmt , \
|
||||
c->cmp_bits , c->raw_bits , ##arg)
|
||||
#if 1
|
||||
#define COMP_DBG1(fmt,arg...)
|
||||
#else
|
||||
#define COMP_DBG1(fmt,arg...) COMP_DBG(fmt , ##arg)
|
||||
static char *show_string(struct comp_state *c, u16 cw)
|
||||
{
|
||||
static char _str[COMP_MAX_STRING+1];
|
||||
int j;
|
||||
_str[COMP_MAX_STRING] = 0;
|
||||
for(j = COMP_MAX_STRING-1; cw && j >= 0 ; j--) {
|
||||
_str[j] = c->dict[cw].ch;
|
||||
cw = c->dict[cw].parent;
|
||||
}
|
||||
return _str+j+1;
|
||||
}
|
||||
#endif // 0
|
||||
#else /* !COMP_DEBUG */
|
||||
#define INLINE_FUNC extern inline
|
||||
#define COMP_DBG(fmt,arg...)
|
||||
#define COMP_DBG1(fmt,arg...)
|
||||
#endif /* !COMP_DEBUG */
|
||||
|
||||
#define COMP_ERR(fmt,arg...) eprintf("err: " fmt , ##arg)
|
||||
|
||||
|
||||
/*
|
||||
* common procedures
|
||||
*
|
||||
*/
|
||||
|
||||
/* initialize dictionary and params */
|
||||
static void dict_init(struct comp_state *c)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<c->dict_size;i++) {
|
||||
c->dict[i].parent = 0;
|
||||
c->dict[i].child = 0;
|
||||
c->dict[i].next = 0;
|
||||
}
|
||||
c->next_free = FIRST_FREE;
|
||||
c->last_matched = 0;
|
||||
c->update_at = 0;
|
||||
c->last_added = 0;
|
||||
c->cw_size = CHAR_SIZE + 1;
|
||||
c->threshold = TOTAL_CHARS<<1;
|
||||
c->bit_len = 0;
|
||||
c->flushed_len = 0;
|
||||
c->str_len = 0;
|
||||
c->escape_char = 0;
|
||||
c->cmp_last = TEST_SLICE<<3;
|
||||
c->mode = TRANSPARENT;
|
||||
c->escape = 0;
|
||||
}
|
||||
|
||||
/* match one char */
|
||||
INLINE_FUNC u16 match_char(struct comp_state *c, u16 at, u8 ch)
|
||||
{
|
||||
register u16 e;
|
||||
if (!at)
|
||||
return ch + FIRST_ENTRY;
|
||||
e = c->dict[at].child;
|
||||
while(e) {
|
||||
if (c->dict[e].ch == ch)
|
||||
return e;
|
||||
e = c->dict[e].next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* add one char */
|
||||
INLINE_FUNC u16 add_char(struct comp_state *c, u16 at, u8 ch)
|
||||
{
|
||||
register u16 new = c->next_free;
|
||||
register u16 next;
|
||||
/* add */
|
||||
c->dict[new].ch = ch;
|
||||
c->dict[new].parent = at;
|
||||
c->dict[new].child = 0;
|
||||
c->dict[new].next = c->dict[at].child;
|
||||
c->dict[at].child = new;
|
||||
/* update next free */;
|
||||
next = new;
|
||||
do {
|
||||
if (++next == c->dict_size)
|
||||
next = FIRST_FREE;
|
||||
} while(c->dict[next].child);
|
||||
if (c->dict[next].parent) {
|
||||
u16 e = c->dict[next].parent;
|
||||
if(c->dict[e].child == next)
|
||||
c->dict[e].child = c->dict[next].next;
|
||||
else {
|
||||
e = c->dict[e].child;
|
||||
while(c->dict[e].next != next)
|
||||
e = c->dict[e].next;
|
||||
c->dict[e].next = c->dict[next].next;
|
||||
}
|
||||
}
|
||||
c->next_free = next;
|
||||
return new;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* decoder
|
||||
*
|
||||
*/
|
||||
|
||||
/* out decoded string */
|
||||
INLINE_FUNC int send_string(struct comp_state *c)
|
||||
{
|
||||
int ret;
|
||||
#if 0
|
||||
c->str_data[c->str_len] = 0;
|
||||
COMP_DBG("out string %d: '%s'\n",c->last_matched,c->str_data);
|
||||
#endif
|
||||
memcpy(c->obuf+c->olen,c->str_data,c->str_len);
|
||||
ret = c->str_len;
|
||||
c->olen += ret;
|
||||
c->str_len = 0;
|
||||
c->flushed_len = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* receive encoded data */
|
||||
INLINE_FUNC int recv_data(struct comp_state *c, u16 cw)
|
||||
{
|
||||
int i,ret = 0;
|
||||
u16 p = cw;
|
||||
COMP_DBG1("dec recv %d: '%s'\n",cw,show_string(c,cw));
|
||||
for (ret = 0 ; p ; ret++) {
|
||||
p = c->dict[p].parent;
|
||||
}
|
||||
p = cw;
|
||||
i = c->str_len + ret - 1;
|
||||
while(p) {
|
||||
c->str_data[i--] = c->dict[p].ch;
|
||||
p = c->dict[p].parent;
|
||||
}
|
||||
c->str_len += ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* flush decoder */
|
||||
int comp_flush_decoder(struct comp_state *c)
|
||||
{
|
||||
int ret, total_len;
|
||||
total_len = c->flushed_len + c->str_len;
|
||||
ret = send_string(c);
|
||||
c->flushed_len = total_len;
|
||||
if (ret) {
|
||||
COMP_DBG("flush_decoder: %d...\n", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* decoder */
|
||||
int comp_decode(struct comp_state *c, u8 *in, int n)
|
||||
{
|
||||
register int i, ret = 0;
|
||||
register u16 cw, p;
|
||||
u8 ch;
|
||||
for (i = 0 ; i<n ;) {
|
||||
switch (c->mode) {
|
||||
case COMPRESSED:
|
||||
/* get cw from input */
|
||||
while (c->bit_len < c->cw_size && i<n) {
|
||||
c->bit_data |= *in++ << c->bit_len;
|
||||
c->bit_len += 8;
|
||||
i++;
|
||||
}
|
||||
if (c->bit_len < c->cw_size)
|
||||
break;
|
||||
|
||||
cw = c->bit_data&((1<<c->cw_size)-1);
|
||||
c->bit_data >>= c->cw_size;
|
||||
c->bit_len -= c->cw_size;
|
||||
|
||||
/* process cw */
|
||||
switch (cw) {
|
||||
/* control cw */
|
||||
case CCW_ETM: /* enter transparent mode */
|
||||
COMP_DBG("C decoder: ETM\n");
|
||||
c->bit_len = 0;
|
||||
c->mode = TRANSPARENT;
|
||||
c->last_matched = 0;
|
||||
c->last_added = 0;
|
||||
break;
|
||||
case CCW_FLUSH: /* flush signal */
|
||||
COMP_DBG("C decoder: FLUSH\n");
|
||||
c->bit_len = 0;
|
||||
break;
|
||||
case CCW_STEPUP: /* increase cw size */
|
||||
c->cw_size++;
|
||||
c->threshold <<= 1;
|
||||
COMP_DBG("C decoder: STEPUP %d\n", c->cw_size);
|
||||
if (c->cw_size > (c->dict_size>>3)) { /* C-ERROR */
|
||||
COMP_ERR("fatal: cw size too big!\n");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default: /* regular codeword */
|
||||
if (cw == c->next_free) { /* C-ERROR */
|
||||
COMP_ERR("fatal: next free!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret += recv_data(c,cw);
|
||||
if (c->update_at) {
|
||||
ch = c->str_data[0];
|
||||
p = match_char(c,c->update_at,ch);
|
||||
if (!p) {
|
||||
// fixme: prevent case add 303 at 303
|
||||
c->last_added = add_char(c,c->update_at,ch);
|
||||
COMP_DBG1("C dec add %d at %d: %d(%c) '%s'\n",
|
||||
c->last_added,c->update_at,
|
||||
ch,ch,show_string(c,c->last_added));
|
||||
if (cw == c->next_free) { /* C-ERROR */
|
||||
COMP_ERR("fatal: empty cw!\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (p == c->last_added)
|
||||
c->last_added = 0;
|
||||
}
|
||||
if (c->str_len + c->flushed_len == c->max_string) {
|
||||
c->update_at = 0;
|
||||
}
|
||||
else {
|
||||
c->update_at = cw;
|
||||
}
|
||||
/* process escape */
|
||||
// fixme: separate it in func (send_string ?)
|
||||
{ int j;
|
||||
for (j=0;j<c->str_len;j++) {
|
||||
if(c->str_data[j]==c->escape_char) {
|
||||
COMP_DBG("C dec: ESCAPE %d\n", c->escape_char);
|
||||
c->escape_char+=ESCAPE_STEP;
|
||||
}
|
||||
}
|
||||
}
|
||||
send_string(c);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TRANSPARENT:
|
||||
if (c->escape) { /* command */
|
||||
c->escape = 0;
|
||||
switch(*in) {
|
||||
case CC_ECM: /* enter compressed mode */
|
||||
COMP_DBG("T decoder: ECM\n");
|
||||
ret += send_string(c);
|
||||
c->mode = COMPRESSED;
|
||||
c->update_at = c->last_matched;
|
||||
c->last_matched = 0;
|
||||
in++;i++;
|
||||
continue;
|
||||
//break;
|
||||
case CC_EID: /* escape symbol */
|
||||
COMP_DBG("T decoder: EID\n");
|
||||
// fixme: don't rewrite in buf
|
||||
*in = c->escape_char;
|
||||
c->escape_char += ESCAPE_STEP;
|
||||
break;
|
||||
case CC_RESET: /* reset dict */
|
||||
COMP_DBG("T decoder: RESET\n");
|
||||
// TBD
|
||||
ret += send_string(c);
|
||||
dict_init(c);
|
||||
in++;i++;
|
||||
continue;
|
||||
//break;
|
||||
default: /* C-ERROR */
|
||||
COMP_ERR("fatal: invalid cmd!\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (*in == c->escape_char) {
|
||||
COMP_DBG("T dec ESCAPE %d\n", *in);
|
||||
c->escape = 1;
|
||||
in++; i++;
|
||||
break;
|
||||
}
|
||||
|
||||
//COMP_DBG1("dec rcv: %d(%c)\n", *in, *in);
|
||||
|
||||
if (c->update_at) {
|
||||
if(!match_char(c,c->update_at,*in)) {
|
||||
c->last_added = add_char(c,c->update_at,*in);
|
||||
COMP_DBG1("T dec add %d at %d: %d(%c) '%s'\n",
|
||||
c->last_added,c->update_at,
|
||||
*in,*in,show_string(c,c->last_added));
|
||||
}
|
||||
c->update_at = 0;
|
||||
}
|
||||
|
||||
cw = match_char(c,c->last_matched,*in);
|
||||
if(!cw) {
|
||||
c->update_at = c->last_matched;
|
||||
/* out string */
|
||||
ret += send_string(c);
|
||||
c->last_matched = 0;
|
||||
}
|
||||
else if (cw == c->last_added) {
|
||||
c->last_added = 0;
|
||||
/* out string */
|
||||
ret += send_string(c);
|
||||
c->last_matched = 0;
|
||||
}
|
||||
else {
|
||||
c->last_matched = cw;
|
||||
c->str_data[c->str_len++] = *in++;
|
||||
if (c->str_len + c->flushed_len == c->max_string) {
|
||||
/* out string */
|
||||
ret += send_string(c);
|
||||
c->last_matched = 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* encoder
|
||||
*
|
||||
*/
|
||||
|
||||
#define SEND_CW(c,cw) { (c)->bit_data |= (cw) << (c)->bit_len; \
|
||||
(c)->bit_len += (c)->cw_size; }
|
||||
#define ALIGN_BITS(c) { if((c)->bit_len%8) \
|
||||
(c)->bit_len += 8 - (c)->bit_len%8; }
|
||||
#define SEND_BITS(c) { while((c)->bit_len >= 8) { \
|
||||
(c)->obuf[c->olen++]=(c)->bit_data&0xff; \
|
||||
(c)->bit_data >>= 8; \
|
||||
(c)->bit_len -= 8; ret++; \
|
||||
} }
|
||||
|
||||
|
||||
|
||||
/* send encoded data */
|
||||
static int send_data(struct comp_state *c, u16 cw)
|
||||
{
|
||||
register int i, ret = 0;
|
||||
|
||||
/* update test info */
|
||||
c->raw_bits += c->str_len<<3;
|
||||
c->cmp_bits += c->cw_size;
|
||||
c->cmp_last += c->cw_size - c->cmp_last*c->str_len/TEST_SLICE;
|
||||
|
||||
switch(c->mode) {
|
||||
case TRANSPARENT:
|
||||
for (i = 0;i<c->str_len;i++) {
|
||||
c->obuf[c->olen++] = c->str_data[i];
|
||||
ret++;
|
||||
if (c->str_data[i] == c->escape_char) {
|
||||
COMP_DBG("T enc ESCAPE %d\n", c->escape_char);
|
||||
c->obuf[c->olen++] = CC_EID;
|
||||
ret++;
|
||||
c->escape_char += ESCAPE_STEP;
|
||||
}
|
||||
COMP_DBG1("enc send: %d(%c)\n",c->str_data[i],c->str_data[i]);
|
||||
}
|
||||
break;
|
||||
case COMPRESSED:
|
||||
/* process escape */
|
||||
for (i = 0;i<c->str_len;i++) {
|
||||
if (c->str_data[i] == c->escape_char) {
|
||||
COMP_DBG("C enc ESCAPE %d\n", c->escape_char);
|
||||
c->escape_char += ESCAPE_STEP;
|
||||
}
|
||||
}
|
||||
/* send codeword */
|
||||
/* check cw size and send STEPUP if need */
|
||||
while (cw >= c->threshold) {
|
||||
SEND_CW(c,CCW_STEPUP);
|
||||
SEND_BITS(c);
|
||||
c->threshold <<= 1;
|
||||
c->cw_size++;
|
||||
COMP_DBG("C enc STEPUP %d\n",c->cw_size);
|
||||
}
|
||||
SEND_CW(c,cw);
|
||||
SEND_BITS(c);
|
||||
COMP_DBG1("enc send %d: '%s'\n",cw,show_string(c,cw));
|
||||
break;
|
||||
}
|
||||
c->str_len = 0;
|
||||
c->flushed_len = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* test compression */
|
||||
static int test_mode(struct comp_state *c)
|
||||
{
|
||||
int ret = 0;
|
||||
switch(c->mode) {
|
||||
case TRANSPARENT:
|
||||
/* fixme: why 11 ? */
|
||||
if (c->cmp_last < (TEST_SLICE<<3) - 11) {
|
||||
/* switch to compressed mode */
|
||||
COMP_DBG("encoder %d/%d %d: --> COMPRESSED mode.\n",
|
||||
c->cmp_bits,c->raw_bits,c->cmp_last);
|
||||
if (c->last_matched) {
|
||||
c->update_at = c->last_matched;
|
||||
ret += send_data(c,c->last_matched);
|
||||
c->last_matched = 0;
|
||||
}
|
||||
c->obuf[c->olen++] = c->escape_char;
|
||||
c->obuf[c->olen++] = CC_ECM;
|
||||
ret += 2;
|
||||
c->bit_data = 0;
|
||||
c->mode = COMPRESSED;
|
||||
}
|
||||
#if 0
|
||||
else if (0) { /* fixme: when RESET? */
|
||||
COMP_DBG("encoder RESET\n");
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case COMPRESSED:
|
||||
if (c->cmp_last > (TEST_SLICE<<3)) {
|
||||
/* switch to transparent mode */
|
||||
COMP_DBG("encoder %d/%d %d: --> TRANSPARENT mode.\n",
|
||||
c->cmp_bits,c->raw_bits,c->cmp_last);
|
||||
if (c->last_matched) {
|
||||
c->update_at = c->last_matched;
|
||||
ret += send_data(c,c->last_matched);
|
||||
c->last_matched = 0;
|
||||
}
|
||||
c->last_added = 0;
|
||||
SEND_CW(c,CCW_ETM);
|
||||
ALIGN_BITS(c);
|
||||
SEND_BITS(c);
|
||||
c->mode = TRANSPARENT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* flush encoder data */
|
||||
int comp_flush_encoder(struct comp_state *c)
|
||||
{
|
||||
int ret = 0;
|
||||
//COMP_DBG1("flush_encoder...\n");
|
||||
#if 1 /* fixme: use something better */
|
||||
if (c->update_at) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
if (c->last_matched) {
|
||||
int total_len = c->flushed_len + c->str_len;
|
||||
ret = send_data(c,c->last_matched);
|
||||
c->flushed_len = total_len;
|
||||
}
|
||||
if(c->mode == COMPRESSED) {
|
||||
c->update_at = c->last_matched;
|
||||
c->last_matched = 0;
|
||||
c->flushed_len = 0;
|
||||
//if (c->bit_len > 0) {
|
||||
COMP_DBG("flush_encoder: send FLUSH\n");
|
||||
/* send FLUSH and align by zeros */
|
||||
SEND_CW(c,CCW_FLUSH);
|
||||
ALIGN_BITS(c);
|
||||
SEND_BITS(c);
|
||||
//}
|
||||
}
|
||||
if (ret)
|
||||
COMP_DBG("flush_encoder %d...\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* encoder */
|
||||
#define NEW_ENCODER 1
|
||||
int comp_encode(struct comp_state *c, u8 *in, int n)
|
||||
{
|
||||
register int i, ret=0;
|
||||
register u16 cw = 0;
|
||||
|
||||
for(i=0;i<n;) {
|
||||
if (c->update_at) {
|
||||
if (!match_char(c,c->update_at,*in)) {
|
||||
c->last_added = add_char(c,c->update_at,*in);
|
||||
COMP_DBG1("enc add %d at %d: %d(%c) '%s'\n",
|
||||
c->last_added,c->update_at,
|
||||
*in,*in,show_string(c,c->last_added));
|
||||
}
|
||||
c->update_at = 0;
|
||||
}
|
||||
#if NEW_ENCODER
|
||||
/* match string */
|
||||
while(i<n) {
|
||||
cw = match_char(c,c->last_matched,*in);
|
||||
if (!cw) {
|
||||
c->update_at = c->last_matched;
|
||||
ret += send_data(c,c->last_matched);
|
||||
c->last_matched = 0;
|
||||
break;
|
||||
}
|
||||
if (cw == c->last_added) {
|
||||
c->last_added = 0;
|
||||
ret += send_data(c,c->last_matched);
|
||||
c->last_matched = 0;
|
||||
break;
|
||||
}
|
||||
c->last_matched = cw;
|
||||
/* collect char */
|
||||
c->str_data[c->str_len++] = *in++; i++;
|
||||
if ( c->str_len + c->flushed_len == c->max_string ) {
|
||||
ret += send_data(c,c->last_matched);
|
||||
c->last_matched = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret += test_mode(c);
|
||||
}
|
||||
#else
|
||||
/* match char */
|
||||
cw = match_char(c,c->last_matched,*in);
|
||||
if (!cw) {
|
||||
/* add char */
|
||||
c->update_at = c->last_matched;
|
||||
/* send and reset string */
|
||||
ret += send_data(c,c->last_matched);
|
||||
c->last_matched = 0;
|
||||
}
|
||||
else if (cw == c->last_added) {
|
||||
c->last_added = 0;
|
||||
/* send and reset string */
|
||||
ret += send_data(c,c->last_matched);
|
||||
c->last_matched = 0;
|
||||
}
|
||||
else {
|
||||
c->last_matched = cw;
|
||||
/* collect char */
|
||||
c->str_data[c->str_len++] = *in++;
|
||||
if ( c->str_len + c->flushed_len == c->max_string ) {
|
||||
/* send and reset string */
|
||||
ret += send_data(c,c->last_matched);
|
||||
c->last_matched = 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
ret += test_mode(c);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#if COMP_TEST
|
||||
/*
|
||||
* Test encoder procedures
|
||||
*
|
||||
*/
|
||||
|
||||
/* force reset */
|
||||
int comp_force_reset(struct comp_state *c)
|
||||
{
|
||||
int ret = 0;
|
||||
if (c->mode != TRANSPARENT)
|
||||
return 0;
|
||||
COMP_DBG("comp_reset...\n");
|
||||
if (c->last_matched) {
|
||||
ret = send_data(c,c->last_matched);
|
||||
c->last_matched = 0;
|
||||
}
|
||||
c->obuf[c->olen++] = c->escape_char;
|
||||
c->obuf[c->olen++] = CC_RESET;
|
||||
ret += 2;
|
||||
c->bit_data = 0;
|
||||
dict_init(c);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* force change compression mode */
|
||||
int comp_force_change_mode(struct comp_state *c, enum COMP_MODE mode)
|
||||
{
|
||||
int ret = 0;
|
||||
if (mode == c->mode)
|
||||
return 0;
|
||||
COMP_DBG("change_mode...\n");
|
||||
if (c->last_matched) {
|
||||
c->update_at = c->last_matched;
|
||||
ret += send_data(c,c->last_matched);
|
||||
c->last_matched = 0;
|
||||
}
|
||||
/* switch to compressed mode */
|
||||
if (c->mode == TRANSPARENT) {
|
||||
COMP_DBG("encoder %ld/%ld %d: switch to COMPRESSED mode.\n",
|
||||
c->cmp_bits,c->raw_bits,c->cmp_last);
|
||||
c->obuf[c->olen++] = c->escape_char;
|
||||
c->obuf[c->olen++] = CCW_ECM;
|
||||
ret += 2;
|
||||
c->bit_data = 0;
|
||||
c->mode = COMPRESSED;
|
||||
}
|
||||
/* switch to transparent mode */
|
||||
else if (c->mode == COMPRESSED) {
|
||||
COMP_DBG("encoder %ld/%ld %d: switch to TRANSPARENT mode.\n",
|
||||
c->cmp_bits,c->raw_bits,c->cmp_last);
|
||||
SEND_CW(c,CCW_ETM);
|
||||
ALIGN_BITS(c);
|
||||
SEND_BITS(c);
|
||||
c->mode = TRANSPARENT;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* init procedures
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
int comp_init(struct comp_state *c,int dict_size,int max_str)
|
||||
{
|
||||
struct dict *d;
|
||||
int i;
|
||||
memset(c,0,sizeof(*c));
|
||||
if (dict_size < MIN_DICT_SIZE ||
|
||||
max_str < MIN_STR_SIZE || max_str > MAX_STR_SIZE)
|
||||
return -1;
|
||||
/* alloc dict */
|
||||
d = COMP_ALLOC(dict_size*sizeof(*d));
|
||||
if (!d)
|
||||
return -1;
|
||||
COMP_DBG("comp_init: dict size %d, max str %d (dict %d bytes).\n",
|
||||
dict_size,max_str,dict_size*sizeof(*d));
|
||||
memset(d,0,dict_size*sizeof(*d));
|
||||
c->max_string= max_str;
|
||||
c->dict_size = dict_size;
|
||||
c->dict = d;
|
||||
/* init dict */
|
||||
for(i=0;i<TOTAL_CHARS;i++) {
|
||||
c->dict[i+FIRST_ENTRY].ch = i;
|
||||
}
|
||||
dict_init(c);
|
||||
/* temporary */
|
||||
c->olen = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int comp_config(struct comp_state *c,int dict_size,int max_str)
|
||||
{
|
||||
if (dict_size < MIN_DICT_SIZE ||
|
||||
max_str < MIN_STR_SIZE || max_str > MAX_STR_SIZE)
|
||||
return -1;
|
||||
if (dict_size > c->dict_size || max_str > sizeof(c->str_data))
|
||||
return -1;
|
||||
c->max_string= max_str;
|
||||
c->dict_size = dict_size;
|
||||
//dict_init(c);
|
||||
/* temporary */
|
||||
//c->olen = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int comp_exit(struct comp_state *c)
|
||||
{
|
||||
COMP_DBG("comp exit: %d/%d %d\n",
|
||||
c->cmp_bits,c->raw_bits,c->cmp_last);
|
||||
c->dict_size = 0;
|
||||
if(c->dict) {
|
||||
COMP_FREE(c->dict);
|
||||
c->dict = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* modem init procedures
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* exported functions prototypes */
|
||||
extern int comp_init(struct comp_state *c,int dict_size,int max_str);
|
||||
extern int comp_config(struct comp_state *c,int dict_size,int max_str);
|
||||
extern int comp_exit(struct comp_state *c);
|
||||
extern int comp_encode(struct comp_state *c, u8 *in, int n);
|
||||
extern int comp_decode(struct comp_state *c, u8 *in, int n);
|
||||
extern int comp_flush_encoder(struct comp_state *c);
|
||||
extern int comp_flush_decoder(struct comp_state *c);
|
||||
|
||||
|
||||
int modem_comp_init(struct modem *m)
|
||||
{
|
||||
int ret;
|
||||
ret = comp_init(&m->comp.encoder,
|
||||
m->cfg.comp_dict_size,m->cfg.comp_max_string);
|
||||
if(ret)
|
||||
return ret;
|
||||
ret = comp_init(&m->comp.decoder,
|
||||
m->cfg.comp_dict_size,m->cfg.comp_max_string);
|
||||
if (ret) {
|
||||
comp_exit(&m->comp.encoder);
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int modem_comp_config(struct modem *m,int dict_size,int max_str)
|
||||
{
|
||||
int ret = 0;
|
||||
if ((ret = comp_config(&m->comp.encoder,dict_size,max_str)) ||
|
||||
(ret = comp_config(&m->comp.decoder,dict_size,max_str)) )
|
||||
COMP_ERR("modem_comp_config: setup failed (%d/%d).\n",
|
||||
dict_size,max_str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void modem_comp_exit(struct modem *m)
|
||||
{
|
||||
comp_exit(&m->comp.encoder);
|
||||
comp_exit(&m->comp.decoder);
|
||||
// temproary
|
||||
m->comp.head = m->comp.count = 0;
|
||||
}
|
||||
|
||||
|
||||
// FIXME: remove this stupest things
|
||||
static int get_odata(struct comp_state *c, char *buf, int n)
|
||||
{
|
||||
int ret = 0;
|
||||
if(c->olen > 0) {
|
||||
ret = c->olen - c->ohead < n ?
|
||||
c->olen - c->ohead : n;
|
||||
memcpy(buf,c->obuf+c->ohead,ret);
|
||||
c->ohead += ret;
|
||||
if (c->ohead == c->olen) {
|
||||
c->ohead = 0;
|
||||
c->olen = 0;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int modem_comp_encode(struct modem *m, u8 ch, char *buf, int n)
|
||||
{
|
||||
int ret;
|
||||
ret = get_odata(&m->comp.encoder,buf,n);
|
||||
if (ret == n) return ret;
|
||||
if(comp_encode(&m->comp.encoder,&ch,1)<0)
|
||||
return -1;
|
||||
ret += get_odata(&m->comp.encoder,buf+ret,n-ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int modem_comp_decode(struct modem *m, u8 ch, char *buf, int n)
|
||||
{
|
||||
int ret;
|
||||
ret = get_odata(&m->comp.decoder,buf,n);
|
||||
if(ret == n) return ret;
|
||||
if(comp_decode(&m->comp.decoder,&ch,1)<0)
|
||||
return -1;
|
||||
ret += get_odata(&m->comp.decoder,buf+ret,n-ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int modem_comp_flush_encoder(struct modem *m, char *buf, int n)
|
||||
{
|
||||
int ret;
|
||||
ret = get_odata(&m->comp.encoder,buf,n);
|
||||
if (ret == n) return ret;
|
||||
if(comp_flush_encoder(&m->comp.encoder) < 0)
|
||||
return -1;
|
||||
ret += get_odata(&m->comp.encoder,buf+ret,n-ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int modem_comp_flush_decoder(struct modem *m, char *buf, int n)
|
||||
{
|
||||
int ret;
|
||||
ret = get_odata(&m->comp.decoder,buf,n);
|
||||
if (ret == n) return ret;
|
||||
if(comp_flush_decoder(&m->comp.decoder) < 0)
|
||||
return -1;
|
||||
ret += get_odata(&m->comp.decoder,buf+ret,n-ret);
|
||||
return ret;
|
||||
}
|
137
slmodemd/modem_datafile.c
Normal file
137
slmodemd/modem_datafile.c
Normal file
|
@ -0,0 +1,137 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_datafile.c -- modem data file stuff.
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*/
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <modem_defs.h>
|
||||
#include <modem_debug.h>
|
||||
|
||||
#define DBG(fmt,args...) dprintf( fmt , ##args );
|
||||
|
||||
|
||||
struct datafile_record {
|
||||
unsigned minor;
|
||||
struct dsp_info dsp_info;
|
||||
unsigned size;
|
||||
};
|
||||
|
||||
|
||||
|
||||
int datafile_load_info(char *file_name,struct dsp_info *info)
|
||||
{
|
||||
struct datafile_record *dr;
|
||||
int ret = -1;
|
||||
int fd;
|
||||
|
||||
DBG("open file: %s...\n",file_name);
|
||||
fd = open(file_name, 0, 0);
|
||||
if(fd < 0) {
|
||||
DBG("cannot open '%s': %s\n",
|
||||
file_name,strerror(errno));
|
||||
return -errno;
|
||||
}
|
||||
|
||||
dr = (struct datafile_record *)malloc(sizeof(*dr));
|
||||
if (!dr) {
|
||||
close(fd);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
ret = read(fd,(char *)dr,sizeof(*dr));
|
||||
if (ret < 0) {
|
||||
free(dr);
|
||||
close(fd);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* simple validation */
|
||||
if(dr->size != sizeof(*dr)) {
|
||||
free(dr);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(info,&dr->dsp_info,sizeof(*info));
|
||||
|
||||
free(dr);
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int datafile_save_info(char *file_name,struct dsp_info *info)
|
||||
{
|
||||
struct datafile_record *dr;
|
||||
int ret = -1;
|
||||
int fd;
|
||||
|
||||
fd = open(file_name,O_CREAT|O_WRONLY,(S_IRUSR|S_IWUSR));
|
||||
if(fd < 0)
|
||||
return -errno;
|
||||
|
||||
dr = (struct datafile_record *)malloc(sizeof(*dr));
|
||||
if (!dr) {
|
||||
return -errno;
|
||||
close(fd);
|
||||
}
|
||||
|
||||
memcpy(&dr->dsp_info,info,sizeof(*info));
|
||||
dr->size = sizeof(*dr);
|
||||
|
||||
ret = write(fd,(char *)dr,sizeof(*dr));
|
||||
|
||||
free(dr);
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
169
slmodemd/modem_debug.c
Normal file
169
slmodemd/modem_debug.c
Normal file
|
@ -0,0 +1,169 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_debug.c -- modem debug module (dummy).
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <modem.h>
|
||||
#include <modem_debug.h>
|
||||
|
||||
unsigned int modem_debug_level=0;
|
||||
unsigned int modem_debug_logging=0;
|
||||
unsigned int dsplibs_debug_level=0;
|
||||
|
||||
static const char *modem_debug_logfile = "slmodem.log";
|
||||
|
||||
static int modem_log_fd;
|
||||
|
||||
/* logging */
|
||||
|
||||
int modem_debug_log_data(struct modem *m, unsigned id, const void *data, int count)
|
||||
{
|
||||
struct sllog_header hdr;
|
||||
int ret = 0;
|
||||
if(id <= modem_debug_logging && modem_log_fd > 0) {
|
||||
hdr.modem_id = (unsigned)m ;
|
||||
hdr.id = id;
|
||||
hdr.length = count;
|
||||
ret = write(modem_log_fd,&hdr,sizeof(hdr));
|
||||
if(ret < 0) {
|
||||
fprintf(stderr,"log_data: cannot write header: %s\n",
|
||||
strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
ret = write(modem_log_fd,data,count);
|
||||
if(ret < 0) {
|
||||
fprintf(stderr,"log_data: cannot write data: %s\n",
|
||||
strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* printing */
|
||||
|
||||
static int debug_vprintf(unsigned level, const char *fmt, va_list args)
|
||||
{
|
||||
static char debug_temp[512];
|
||||
struct timeval tv;
|
||||
int i, len;
|
||||
gettimeofday(&tv,NULL);
|
||||
i = snprintf(debug_temp,sizeof(debug_temp),"<%03ld.%06ld> ",
|
||||
(tv.tv_sec % 1000), tv.tv_usec);
|
||||
len = vsnprintf(debug_temp + i, sizeof(debug_temp) - i, fmt, args);
|
||||
if(modem_debug_logging)
|
||||
modem_debug_log_data(0,
|
||||
MODEM_DBG_PRINT_MSG,debug_temp,len + i);
|
||||
if(level <= modem_debug_level)
|
||||
fprintf( stderr, "%s", debug_temp);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int dsplibs_debug_printf(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int len;
|
||||
va_start(args, fmt);
|
||||
len = debug_vprintf(dsplibs_debug_level, fmt, args);
|
||||
va_end(args);
|
||||
return len;
|
||||
}
|
||||
|
||||
int modem_debug_printf(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int len;
|
||||
va_start(args, fmt);
|
||||
len = debug_vprintf(1, fmt, args);
|
||||
va_end(args);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int modem_debug_init(const char *suffix)
|
||||
{
|
||||
dsplibs_debug_level = modem_debug_level;
|
||||
if(modem_debug_logging) {
|
||||
char path_name[PATH_MAX];
|
||||
const char *name;
|
||||
if(suffix) {
|
||||
snprintf(path_name, sizeof(path_name),
|
||||
"%s.%s", modem_debug_logfile, suffix);
|
||||
name = path_name;
|
||||
}
|
||||
else
|
||||
name = modem_debug_logfile;
|
||||
modem_log_fd = creat(name,S_IREAD|S_IWRITE);
|
||||
if(modem_log_fd < 0) {
|
||||
fprintf(stderr,"cannot create `%s': %s\n",
|
||||
name,strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if(dsplibs_debug_level < 3)
|
||||
dsplibs_debug_level = 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void modem_debug_exit()
|
||||
{
|
||||
if(modem_log_fd > 0) {
|
||||
close(modem_log_fd);
|
||||
modem_log_fd = 0;
|
||||
}
|
||||
}
|
||||
|
104
slmodemd/modem_debug.h
Normal file
104
slmodemd/modem_debug.h
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_debug.h - modem debug definitions.
|
||||
*
|
||||
* Author: SashaK <sashak@smlink.com>
|
||||
*
|
||||
* Change History:
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MODEM_DEBUG_H__
|
||||
#define __MODEM_DEBUG_H__
|
||||
|
||||
|
||||
/* constant definitions */
|
||||
enum MODEM_LOG_CATEGORIES {
|
||||
/* 0-3 */
|
||||
MODEM_DBG_PRINT_MSG = 0,
|
||||
MODEM_DBG_RX_SAMPLES,
|
||||
MODEM_DBG_TX_SAMPLES,
|
||||
MODEM_DBG_ECHOC_SAMPLES,
|
||||
/* 4-5 */
|
||||
MODEM_DBG_MISC_DATA,
|
||||
MODEM_DBG_MISC1_DATA,
|
||||
/* 6-9 */
|
||||
MODEM_DBG_RX_BITS,
|
||||
MODEM_DBG_TX_BITS,
|
||||
MODEM_DBG_RX_DATA,
|
||||
MODEM_DBG_TX_DATA,
|
||||
/* 10-11 */
|
||||
MODEM_DBG_RX_CHARS,
|
||||
MODEM_DBG_TX_CHARS,
|
||||
/* 'overflow marker' */
|
||||
MODEM_DBG_OVERFLOW
|
||||
};
|
||||
|
||||
|
||||
struct sllog_header {
|
||||
unsigned modem_id;
|
||||
unsigned id;
|
||||
unsigned length;
|
||||
char data[0];
|
||||
};
|
||||
|
||||
struct modem;
|
||||
|
||||
#ifdef CONFIG_DEBUG_MODEM
|
||||
|
||||
extern unsigned modem_debug_level;
|
||||
extern int modem_debug_printf(const char *fmt,...)
|
||||
__attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
#define eprintf(args...) { modem_debug_printf("err: " args) ; }
|
||||
#define dprintf(args...) { modem_debug_printf(args) ; }
|
||||
|
||||
extern int modem_debug_log_data(struct modem *m, unsigned id, const void *, int);
|
||||
|
||||
#else /* not CONFIG_DEBUG_MODEM */
|
||||
|
||||
#define eprintf(fmt...)
|
||||
#define dprintf(fmt...)
|
||||
#define modem_debug_log_data(m,id,data,cnt)
|
||||
|
||||
#endif /* not CONFIG_DEBUG_MODEM */
|
||||
|
||||
extern int modem_debug_init(const char *suffix);
|
||||
extern void modem_debug_exit();
|
||||
|
||||
|
||||
#endif /* __MODEM_DEBUG_H__ */
|
||||
|
443
slmodemd/modem_defs.h
Normal file
443
slmodemd/modem_defs.h
Normal file
|
@ -0,0 +1,443 @@
|
|||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_defs.h - modem common definitions
|
||||
*
|
||||
* Author: sashak@smlink.com
|
||||
*/
|
||||
|
||||
#ifndef __MODEM_DEFS_H__
|
||||
#define __MODEM_DEFS_H__
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#include <linux/types.h>
|
||||
#else
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef __uint8_t u8;
|
||||
typedef __uint16_t u16;
|
||||
typedef __uint32_t u32;
|
||||
|
||||
typedef __int8_t s8;
|
||||
typedef __int16_t s16;
|
||||
typedef __int32_t s32;
|
||||
#endif /* !__KERNEL__ */
|
||||
|
||||
/* hook states */
|
||||
#define MODEM_HOOK_ON 0
|
||||
#define MODEM_HOOK_OFF 1
|
||||
#define MODEM_HOOK_SNOOPING 2
|
||||
|
||||
/* modem device ctrl interface */
|
||||
#define MDMCTL_CAPABILITIES 0x01
|
||||
#define MDMCTL_HOOKSTATE 0x02
|
||||
#define MDMCTL_SPEED 0x04
|
||||
#define MDMCTL_GETFMTS 0x05
|
||||
#define MDMCTL_SETFMT 0x06
|
||||
#define MDMCTL_SETFRAG 0x07
|
||||
#define MDMCTL_SETFRAGMENT MDMCTL_SETFRAG
|
||||
#define MDMCTL_SPEAKERVOL 0x08
|
||||
#define MDMCTL_IODELAY 0x10
|
||||
#define MDMCTL_CODECTYPE 0x11
|
||||
#define MDMCTL_PULSEDIAL 0x12
|
||||
#define MDMCTL_GETSTAT 0x20
|
||||
#define MDMCTL_START 0x21
|
||||
#define MDMCTL_STOP 0x22
|
||||
|
||||
|
||||
/* modem device status mask */
|
||||
#define MDMSTAT_ERROR 0x1
|
||||
#define MDMSTAT_RING 0x2
|
||||
#define MDMSTAT_DATA 0x4
|
||||
|
||||
|
||||
/* codec types - numbers important */
|
||||
enum codec_types {
|
||||
CODEC_UNKNOWN = 0,
|
||||
CODEC_AD1821 = 1,
|
||||
CODEC_STLC7550= 4,
|
||||
CODEC_SILABS = 9,
|
||||
CODEC_SIL3052 = 10,
|
||||
CODEC_SIL3054 = 11,
|
||||
CODEC_AD1803 = 12,
|
||||
CODEC_ALC545A = 13,
|
||||
};
|
||||
|
||||
/* sample formats + extensions */
|
||||
#define MFMT_SIZE_MASK 0x000f
|
||||
#define MFMT_SIZE_8 0x0000
|
||||
#define MFMT_SIZE_16 0x0001
|
||||
#define MFMT_SIGN_MASK 0x00f0
|
||||
#define MFMT_SIGNED 0x0010
|
||||
#define MFMT_UNSIGNED 0x0000
|
||||
#define MFMT_ORDER_MASK 0x0f00
|
||||
#define MFMT_ORDER_LE 0x0100
|
||||
#define MFMT_ORDER_BE 0x0000
|
||||
|
||||
#define MFMT_QUERY 0x0
|
||||
|
||||
#define MFMT_S8 (MFMT_SIZE_8|MFMT_SIGNED)
|
||||
#define MFMT_U8 (MFMT_SIZE_8|MFMT_UNSIGNED)
|
||||
#define MFMT_S16_LE (MFMT_SIZE_16|MFMT_SIGNED|MFMT_ORDER_LE)
|
||||
#define MFMT_S16_BE (MFMT_SIZE_16|MFMT_SIGNED|MFMT_ORDER_BE)
|
||||
#define MFMT_U16_LE (MFMT_SIZE_16|MFMT_UNSIGNED|MFMT_ORDER_LE)
|
||||
#define MFMT_U16_BE (MFMT_SIZE_16|MFMT_UNSIGNED|MFMT_ORDER_BE)
|
||||
|
||||
#define MFMT_IS_16BIT(x) ((x)&MFMT_SIZE_16)
|
||||
#define MFMT_IS_LE(x) ((x)&MFMT_ORDER_LE)
|
||||
#define MFMT_BYTESSHIFT(x) ((x)&MFMT_SIZE_MASK)
|
||||
#define MFMT_SHIFT(x) (MFMT_BYTESSHIFT(x))
|
||||
#define MFMT_BYTES(x) (1<<MFMT_BYTESSHFIT(x))
|
||||
|
||||
|
||||
/* s-registers */
|
||||
enum S_REGISTER {
|
||||
SREG_RINGS_TO_AUTO_ANSWER = 0,
|
||||
SREG_RING_COUNTER = 1,
|
||||
SREG_ESCAPE_CHAR = 2,
|
||||
SREG_CR_CHAR = 3,
|
||||
SREG_LF_CHAR = 4,
|
||||
SREG_BS_CHAR = 5,
|
||||
SREG_DIAL_TONE_WAIT_TIME = 6,
|
||||
SREG_WAIT_CARRIER_AFTER_DIAL = 7,
|
||||
SREG_DIAL_PAUSE_TIME = 8,
|
||||
SREG_CARRIER_DETECT_RESPONSE_TIME = 9,
|
||||
SREG_CARRIER_LOSS_DISCONNECT_TIME = 10,
|
||||
SREG_DTMF_DURATION = 11,
|
||||
SREG_ESCAPE_PROMPT_DELAY = 12,
|
||||
SREG_ECHO = 13,
|
||||
SREG_QUIET = 14,
|
||||
SREG_VERBOSE = 15,
|
||||
SREG_TONE_OR_PULSE = 16,
|
||||
SREG_TEST_TIMER = 18,
|
||||
SREG_INACTIVITY_TIMEOUT = 19,
|
||||
SREG_BREAK_LENGTH = 21,
|
||||
SREG_ORIGIN_OR_ANSWER = 22,
|
||||
SREG_XOFF_CHAR = 23,
|
||||
SREG_FLASH_TIMER = 24,
|
||||
SREG_DELAY_TO_DTR_OFF = 25, /* (NA) */
|
||||
SREG_RTS_TO_CTS_DELAY = 26, /* (NA) */
|
||||
SREG_AUTOANSWER_CLEAR_TIMEOUT = 27,
|
||||
SREG_PULSE_RATIO = 28,
|
||||
SREG_SPEAKER_CONTROL = 29,
|
||||
SREG_SPEAKER_VOLUME = 30,
|
||||
SREG_SPEAKER_LEVEL = 30,
|
||||
SREG_AUTOMODE = 31,
|
||||
SREG_DP = 32,
|
||||
|
||||
#if 1
|
||||
SREG_LINE_QUALITY_CONTROL = 39,
|
||||
SREG_X_CODE = 56,
|
||||
SREG_CD = 60, /* (&CN) */
|
||||
SREG_FLOW_CONTROL = 62, /* (&HN) */
|
||||
SREG_CONNNECT_MSG_FORMAT = 70,
|
||||
SREG_CONNNECT_MSG_SPEED_SRC = 71,
|
||||
SREG_ANS_DELAY = 92,
|
||||
/* new sgregs */
|
||||
SREG_EC = 103,
|
||||
SREG_COMP = 104,
|
||||
|
||||
SREG_DEFAULT_SETTING = 161, // AT used
|
||||
#else
|
||||
SREG_REQUESTED_DP = SREG_DP,
|
||||
SREG_REQUESTED_MIN_SPEED = 33,
|
||||
SREG_REQUESTED_MAX_SPEED = 34,
|
||||
SREG_ACTUAL_SPEED = 35,
|
||||
SREG_CONNECT_RESULT_CODE = 35,
|
||||
SREG_DATA_PUMP_STATUS = 36,
|
||||
SREG_VXX_STATUS = 36,
|
||||
SREG_ACTUAL_DP = 37,
|
||||
SREG_ACTUAL_RX_SPEED = 38,
|
||||
SREG_LINE_QUALITY_CONTROL = 39,
|
||||
SREG_SIGNAL_RECEPTION_GAIN = 41,
|
||||
SREG_SNR = 42,
|
||||
SREG_RESULT_CODES_CONTROL = 43,
|
||||
SREG_CONFIGURATION_SETTING = 44,
|
||||
SREG_SIGNAL_TRANSMISSION_LEVEL = 45,
|
||||
SREG_DISTINCTIVE_RING_SILENCE_PERIOD = 48,
|
||||
SREG_ADAPTIVE_ANSWER_MODE = 49,
|
||||
SREG_TEST_BASE = 50,
|
||||
SREG_TEST_MODE = SREG_TEST_BASE,
|
||||
SREG_TEST_PAR1 = (SREG_TEST_BASE+1),
|
||||
SREG_MAPPED_S28 = 52,
|
||||
SREG_MAPPED_S37 = 53,
|
||||
SREG_TEST_RES1 = (SREG_TEST_BASE+4),
|
||||
SREG_TEST_RES2 = (SREG_TEST_BASE+5),
|
||||
SREG_X_CODE = 56,
|
||||
SREG_MESSAGE_DETAIL = 57,
|
||||
SREG_CURRENT_SETTING = 59, /* (ZN,&FN) */
|
||||
SREG_CD = 60, /* (&CN) */
|
||||
SREG_FLOW_CONTROL = 62, /* (&HN) */
|
||||
SREG_CIRCUIT_106 = 66,
|
||||
SREG_CIRCUIT_107 = 67,
|
||||
SREG_CIRCUIT_109 = 68,
|
||||
SREG_CONNNECT_MSG_FORMAT = 70,
|
||||
SREG_COMMAND_AT_A = 70,
|
||||
SREG_CONNNECT_MSG_SPEED_SRC = 71,
|
||||
/* Modem Support registers */
|
||||
SREG_HANDSET_GANE = 72,
|
||||
SREG_RECBUF_PURGE_UPON_ABORT = 73,
|
||||
SREG_VOICE_DIALTONE_DETECT_DELAY = 73, /* in seconds */
|
||||
SREG_PLAYBACK_VALUME = 74, /* #VGT */
|
||||
SREG_CID_ENABLE = 75, /* #CID */
|
||||
SREG_ADPCM_BPS = 76, /* #VBS */
|
||||
SREG_BEEP_TONE_TIMER = 77, /* #VBT */
|
||||
SREG_VOICE_SRC_SELECT = 78, /* #VLS */
|
||||
SREG_RING_GOES_AWAY_TIMER = 79, /* #VRA */
|
||||
SREG_RING_NEVER_CAME_TIMER = 80, /* #VRN */
|
||||
SREG_SILENCE_DETECT_ENABLE = 81, /* #VSD */
|
||||
SREG_SILENCE_DETECT_SENSITIVITY = 82, /* #VSS */
|
||||
SREG_SILENCE_DETECT_DURATION = 83, /* #VSP */
|
||||
SREG_DTMF_TONE_REPORTS_CAP0 = 84, /* #VTD */
|
||||
SREG_DTMF_TONE_REPORTS_CAP1 = 85,
|
||||
SREG_DTMF_TONE_REPORTS_CAP2 = 86,
|
||||
SREG_TIME_MARK_PLACEMENT = 87, /* #VTM */
|
||||
SREG_SPK_MUTE = 88, /* #SPK */
|
||||
SREG_SPK_SPKR = 89, /* #SPK 2 */
|
||||
SREG_SPK_MICROPHONE = 90, /* #SPK 3 */
|
||||
SREG_ADPCM_SAMPLE_RATE = 91, /* #VSR */
|
||||
SREG_ANS_DELAY = 92,
|
||||
/* Voice Modem Support registers */
|
||||
SREG_DP_CYCLE_TIME = 93,
|
||||
SREG_ENV_CYCLE_TIME = 94,
|
||||
SREG_V42_CYCLE_TIME = 95,
|
||||
/* Sample Rate Sregister: */
|
||||
SREG_AUDIO_SAMPLE_RATE = 96,
|
||||
SREG_RAW_RMS_ENABLE = 97,
|
||||
SREG_RAW_RMS_IN = 98,
|
||||
SREG_RAW_RMS_OUT = 99,
|
||||
SREG_V42_BASEREG = 100,
|
||||
SREG_V42_DATA_LINK = SREG_V42_BASEREG,
|
||||
SREG_V42_MNP_BLOCK_SIZE = (SREG_V42_BASEREG + 1),
|
||||
SREG_V42_DATA_COMPRESSION = (SREG_V42_BASEREG + 2),
|
||||
SREG_V42_OUTPUT_PROTOCOL = (SREG_V42_BASEREG + 24),
|
||||
SREG_V42_OUTPUT_COMRESION = (SREG_V42_BASEREG + 26),
|
||||
SREG_V42_ORIG_REQUEST = (SREG_V42_BASEREG + 29),
|
||||
SREG_V42_ORIG_FALLBACK = (SREG_V42_BASEREG + 30),
|
||||
SREG_V42_ANSWER_FALLBACK = (SREG_V42_BASEREG + 31),
|
||||
SREG_V42_COMPRESSION_RATIO_REPORT = (SREG_V42_BASEREG + 32),
|
||||
SREG_V42_BAD_BYTES_PERCENTAGE = (SREG_V42_BASEREG + 33),
|
||||
SREG_RS_DEBUG_LEVEL = (SREG_V42_BASEREG + 34),
|
||||
SREG_V42_EA_SINGLE_UNIT_TIME = (SREG_V42_BASEREG + 35),
|
||||
SREG_V42_EA_USED_UNITS_NUMBER = (SREG_V42_BASEREG + 36),
|
||||
SREG_V42_EA_CRITICAL_BAD_UNITS_NUMBER = (SREG_V42_BASEREG + 37),
|
||||
SREG_MIC_GAIN = 138,
|
||||
SREG_LINE_RECORD_GAIN = 139,
|
||||
SREG_LOCAL_FLASH = 140,
|
||||
SREG_V42_EA_CRITICAL_BAD_UNITS_NUMBER_FOR_V34 = (SREG_V42_BASEREG+41),
|
||||
SREG_ATH1_FLAG = 142,
|
||||
SREG_BELL_MODE = 143,
|
||||
SREG_MAPPED_S35 = 144,
|
||||
SREG_TEST_COMMAND_SUBMODE = 145,
|
||||
SREG_PULSE_MAKE = 146, /* Percent */
|
||||
SREG_PULSE_PPS = 147, /* 10,20 */
|
||||
SREG_PULSE_PAUSE = 148, /* * 10ms */
|
||||
SREG_PULSE_REFRESH = 149, /* ms */
|
||||
SREG_FCLASS_CURRENT = 150,
|
||||
SREG_FAE_CURRENT = 151,
|
||||
SREG_LINE_OUT_GAIN = 152,
|
||||
SREG_SPK_OUT_GAIN = 153,
|
||||
SREG_HS_OUT_GAIN = 154,
|
||||
SREG_DTMF_LOW_GAIN_DB_2SCOMP = 155,
|
||||
SREG_DTMF_HIGH_GAIN_DB_2SCOMP = 156,
|
||||
SREG_SINUS_SAMPLE_RATE_REG_1 = 157,
|
||||
SREG_SINUS_SAMPLE_RATE_REG_2 = 158,
|
||||
SREG_PULSEDIAL_DISABLE = 159,
|
||||
/* ---------- Unsaved region from 160 ------------------- */
|
||||
SREG_DEFAULT_SETTING = 161, // AT used
|
||||
SREG_CALL_PROGRESS_CODE = 162,
|
||||
SREG_COUNTRY_CODE = 162,
|
||||
SREG_DEBUG_REG_0 = 170,
|
||||
SREG_DEBUG_REG_1 = 171,
|
||||
SREG_DEBUG_REG_2 = 172,
|
||||
SREG_DEBUG_REG_3 = 173,
|
||||
SREG_DEBUG_REG_4 = 174,
|
||||
SREG_DIAG_PROC_CNT1_ID = 180,
|
||||
SREG_DIAG_PROC_CNT2_ID = 181,
|
||||
SREG_DIAG_RING = 182,
|
||||
SREG_DIAG_COUNT_TYPE = 183,
|
||||
SREG_DIAG_TYPE = 184,
|
||||
SREG_DIAG_SCOPE = 185,
|
||||
SREG_PM_UPPER_THR = 186,
|
||||
SREG_PM_LOWER_THR = 187,
|
||||
SREG_PM_WEIGHT1 = 188,
|
||||
SREG_PM_WEIGHT2 = 189,
|
||||
SREG_PM_DEGRADE_ENABLE = 190,
|
||||
SREG_PM_DECISION_VALUE = 191,
|
||||
SREG_PROCESSOR_TYPE = 193,
|
||||
SREG_HW_TRACE_LEVEL = 197,
|
||||
SREG_HARDWARE_CONTROL = 197,
|
||||
SREG_STRM_TRACE_LEVEL = 198,
|
||||
SREG_STREAM_MANAGER_DEBUG_LEVEL = 198,
|
||||
SREG_BLACKLISTING_ENABLED_FLAG = 200,
|
||||
SREG_FAILED_ATTEMPTS_BEFORE_BLACKLISTING = 201,
|
||||
SREG_BLACKLISTING_DURATION = 202,
|
||||
SREG_BLACKLIST_TIMEOUT = 203,
|
||||
SREG_AT_P_COMMAND_DISABLED = 204,
|
||||
SREG_CID_TIMEOUT_IN_100MS = 205,
|
||||
SREG_V90_PAD_TYPE = 210,
|
||||
SREG_V90_POWER_REDUCTION = 211,
|
||||
SREG_V90_PROBING_MODE = 212,
|
||||
SREG_V90_COMPUTATIONAL_MODE = 213,
|
||||
SREG_CALL_PROGRESS_SIGNAL_RECEPTION_GAIN = 214,
|
||||
SREG_LINE_QUALITY = 215,
|
||||
SREG_DC_RECALIBRATION_PERIOD = 216,
|
||||
SREG_UPSTREAM_MIN_RATE = 217,
|
||||
SREG_UPSTREAM_MAX_RATE = 218,
|
||||
SREG_V22_LEVEL_CONTROL = 220,
|
||||
SREG_CALLING_TONE_LEVEL_CONTROL = 221,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/* data pumps identifiers */
|
||||
enum DP_ID {
|
||||
DP_CALLPROG = 2,
|
||||
DP_DUMMY = 3,
|
||||
DP_AUTOMODE = 4,
|
||||
DP_V8 = 8,
|
||||
DP_V17 = 17,
|
||||
DP_V21 = 21,
|
||||
DP_V22 = 22,
|
||||
DP_V23 = 23,
|
||||
DP_V22BIS = 122,
|
||||
DP_V32 = 32,
|
||||
DP_V32BIS = 132,
|
||||
DP_V34 = 34,
|
||||
DP_V34BIS = 134,
|
||||
DP_B103 = 103,
|
||||
DP_B212 = 212,
|
||||
DP_FAX = 100,
|
||||
DP_K56 = 56,
|
||||
DP_K56_OR_V90 = 65,
|
||||
DP_V8BIS = 108,
|
||||
DP_V90 = 90,
|
||||
DP_V90_NO_V8BIS = 91,
|
||||
DP_V92 = 92,
|
||||
DP_TEST = 126,
|
||||
DP_SINUS = 127,
|
||||
DP_MAX = 128,
|
||||
MAX_DP = 128
|
||||
};
|
||||
|
||||
/* dp status */
|
||||
#define DPSTAT_OK 0
|
||||
#define DPSTAT_CONNECT 1
|
||||
#define DPSTAT_ERROR 4
|
||||
#define DPSTAT_NODIALTONE 6
|
||||
#define DPSTAT_BUSY 7
|
||||
#define DPSTAT_NOANSWER 8
|
||||
#define DPSTAT_CHANGEDP 10
|
||||
|
||||
/* dsp info structure */
|
||||
struct dsp_info {
|
||||
unsigned connection_type;
|
||||
long clock_deviation;
|
||||
unsigned qc_lapm;
|
||||
unsigned qc_index;
|
||||
};
|
||||
|
||||
|
||||
/* fax definitions */
|
||||
|
||||
#define FAX_STATUS_OK 1
|
||||
#define FAX_STATUS_ERROR 2
|
||||
#define FAX_STATUS_CONNECT 3
|
||||
#define FAX_STATUS_NOCARRIER 4
|
||||
|
||||
enum FAX_CMD {
|
||||
FAX_CMD_FTS,
|
||||
FAX_CMD_FRS,
|
||||
FAX_CMD_FTM,
|
||||
FAX_CMD_FRM,
|
||||
FAX_CMD_FTH,
|
||||
FAX_CMD_FRH,
|
||||
};
|
||||
|
||||
/* voice definitions */
|
||||
|
||||
enum VOICE_CMD {
|
||||
VOICE_CMD_STATE_COMMAND,
|
||||
VOICE_CMD_STATE_RX,
|
||||
VOICE_CMD_STATE_TX,
|
||||
VOICE_CMD_STATE_DUPLEX,
|
||||
VOICE_CMD_STATE_SPEAKER,
|
||||
VOICE_CMD_BEEP,
|
||||
VOICE_CMD_DTMF,
|
||||
VOICE_CMD_ABORT,
|
||||
};
|
||||
|
||||
#define VOICE_STATUS_OK 1
|
||||
#define VOICE_STATUS_ERROR 2
|
||||
#define VOICE_STATUS_CONNECT 3
|
||||
|
||||
#define VOICE_STATE_COMMAND 0x00
|
||||
#define VOICE_STATE_RX 0x01
|
||||
#define VOICE_STATE_TX 0x02
|
||||
#define VOICE_STATE_DUPLEX (VOICE_STATE_TX|VOICE_STATE_RX)
|
||||
#define VOICE_STATE_SPEAKER 0x08
|
||||
|
||||
#define VOICE_DEVICE_NONE 0
|
||||
#define VOICE_DEVICE_LINE 1
|
||||
|
||||
struct voice_info {
|
||||
unsigned comp_method;
|
||||
unsigned sample_rate;
|
||||
unsigned rx_gain;
|
||||
unsigned tx_gain;
|
||||
unsigned dtmf_symbol;
|
||||
unsigned tone1_freq;
|
||||
unsigned tone2_freq;
|
||||
unsigned tone_duration;
|
||||
unsigned inactivity_timer;
|
||||
unsigned silence_detect_sensitivity;
|
||||
unsigned silence_detect_period;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*
|
||||
*/
|
||||
|
||||
struct modem;
|
||||
|
||||
extern int modem_get_sreg(struct modem *m, unsigned int num);
|
||||
extern int modem_set_sreg(struct modem *m, unsigned int num, int val);
|
||||
|
||||
|
||||
#endif /* __MODEM_DEFS_H__ */
|
||||
|
91
slmodemd/modem_dp.h
Normal file
91
slmodemd/modem_dp.h
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_dp.h - modem data pumps interface definitions
|
||||
*
|
||||
* Author: sashak@smlink.com
|
||||
*/
|
||||
|
||||
#ifndef __MODEM_DP_H__
|
||||
#define __MODEM_DP_H__
|
||||
|
||||
#include <modem_defs.h>
|
||||
|
||||
|
||||
/*
|
||||
* type definitions
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* data pump operations structure */
|
||||
struct dp_operations {
|
||||
const char *name;
|
||||
int use_count;
|
||||
/* dp interface */
|
||||
struct dp *(*create)(struct modem *, enum DP_ID id,
|
||||
int caller, int srate, int max_frag,
|
||||
struct dp_operations *);
|
||||
int (*delete)(struct dp *);
|
||||
int (*process)(struct dp *, void *in, void *out, int cnt);
|
||||
int (*hangup)(struct dp *);
|
||||
};
|
||||
|
||||
/* data pump structure */
|
||||
struct dp {
|
||||
enum DP_ID id;
|
||||
struct modem *modem;
|
||||
unsigned status;
|
||||
struct dp_operations *op;
|
||||
void *dp_data;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*
|
||||
*/
|
||||
|
||||
/* bit interface */
|
||||
extern int modem_get_bits(struct modem *m, int nbits, u8 *buf, int n);
|
||||
extern int modem_put_bits(struct modem *m, int nbits, u8 *buf, int n);
|
||||
|
||||
/* modem dp registration */
|
||||
extern int modem_dp_register(enum DP_ID id, struct dp_operations *op);
|
||||
extern void modem_dp_deregister(enum DP_ID id, struct dp_operations *op);
|
||||
|
||||
|
||||
#endif /* __MODEM_DP_H__ */
|
||||
|
1425
slmodemd/modem_ec.c
Normal file
1425
slmodemd/modem_ec.c
Normal file
File diff suppressed because it is too large
Load diff
111
slmodemd/modem_homolog.h
Normal file
111
slmodemd/modem_homolog.h
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_homolog.h -- Modem Homologation definitions.
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef __MODEM_HOMOLOG_H__
|
||||
#define __MODEM_HOMOLOG_H__
|
||||
|
||||
|
||||
/* homologation parameters struct */
|
||||
struct homolog_params {
|
||||
u8 PulseDialMakeTime;
|
||||
u8 PulseDialBreakTime;
|
||||
u8 PulseDialDigitPattern;
|
||||
u8 DTMFHighToneLevel;
|
||||
u8 DTMFDialSpeed;
|
||||
u8 MinBusyCadenceOnTime;
|
||||
u8 MaxBusyCadenceOnTime;
|
||||
u8 BusyDetectionCyclesNumber;
|
||||
u8 MinBusyCadenceOffTime;
|
||||
u8 MaxBusyCadenceOffTime;
|
||||
u8 CallingToneFlag;
|
||||
u8 HookFlashTime;
|
||||
u8 DialPauseTime; // ?
|
||||
u8 TransmitLevel;
|
||||
u8 DialModifierValidation;
|
||||
u8 DialToneValidationTime;
|
||||
//u8 BusyToneDiffTime;
|
||||
u8 DTMFHighAndLowToneLevelDifference;
|
||||
u8 DialToneCallProgressFilterIndex;
|
||||
u8 DialToneDetectionThreshold;
|
||||
u8 ABCDDialingPermittedFlag;
|
||||
u8 ComaPauseDurationLimit;
|
||||
//u8 PulseAndToneDialInSameDialStringPermittedFlag;
|
||||
u8 BusyToneCallProgressFilterIndex;
|
||||
u8 PulseBetweenDigitsInterval;
|
||||
u8 DialToneWaitTime;
|
||||
u8 MinRingbackCadenceOnTime;
|
||||
u8 MaxRingbackCadenceOnTime;
|
||||
u8 RingbackDetectionCyclesNumber;
|
||||
//u8 MinRingbackCadenceOffTime;
|
||||
//u8 MaxRingbackCadenceOffTime;
|
||||
//u8 RingbackToneCallProgressFilterIndex;
|
||||
//u8 MinCongestionCadenceOnTime;
|
||||
//u8 MaxCongestionCadenceOnTime;
|
||||
//u8 CongestionDetectionCyclesNumber;
|
||||
//u8 MinCongestionCadenceOffTime;
|
||||
//u8 MaxCongestionCadenceOffTime;
|
||||
//u8 CongestionToneCallProgressFilterIndex;
|
||||
u16 CallProgressSamplesBufferLength;
|
||||
u8 MustNoiseFilterBeApplied;
|
||||
//u32 DigitalImpairmentsMask;
|
||||
//u8 DialToneFilterSubindex;
|
||||
//u8 BusyToneLooseDetectionEnabled;
|
||||
//u8 CallWaitingIntegrationTimeMiliSec;
|
||||
//u8 CallWaitingThresholdPercentage;
|
||||
};
|
||||
|
||||
|
||||
/* homologation country set */
|
||||
struct homolog_set {
|
||||
const u16 id;
|
||||
const char *name;
|
||||
const struct homolog_params *params;
|
||||
};
|
||||
|
||||
/* 'nulled'-terminated homologation array */
|
||||
extern const struct homolog_set homolog_set[];
|
||||
|
||||
#endif /* __MODEM_HOMOLOG_H__ */
|
1212
slmodemd/modem_main.c
Normal file
1212
slmodemd/modem_main.c
Normal file
File diff suppressed because it is too large
Load diff
634
slmodemd/modem_pack.c
Normal file
634
slmodemd/modem_pack.c
Normal file
|
@ -0,0 +1,634 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_pack.c -- modem packer module.
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <modem.h>
|
||||
#include <modem_debug.h>
|
||||
|
||||
#define PACK_DBG(fmt,arg...) dprintf("%s: " fmt , m->name , ##arg)
|
||||
#define PACK_ERR(fmt,arg...) eprintf("%s: " fmt , m->name , ##arg)
|
||||
|
||||
/* HDLC definitions */
|
||||
|
||||
#define HDLC_FLAG 0x7e
|
||||
#define HDLC_ESCAPE (0x1f<<3)
|
||||
|
||||
|
||||
/* bit ordering (reverse) table */
|
||||
static const u8 _ordered[] = {
|
||||
0x0,0x8,0x4,0xc,0x2,0xa,0x6,0xe,
|
||||
0x1,0x9,0x5,0xd,0x3,0xb,0x7,0xf};
|
||||
#define REVERSE_BITS(c) { (c) = _ordered[(c)&0xf]<<4 | _ordered[(c)>>4] ; }
|
||||
|
||||
|
||||
/*
|
||||
* Async packer
|
||||
*
|
||||
*/
|
||||
|
||||
#define START_BIT 0
|
||||
#define STOP_BIT 1
|
||||
#if 0
|
||||
#define STOP_BITS(p) ((p)->stop_bits)
|
||||
#define DATA_SIZE(p) ((p)->data_bits)
|
||||
#define CHAR_SIZE(p) ((p)->char_size)
|
||||
#define CHAR_DATA(p,ch) ( ( ~(0x1<<(CHAR_SIZE(p)-1)) & \
|
||||
((ch)<<(p)->stop_bits) ) | \
|
||||
((0x1<<(p)->stop_bits)-1) )
|
||||
#else
|
||||
#define STOP_BITS(p) 1
|
||||
#define DATA_SIZE(p) 8
|
||||
#define CHAR_SIZE(p) 10
|
||||
#define CHAR_DATA(p,ch) (((ch)<<1)|0x1)
|
||||
#endif
|
||||
|
||||
int modem_async_get_bits(struct modem *m, int nbits, u8 *bit_buf, int bit_cnt)
|
||||
{
|
||||
struct bits_state *s = &m->pack;
|
||||
int ret = 0;
|
||||
u8 ch;
|
||||
do {
|
||||
/* fill bits */
|
||||
while ( bit_cnt > 0 && s->bit >= nbits) {
|
||||
*bit_buf++ = (s->data>>(s->bit-nbits));
|
||||
s->bit -= nbits;
|
||||
ret ++;
|
||||
bit_cnt--;
|
||||
}
|
||||
if (bit_cnt <= 0)
|
||||
break;
|
||||
/* get char */
|
||||
if (!m->get_chars || m->get_chars(m, (char*)&ch, 1) != 1)
|
||||
break;
|
||||
REVERSE_BITS(ch);
|
||||
s->data <<= CHAR_SIZE(m);
|
||||
s->data |= CHAR_DATA(m,ch);
|
||||
s->bit += CHAR_SIZE(m);
|
||||
} while (1);
|
||||
if (s->bit && bit_cnt > 0) {
|
||||
/* left data + stops */
|
||||
*bit_buf++ = (s->data<<(nbits-s->bit))|((0x1<<(nbits-s->bit))-1);
|
||||
ret ++;
|
||||
bit_cnt--;
|
||||
s->bit = 0;
|
||||
}
|
||||
#if 0
|
||||
memcpy(bit_buf,(1<<nbits)-1,bit_cnt);
|
||||
ret += bit_cnt;
|
||||
#else
|
||||
while (bit_cnt > 0) {
|
||||
/* fill stops */
|
||||
*bit_buf++ = (1<<nbits)-1;
|
||||
bit_cnt --;
|
||||
ret ++;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int modem_async_put_bits(struct modem *m, int nbits, u8 *bit_buf, int bit_cnt)
|
||||
{
|
||||
struct bits_state *s = &m->unpack;
|
||||
int ret = 0;
|
||||
u8 ch;
|
||||
while(bit_cnt > 0) {
|
||||
s->data<<= nbits;
|
||||
s->data |= *bit_buf++ & ((0x1<<nbits)-1);
|
||||
s->bit += nbits;
|
||||
bit_cnt --;
|
||||
ret++;
|
||||
while(s->bit && s->data&(0x1<<(s->bit-1))) /* stop bit */
|
||||
s->bit--;
|
||||
while (s->bit >= CHAR_SIZE(m)) {
|
||||
ch = s->data >>
|
||||
(s->bit-(CHAR_SIZE(m)-STOP_BITS(m)));
|
||||
s->bit-= CHAR_SIZE(m);
|
||||
REVERSE_BITS(ch);
|
||||
if (m->put_chars)
|
||||
m->put_chars(m,(const char*)&ch,1);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void modem_async_start(struct modem *m)
|
||||
{
|
||||
m->pack.bit = m->unpack.bit = 0;
|
||||
m->pack.data = m->unpack.data = 0;
|
||||
m->bit_timer_func = NULL;
|
||||
m->bit_timer = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Packer detector
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Detection phase description.
|
||||
* originator - transmits ODPs until T400 timer is expired
|
||||
* or until ADP is received.
|
||||
*
|
||||
* answer - transmits marks(1) until: detect phase termination,
|
||||
* ODP receipt - send at least 10 ADPs,
|
||||
* detection of start protocol phase (continuous flags).
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* ODP: 0100010001 11111111 0100010011 11111111 */
|
||||
#define ODP0 0x88
|
||||
#define ODP1 0x89
|
||||
/* ADP v42: 0101000101 11111111 0110000101 11111111 */
|
||||
/* ADP v14: 0101000101 11111111 0000000001 11111111 */
|
||||
#define ADP0 0xa2
|
||||
#define ADP1_V14 0x00
|
||||
#define ADP1_V42 0xc2
|
||||
#define ADP1 ADP1_V42
|
||||
|
||||
#define MIN_RX_PATTERNS 2
|
||||
#define MAX_TX_PATTERNS 16
|
||||
#define PATTERN_SIZE 36
|
||||
|
||||
#define FILL_PATTERN_ODP(pat) { (pat)[0]=ODP0 ; (pat)[1]=ODP1; }
|
||||
#define FILL_PATTERN_ADP(pat) { (pat)[0]=ADP0 ; (pat)[1]=ADP1; }
|
||||
|
||||
|
||||
static void detector_start(struct modem *m)
|
||||
{
|
||||
PACK_DBG("detector start...\n");
|
||||
m->packer.detector.tx_count = 1;
|
||||
}
|
||||
|
||||
static void detector_finish(struct modem *m)
|
||||
{
|
||||
PACK_DBG("detector finished.\n");
|
||||
// fixme: modem update config
|
||||
m->cfg.ec = m->packer.detector.ec_enable;
|
||||
modem_update_status(m,STATUS_PACK_LINK);
|
||||
}
|
||||
|
||||
int modem_detector_get_bits(struct modem *m, int nbits, u8 *bit_buf, int bit_cnt)
|
||||
{
|
||||
struct bits_state *s = &m->pack;
|
||||
struct detect_state *d = &m->packer.detector;
|
||||
int ret = 0;
|
||||
do {
|
||||
/* fill bits */
|
||||
while ( bit_cnt > 0 && s->bit >= nbits) {
|
||||
*bit_buf++ = (s->data>>(s->bit-nbits));
|
||||
s->bit -= nbits;
|
||||
ret ++;
|
||||
bit_cnt--;
|
||||
}
|
||||
if (bit_cnt <= 0)
|
||||
break;
|
||||
#if 0
|
||||
s->data <<= 18;
|
||||
s->data |= (0x1ff<<9)|(d->tx_pattern[d->tx_count++%2]);
|
||||
s->bit += 18;
|
||||
#else
|
||||
/* get char */
|
||||
s->data <<= 9;
|
||||
s->data |= 0x1ff;
|
||||
s->bit += 9;
|
||||
if (d->tx_count > 0) {
|
||||
s->data <<= 9;
|
||||
s->data |= d->tx_pattern[d->tx_count++%2];
|
||||
s->bit += 9;
|
||||
}
|
||||
#endif
|
||||
} while (1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int modem_detector_put_bits(struct modem *m, int nbits, u8 *bit_buf, int bit_cnt)
|
||||
{
|
||||
struct bits_state *s = &m->unpack;
|
||||
struct detect_state *d = &m->packer.detector;
|
||||
int ret = 0;
|
||||
u8 ch;
|
||||
while(bit_cnt > 0) {
|
||||
s->data<<= nbits;
|
||||
s->data |= *bit_buf++ & ((0x1<<nbits)-1);
|
||||
s->bit += nbits;
|
||||
bit_cnt --;
|
||||
ret++;
|
||||
while(s->bit && s->data&(0x1<<(s->bit-1))) /* skip marks */
|
||||
s->bit--;
|
||||
while (s->bit >= 10 ) {
|
||||
ch = s->data >> (s->bit-9);
|
||||
s->bit-= 10;
|
||||
PACK_DBG("rx pattern: 0x%02x.\n",ch);
|
||||
if (ch == HDLC_FLAG) {
|
||||
PACK_DBG("hdlc flag detected.\n");
|
||||
d->ec_enable = 1;
|
||||
m->bit_timer_func = detector_finish;
|
||||
m->bit_timer = PATTERN_SIZE;
|
||||
continue;
|
||||
}
|
||||
if (!d->rx_count) {
|
||||
d->rx_count = (ch == d->rx_pattern[0]);
|
||||
continue;
|
||||
}
|
||||
if (d->rx_count >= 2)
|
||||
continue;
|
||||
switch(ch) {
|
||||
case ODP1:
|
||||
//PACK_DBG("rx ODP.\n");
|
||||
if (!m->caller) {
|
||||
/* start replay ADP and leave detector */
|
||||
d->tx_count = 1;
|
||||
d->rx_count = 2;
|
||||
d->ec_enable = 1;
|
||||
m->bit_timer_func = detector_finish;
|
||||
m->bit_timer = MAX_TX_PATTERNS*PATTERN_SIZE;
|
||||
}
|
||||
else
|
||||
d->rx_count = 0;
|
||||
break;
|
||||
case ADP1_V14:
|
||||
//PACK_DBG("rx ADP non v42.\n");
|
||||
d->rx_count = 2;
|
||||
d->ec_enable = 0;
|
||||
m->bit_timer_func = detector_finish;
|
||||
m->bit_timer = PATTERN_SIZE;
|
||||
break;
|
||||
case ADP1_V42:
|
||||
//PACK_DBG("rx ADP v42.\n");
|
||||
m->cfg.ec = 1;
|
||||
d->rx_count = 2;
|
||||
d->ec_enable = 1;
|
||||
m->bit_timer_func = detector_finish;
|
||||
m->bit_timer = PATTERN_SIZE;
|
||||
break;
|
||||
default:
|
||||
d->rx_count = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void modem_detector_start(struct modem *m) {
|
||||
struct detect_state *d = &m->packer.detector;
|
||||
int rate = 28800 ; // fixme: use real bit rate from modem
|
||||
d->tx_count = 0; /* mute transmitter */
|
||||
d->rx_count = 0;
|
||||
d->ec_enable = 0;
|
||||
if (m->caller) {
|
||||
FILL_PATTERN_ODP(d->tx_pattern);
|
||||
FILL_PATTERN_ADP(d->rx_pattern);
|
||||
m->bit_timer_func = detector_start;
|
||||
m->bit_timer = 64*8 ;
|
||||
}
|
||||
else {
|
||||
FILL_PATTERN_ADP(d->tx_pattern);
|
||||
FILL_PATTERN_ODP(d->rx_pattern);
|
||||
m->bit_timer_func = detector_finish;
|
||||
m->bit_timer = rate*3/4; /* T400 timeout */
|
||||
}
|
||||
m->pack.bit = m->unpack.bit = 0;
|
||||
m->pack.data = m->unpack.data = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* HDLC packer
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* static data */
|
||||
|
||||
/* fcs16 table */
|
||||
static const
|
||||
u16 fcs16_tab[256] = {
|
||||
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
|
||||
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
|
||||
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
|
||||
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
|
||||
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
|
||||
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
|
||||
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
|
||||
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
|
||||
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
|
||||
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
|
||||
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
|
||||
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
|
||||
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
|
||||
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
|
||||
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
|
||||
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
|
||||
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
|
||||
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
|
||||
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
|
||||
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
|
||||
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
|
||||
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
|
||||
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
|
||||
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
|
||||
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
|
||||
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
|
||||
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
|
||||
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
|
||||
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
|
||||
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
|
||||
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
|
||||
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
|
||||
};
|
||||
|
||||
#define fcstab fcs16_tab
|
||||
#define INIT_FCS16 0xffff /* Initial FCS16 value */
|
||||
#define GOOD_FCS16 0xf0b8 /* Good final FCS16 value */
|
||||
|
||||
#define GET_FCS(fcs,c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
|
||||
#define INIT_FCS INIT_FCS16 /* Initial FCS value */
|
||||
#define GOOD_FCS GOOD_FCS16 /* Good final FCS value */
|
||||
|
||||
|
||||
/* hdlc bit generators */
|
||||
|
||||
#define HDLC_PUT_BYTE { \
|
||||
for( i = 0 ; i < 8 ; i++ ) { \
|
||||
s->data<<=1; \
|
||||
s->bit++; \
|
||||
if(in&0x1) { \
|
||||
h->tx_ones++; \
|
||||
s->data |= 0x1; \
|
||||
if (h->tx_ones==5) { \
|
||||
s->data<<=1; \
|
||||
s->bit++; \
|
||||
h->tx_ones = 0; \
|
||||
} \
|
||||
} \
|
||||
else { \
|
||||
h->tx_ones = 0; \
|
||||
} \
|
||||
in>>=1; \
|
||||
} }
|
||||
|
||||
|
||||
int modem_hdlc_get_bits(struct modem *m, int nbits,
|
||||
u8 *bit_buf, int bit_cnt)
|
||||
{
|
||||
struct hdlc_state *h = &m->packer.hdlc;
|
||||
register struct bits_state *s = &m->pack;
|
||||
register int i, ret = 0;
|
||||
register u8 in, mask = ((1<<nbits) - 1);
|
||||
|
||||
do {
|
||||
/* fill bits */
|
||||
while ( bit_cnt > 0 && s->bit >= nbits) {
|
||||
*bit_buf++ = (s->data>>(s->bit-nbits))&mask;
|
||||
s->bit -= nbits;
|
||||
ret ++;
|
||||
bit_cnt--;
|
||||
}
|
||||
if (bit_cnt <= 0)
|
||||
break;
|
||||
if (!h->tx_frame) {
|
||||
s->data <<= 8;
|
||||
s->data |= HDLC_FLAG;
|
||||
s->bit += 8;
|
||||
if (h->get_tx_frame &&
|
||||
(h->tx_frame = h->get_tx_frame(h->framer))) {
|
||||
h->tx_frame->fcs = INIT_FCS;
|
||||
h->tx_frame->count = 0;
|
||||
}
|
||||
}
|
||||
else if(h->tx_frame->count == h->tx_frame->size) {
|
||||
/* end frame */
|
||||
/* put fcs */
|
||||
h->tx_frame->fcs ^= 0xffff;
|
||||
in = h->tx_frame->fcs&0xff;
|
||||
HDLC_PUT_BYTE;
|
||||
in = (h->tx_frame->fcs>>8)&0xff;
|
||||
HDLC_PUT_BYTE;
|
||||
h->tx_ones = 0;
|
||||
/* frame complete callback */
|
||||
if (h->tx_complete)
|
||||
h->tx_complete(h->framer, h->tx_frame);
|
||||
/* reset tx frame */
|
||||
h->tx_frame = NULL;
|
||||
/* put flags will done automatically */
|
||||
}
|
||||
else {
|
||||
in = h->tx_frame->buf[h->tx_frame->count];
|
||||
h->tx_frame->count++;
|
||||
/* fixme: in order to speed up
|
||||
fcs calc: copy it to local var */
|
||||
h->tx_frame->fcs = GET_FCS(h->tx_frame->fcs,in);
|
||||
HDLC_PUT_BYTE;
|
||||
}
|
||||
} while (1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int modem_hdlc_put_bits(struct modem *m, int nbits,
|
||||
u8 *bit_buf, int bit_cnt)
|
||||
{
|
||||
struct hdlc_state *h = &m->packer.hdlc;
|
||||
register struct bits_state *s = &m->unpack;
|
||||
register int ret = 0;
|
||||
register int i;
|
||||
register u8 in, out, mask = ((0x1<<nbits)-1);
|
||||
while(bit_cnt > 0) {
|
||||
s->data <<= nbits;
|
||||
s->data |= *bit_buf++ & mask;
|
||||
s->bit += nbits;
|
||||
bit_cnt--;
|
||||
ret++;
|
||||
|
||||
/* 8 char, 2 possible escapes, +8 estimated flag */
|
||||
if ( s->bit < 8 + 8 + 2)
|
||||
continue;
|
||||
|
||||
out = 0;
|
||||
// fixme: probably may be optimized by handling whole
|
||||
// byte with masking
|
||||
/* mask = 0x80; */
|
||||
for ( i=0 ; i<8 ; i++ ) {
|
||||
in = s->data >> (s->bit-8) ;
|
||||
/* flag: finish frame */
|
||||
if (in == HDLC_FLAG) {
|
||||
/* end of frame */;
|
||||
if ( !h->rx_frame->count ) {
|
||||
//HDLC_DBG("empty.\n");
|
||||
}
|
||||
/* check frame for errors */
|
||||
else if (h->rx_error) {
|
||||
PACK_DBG("hdlc frame error.\n");
|
||||
}
|
||||
else if (i) {
|
||||
PACK_DBG("hdlc frame integrity error.\n");
|
||||
}
|
||||
#if 1
|
||||
else if ( h->rx_frame->count < 3 ) {
|
||||
#else
|
||||
else if ( h->rx_frame->count < 4 ) {
|
||||
#endif
|
||||
PACK_DBG("hdlc frame size error.\n");
|
||||
}
|
||||
else if ( h->rx_frame->fcs != GOOD_FCS ) {
|
||||
PACK_DBG("hdlc frame fcs error.\n");
|
||||
}
|
||||
/* good frame */
|
||||
else if ( h->rx_complete ) {
|
||||
/* reduce fcs size */
|
||||
h->rx_frame->count -= 2;
|
||||
h->rx_complete(h->framer,h->rx_frame);
|
||||
}
|
||||
s->bit -= 8;
|
||||
h->rx_ones = 0;
|
||||
h->rx_error = 0;
|
||||
h->rx_frame->fcs = INIT_FCS;
|
||||
h->rx_frame->count = 0;
|
||||
break;
|
||||
}
|
||||
else if(h->rx_error) {
|
||||
s->bit--;
|
||||
continue;
|
||||
}
|
||||
/* put reversed data bit */
|
||||
out >>= 1;
|
||||
if (in&0x80) {
|
||||
out |= 0x80;
|
||||
h->rx_ones++;
|
||||
/* escape or idle reached */
|
||||
if (h->rx_ones == 5) {
|
||||
if (in&0x40) {
|
||||
h->rx_error++;
|
||||
h->rx_frame->count = 0;
|
||||
}
|
||||
s->bit--;
|
||||
h->rx_ones = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
h->rx_ones = 0;
|
||||
s->bit--;
|
||||
}
|
||||
|
||||
/* finish char */
|
||||
if(i==8 && !h->rx_error) {
|
||||
if (h->rx_frame->count < h->rx_frame->size) {
|
||||
h->rx_frame->buf[h->rx_frame->count] = out;
|
||||
h->rx_frame->count++;
|
||||
h->rx_frame->fcs = GET_FCS(h->rx_frame->fcs,out);
|
||||
}
|
||||
else { /* overflow */
|
||||
PACK_DBG("hdlc rx frame overflow.\n");
|
||||
h->rx_error++;
|
||||
h->rx_frame->count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void modem_hdlc_start(struct modem *m)
|
||||
{
|
||||
struct hdlc_state *h = &m->packer.hdlc;
|
||||
PACK_DBG("hdlc_start...\n");
|
||||
memset(h,0,sizeof(*h));
|
||||
/* wait for flag to clear rx error state */
|
||||
h->rx_error = 1;
|
||||
/* rx frame */
|
||||
h->rx_frame = &h->_rx_frame;
|
||||
h->rx_frame->buf = h->_rx_buf;
|
||||
h->rx_frame->count= 0;
|
||||
h->rx_frame->size = sizeof(h->_rx_buf);
|
||||
h->rx_frame->fcs = INIT_FCS;
|
||||
/* tx frame */
|
||||
h->tx_frame = 0;
|
||||
|
||||
m->pack.bit = m->unpack.bit = 0;
|
||||
m->pack.data = m->unpack.data = 0;
|
||||
m->bit_timer_func = NULL;
|
||||
m->bit_timer = 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// temp stupid things
|
||||
static struct hdlc_frame *tmp_get_frame(void *framer)
|
||||
{
|
||||
frame_t *f;
|
||||
struct modem *m = framer;
|
||||
if(m->get_chars) {
|
||||
f = &m->packer.hdlc._tx_frame;
|
||||
f->buf = m->packer.hdlc._tx_buf;
|
||||
f->size = m->get_chars(m,f->buf,sizeof(m->packer.hdlc._tx_buf));
|
||||
if(f->size <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
PACK_DBG("get frame: %d...\n",f->size);
|
||||
return f;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
static void tmp_put_frame(void *framer, frame_t *fr)
|
||||
{
|
||||
struct modem *m = framer;
|
||||
if(fr->count > 0 && m->put_chars) {
|
||||
PACK_DBG("put frame: %d...\n",fr->count);
|
||||
m->put_chars(m,fr->buf,fr->count);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void tmp_init(struct modem *m)
|
||||
{
|
||||
m->packer.hdlc.get_tx_frame = tmp_get_frame;
|
||||
m->packer.hdlc.rx_complete = tmp_put_frame;
|
||||
m->packer.hdlc.framer = m;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
207
slmodemd/modem_param.c
Normal file
207
slmodemd/modem_param.c
Normal file
|
@ -0,0 +1,207 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_param.c -- modem parameters access module.
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <modem.h>
|
||||
#include <modem_homolog.h>
|
||||
#include <modem_param.h>
|
||||
|
||||
|
||||
|
||||
/* param access services */
|
||||
long modem_get_sreg_param(struct modem *m,unsigned sreg_num)
|
||||
{
|
||||
return modem_get_sreg(m,sreg_num);
|
||||
}
|
||||
|
||||
long modem_get_param(struct modem *m, unsigned param_name)
|
||||
{
|
||||
int val;
|
||||
switch (param_name) {
|
||||
case MDMPRM_NONE:
|
||||
break;
|
||||
case MDMPRM_MIN_RATE:
|
||||
return m->min_rate;
|
||||
case MDMPRM_MAX_RATE:
|
||||
return m->max_rate;
|
||||
case MDMPRM_IODELAY:
|
||||
return m->driver.ioctl(m,MDMCTL_IODELAY,0);
|
||||
case MDMPRM_CODECTYPE:
|
||||
val = m->driver.ioctl(m,MDMCTL_CODECTYPE,0);
|
||||
if(val<0)
|
||||
return CODEC_UNKNOWN; /* unknown */
|
||||
return val;
|
||||
case MDMPRM_DIALSTR:
|
||||
return (long)m->dial_string;
|
||||
case MDMPRM_AUTOMODE:
|
||||
return 0 /* MODEM_AUTOMODE(m)*/;
|
||||
case MDMPRM_DPRUNTIME:
|
||||
return (long)(m->dp_runtime);
|
||||
case MDMPRM_DSPINFO:
|
||||
return (long)(&m->dsp_info);
|
||||
#ifdef MODEM_CONFIG_VOICE
|
||||
case MDMPRM_VOICEINFO:
|
||||
return (long)(&m->voice_info);
|
||||
#endif
|
||||
case MDMPRM_DP_ADDR:
|
||||
return (long)(m->dp);
|
||||
case GetPulseDialMakeTime:
|
||||
return m->homolog->params->PulseDialMakeTime;
|
||||
case GetPulseDialBreakTime:
|
||||
return m->homolog->params->PulseDialBreakTime;
|
||||
case GetPulseDialDigitPattern:
|
||||
return m->homolog->params->PulseDialDigitPattern;
|
||||
case GetDTMFHighToneLevel:
|
||||
return m->homolog->params->DTMFHighToneLevel;
|
||||
case GetDTMFDialSpeed:
|
||||
return modem_get_sreg(m,SREG_DTMF_DURATION);
|
||||
case GetMinBusyCadenceOnTime:
|
||||
return m->homolog->params->MinBusyCadenceOnTime;
|
||||
case GetMaxBusyCadenceOnTime:
|
||||
return m->homolog->params->MaxBusyCadenceOnTime;
|
||||
case GetBusyDetectionCyclesNumber:
|
||||
return m->homolog->params->BusyDetectionCyclesNumber;
|
||||
case GetMinBusyCadenceOffTime:
|
||||
return m->homolog->params->MinBusyCadenceOffTime;
|
||||
case GetMaxBusyCadenceOffTime:
|
||||
return m->homolog->params->MaxBusyCadenceOffTime;
|
||||
case GetCallingToneFlag:
|
||||
return m->homolog->params->CallingToneFlag;
|
||||
case GetHookFlashTime:
|
||||
#if 0
|
||||
return modem_get_sreg(m,SREG_FLASH_TIMER);
|
||||
#else
|
||||
return m->homolog->params->HookFlashTime;
|
||||
#endif
|
||||
case GetBlindDialPause:
|
||||
return modem_get_sreg(m,SREG_DIAL_TONE_WAIT_TIME);
|
||||
case GetNoAnswerTimeOut:
|
||||
return modem_get_sreg(m,SREG_WAIT_CARRIER_AFTER_DIAL);
|
||||
case GetDialPauseTime:
|
||||
return modem_get_sreg(m,SREG_DIAL_PAUSE_TIME);
|
||||
case GetTransmitLevel:
|
||||
return m->homolog->params->TransmitLevel;
|
||||
case GetDialModifierValidation:
|
||||
return m->homolog->params->DialModifierValidation;
|
||||
case GetDialToneValidationTime:
|
||||
return m->homolog->params->DialToneValidationTime;
|
||||
case GetBusyToneDiffTime:
|
||||
return 0;
|
||||
case GetDTMFHighAndLowToneLevelDifference:
|
||||
return m->homolog->params->DTMFHighAndLowToneLevelDifference;
|
||||
case GetPulseDialingFlag:
|
||||
return !modem_get_sreg(m,SREG_TONE_OR_PULSE);
|
||||
case GetDialToneCallProgressFilterIndex:
|
||||
return m->homolog->params->DialToneCallProgressFilterIndex;
|
||||
case GetDialToneDetectionThreshold:
|
||||
return m->homolog->params->DialToneDetectionThreshold;
|
||||
case GetABCDDialingPermittedFlag:
|
||||
return m->homolog->params->ABCDDialingPermittedFlag;
|
||||
case GetComaPauseDurationLimit:
|
||||
return m->homolog->params->ComaPauseDurationLimit;
|
||||
case GetPulseAndToneDialInSameDialStringPermittedFlag:
|
||||
return 0;
|
||||
case GetBusyToneCallProgressFilterIndex:
|
||||
return m->homolog->params->BusyToneCallProgressFilterIndex;
|
||||
case GetPulseBetweenDigitsInterval:
|
||||
return m->homolog->params->PulseBetweenDigitsInterval;
|
||||
case GetDialToneWaitTime:
|
||||
return modem_get_sreg(m,SREG_DIAL_TONE_WAIT_TIME);
|
||||
case GetMinRingbackCadenceOnTime:
|
||||
return m->homolog->params->MinRingbackCadenceOnTime;
|
||||
case GetMaxRingbackCadenceOnTime:
|
||||
return m->homolog->params->MaxRingbackCadenceOnTime;
|
||||
case GetRingbackDetectionCyclesNumber:
|
||||
return m->homolog->params->RingbackDetectionCyclesNumber;
|
||||
case GetMinRingbackCadenceOffTime:
|
||||
case GetMaxRingbackCadenceOffTime:
|
||||
case GetRingbackToneCallProgressFilterIndex:
|
||||
case GetMinCongestionCadenceOnTime:
|
||||
case GetMaxCongestionCadenceOnTime:
|
||||
case GetCongestionDetectionCyclesNumber:
|
||||
case GetMinCongestionCadenceOffTime:
|
||||
case GetMaxCongestionCadenceOffTime:
|
||||
case GetCongestionToneCallProgressFilterIndex:
|
||||
return 0;
|
||||
case GetCallProgressSamplesBufferLength:
|
||||
return m->homolog->params->CallProgressSamplesBufferLength;
|
||||
case MustNoiseFilterBeApplied:
|
||||
return m->homolog->params->MustNoiseFilterBeApplied;
|
||||
case GetAdditAttenToBeepgenVoice:
|
||||
return 0;
|
||||
case GetDialToneFilterSubindex:
|
||||
return 0;
|
||||
case GetBusyToneLooseDetectionEnabled:
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
long modem_set_param(struct modem *m, unsigned name, int val)
|
||||
{
|
||||
switch(name) {
|
||||
case MDMPRM_NONE:
|
||||
break;
|
||||
case MDMPRM_RX_RATE:
|
||||
m->rx_rate = val;
|
||||
break;
|
||||
case MDMPRM_TX_RATE:
|
||||
m->tx_rate = val;
|
||||
break;
|
||||
case MDMPRM_DP_REQUESTED:
|
||||
m->dp_requested = val;
|
||||
break;
|
||||
case MDMPRM_UPDATE_DELAY:
|
||||
m->update_delay = val;
|
||||
break;
|
||||
case MDMPRM_HOOK_ON:
|
||||
return m->driver.ioctl(m, MDMCTL_HOOKSTATE,
|
||||
val ? MODEM_HOOK_ON : MODEM_HOOK_OFF );
|
||||
case MDMPRM_PULSE_DIAL:
|
||||
// bla-bla
|
||||
return m->driver.ioctl(m, MDMCTL_PULSEDIAL, val);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
202
slmodemd/modem_param.h
Normal file
202
slmodemd/modem_param.h
Normal file
|
@ -0,0 +1,202 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_param.h -- modem parameters access definitions.
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MODEM_PARAM_H__
|
||||
#define __MODEM_PARAM_H__
|
||||
|
||||
/* param names */
|
||||
enum MODEM_PARAMETER_NAMES {
|
||||
MDMPRM_NONE,
|
||||
MDMPRM_RX_RATE,
|
||||
MDMPRM_RATE = MDMPRM_RX_RATE,
|
||||
MDMPRM_TX_RATE,
|
||||
MDMPRM_MIN_RATE,
|
||||
MDMPRM_MAX_RATE,
|
||||
MDMPRM_IODELAY,
|
||||
MDMPRM_CODECTYPE,
|
||||
MDMPRM_DIALSTR,
|
||||
MDMPRM_AUTOMODE,
|
||||
MDMPRM_DP_REQUESTED,
|
||||
MDMPRM_DPRUNTIME,
|
||||
MDMPRM_DSPINFO,
|
||||
MDMPRM_VOICEINFO,
|
||||
MDMPRM_UPDATE_DELAY,
|
||||
MDMPRM_DP_ADDR,
|
||||
MDMPRM_HOOK_ON,
|
||||
MDMPRM_PULSE_DIAL,
|
||||
//GetDTMFBetweenDigitsInterval,
|
||||
GetPulseDialMakeTime,
|
||||
GetPulseDialBreakTime,
|
||||
GetPulseDialDigitPattern,
|
||||
GetDTMFHighToneLevel,
|
||||
GetDTMFDialSpeed,
|
||||
//GetCallProgressDetectionThreshold,
|
||||
//GetDialToneDelay,
|
||||
//GetDialToneHoleTime,
|
||||
//GetDelayBeforeRingCountResettingInMcs,
|
||||
//GetRingCountForAutoanswer,
|
||||
//GetMinRingSignalPeriodInMcs,
|
||||
//GetMaxRingSignalPeriodInMcs,
|
||||
//GetMinRingCadenceOnTimeInMcs,
|
||||
//GetRingCadenceOffTimeInMcs,
|
||||
GetMinBusyCadenceOnTime,
|
||||
GetMaxBusyCadenceOnTime,
|
||||
GetBusyDetectionCyclesNumber,
|
||||
GetMinBusyCadenceOffTime,
|
||||
GetMaxBusyCadenceOffTime,
|
||||
//GetContinuousUnavailableDetectionFlag,
|
||||
//GetAnswerToneValidationTime,
|
||||
//GetBlacklistingDelayedFlag,
|
||||
//GetFailedAttemptsAllowedInFirstStage,
|
||||
//GetFailedAttemptsNumberBeforeBlacklisting,
|
||||
//GetTroubledCallDelay,
|
||||
//GetIneffectiveCallDelay,
|
||||
//GetErroneousCallDelay,
|
||||
//GetBlackListingDuration,
|
||||
//GetLoopCurrentSenseWaitingTime,
|
||||
GetCallingToneFlag,
|
||||
//GetBlindDialFlag,
|
||||
//GetBusyDetectDisable,
|
||||
//GetGuardToneType,
|
||||
//GetBellModesPermittedFlag,
|
||||
//GetOffHookRestrictions,
|
||||
//GetShuntRelayOnTimeDuringOffHook,
|
||||
GetHookFlashTime,
|
||||
GetBlindDialPause,
|
||||
GetNoAnswerTimeOut,
|
||||
GetDialPauseTime,
|
||||
//GetNoCarrierDisconnectTime,
|
||||
GetTransmitLevel,
|
||||
GetDialModifierValidation,
|
||||
//GetTADReceiveGain,
|
||||
//GetHalfOrFullWaveRingDetection,
|
||||
//GetFailedAttemptsNumberBeforeBlockingFurtherAttempts,
|
||||
//GetErroneousCallIncrementCount,
|
||||
GetDialToneValidationTime,
|
||||
//GetDialToneMinOnTimePeriod,
|
||||
GetBusyToneDiffTime,
|
||||
//GetBusyToneDetectionDuringDialToneDetectionFlag,
|
||||
GetDTMFHighAndLowToneLevelDifference,
|
||||
//GetLocalPhoneDetectionInSpeakerphone,
|
||||
GetPulseDialingFlag,
|
||||
GetDialToneCallProgressFilterIndex,
|
||||
GetDialToneDetectionThreshold,
|
||||
GetABCDDialingPermittedFlag,
|
||||
GetComaPauseDurationLimit,
|
||||
//GetTADTransmitLevel,
|
||||
//GetDataFAXCarrierReceiveThreshold,
|
||||
//GetNoDialToneTimeOutDuration,
|
||||
//GetFAXDataAnswerToneDetectionThreshold,
|
||||
//GetDialToneLevel,
|
||||
//GetFAXCallingToneLevel,
|
||||
GetPulseAndToneDialInSameDialStringPermittedFlag,
|
||||
//GetRingerImpedanceRelayFlag,
|
||||
//GetDCLoopVICharacteristicsRelayFlag,
|
||||
//GetDCLoopLimitingRelayFlag,
|
||||
//GetRealOrComplexImpedance,
|
||||
//GetMinPauseBetweenRingSequencesInMcs,
|
||||
//GetMaxPauseBetweenRingSequencesInMcs,
|
||||
//GetMinRingCadenceOnTimeFirstInMcs,
|
||||
//GetMaxRingCadenceOnTimeFirstInMcs,
|
||||
//GetMinRingCadenceOnTimeForFirstSequenceInMcs,
|
||||
//GetMaxRingCadenceOnTimeForFirstSequenceInMcs,
|
||||
//GetMaxRingCadenceOnTimeInMcs,
|
||||
//GetNumberOfSequencesInFirstRing,
|
||||
//GetNumberOfSequencesInRegularRing,
|
||||
//IsALaw,
|
||||
GetBusyToneCallProgressFilterIndex,
|
||||
//GetCoefficientTableIndex,
|
||||
GetPulseBetweenDigitsInterval,
|
||||
GetDialToneWaitTime,
|
||||
//GetAnswerDelay,
|
||||
//GetPulseRefresh,
|
||||
//GetHandsetGain,
|
||||
//GetSpecificHardwareBitmask,
|
||||
//GetDefaultDTMFDialSpeed,
|
||||
//GetDefaultNoAnswerTimeout,
|
||||
//GetBlacklistingTimeout,
|
||||
//IsATPCommandDisabled,
|
||||
//GetDelayAfterCounterpartDisconnection,
|
||||
//IsFloatModeForced,
|
||||
//GetDataFaxCarrierDisconnectThreshold,
|
||||
//GetFaxTransmitLevel,
|
||||
//GetPulseDialingRefreshScheme,
|
||||
GetMinRingbackCadenceOnTime,
|
||||
GetMaxRingbackCadenceOnTime,
|
||||
GetRingbackDetectionCyclesNumber,
|
||||
GetMinRingbackCadenceOffTime,
|
||||
GetMaxRingbackCadenceOffTime,
|
||||
GetRingbackToneCallProgressFilterIndex,
|
||||
GetMinCongestionCadenceOnTime,
|
||||
GetMaxCongestionCadenceOnTime,
|
||||
GetCongestionDetectionCyclesNumber,
|
||||
GetMinCongestionCadenceOffTime,
|
||||
GetMaxCongestionCadenceOffTime,
|
||||
GetCongestionToneCallProgressFilterIndex,
|
||||
GetCallProgressSamplesBufferLength,
|
||||
MustNoiseFilterBeApplied,
|
||||
//GetDigitalImpairmentsMask,
|
||||
GetAdditAttenToBeepgenVoice,
|
||||
GetDialToneFilterSubindex,
|
||||
GetBusyToneLooseDetectionEnabled,
|
||||
//GetRingFreqValueInHz(int);
|
||||
//GetEndUniversalRingTimeoutInMcs,
|
||||
//GetRingIntsForFreq,
|
||||
//GetDelayBeforeUniversalRingCountResettingInMcs,
|
||||
//GetUniversalRingDetectorEnabled,
|
||||
//GetCallWaitingIntegrationTimeMiliSec,
|
||||
//GetCallWaitingThresholdPercentage,
|
||||
//GetDialStringAfterFlash(char *dialString);
|
||||
MDMPRM_LAST
|
||||
};
|
||||
|
||||
|
||||
struct modem;
|
||||
|
||||
extern long modem_get_param(struct modem *m, unsigned param);
|
||||
extern long modem_set_param(struct modem *m, unsigned name, int val);
|
||||
|
||||
extern long modem_get_sreg_param(struct modem *m, unsigned sreg_param);
|
||||
|
||||
#endif /* __MODEM_PARAM_H__ */
|
||||
|
481
slmodemd/modem_test.c
Normal file
481
slmodemd/modem_test.c
Normal file
|
@ -0,0 +1,481 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_test.c -- modem simulator.
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <modem.h>
|
||||
#include <modem_debug.h>
|
||||
|
||||
#define INFO(fmt,args...) fprintf(stderr, fmt , ##args );
|
||||
#define ERR(fmt,args...) fprintf(stderr, "error: " fmt , ##args );
|
||||
|
||||
#define DBG(fmt,args...) if(modem_debug_level) \
|
||||
fprintf(stderr, "main: " fmt , ##args );
|
||||
|
||||
|
||||
//#define SIMULATE_RING 1
|
||||
|
||||
|
||||
/* modem init externals : FIXME remove it */
|
||||
extern int dp_dummy_init(void);
|
||||
extern void dp_dummy_exit(void);
|
||||
extern int dp_sinus_init(void);
|
||||
extern void dp_sinus_exit(void);
|
||||
extern int prop_dp_init(void);
|
||||
extern void prop_dp_exit(void);
|
||||
extern int datafile_load_info(char *name,struct dsp_info *info);
|
||||
extern int datafile_save_info(char *name,struct dsp_info *info);
|
||||
|
||||
|
||||
/* global config data */
|
||||
extern unsigned modem_debug_logging;
|
||||
|
||||
|
||||
struct modem_test {
|
||||
struct modem *modem;
|
||||
struct modem_test *link;
|
||||
int in,out;
|
||||
unsigned int delay;
|
||||
unsigned int started;
|
||||
unsigned pty_closed;
|
||||
unsigned close_count;
|
||||
};
|
||||
|
||||
|
||||
#define CLOSE_COUNT_MAX 100
|
||||
|
||||
/* static data */
|
||||
static char inbuf[4096];
|
||||
static char outbuf[4096];
|
||||
|
||||
|
||||
/* 'driver' simulation */
|
||||
|
||||
static int modem_test_start (struct modem *m)
|
||||
{
|
||||
struct modem_test *t = m->dev_data;
|
||||
DBG("modem_test_start...\n");
|
||||
t->delay = 256;
|
||||
t->started = 1;
|
||||
memset(outbuf,0,t->delay);
|
||||
write(t->out,outbuf,t->delay);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int modem_test_stop (struct modem *m)
|
||||
{
|
||||
struct modem_test *t = m->dev_data;
|
||||
DBG("modem_test_stop...\n");
|
||||
t->started = 0;
|
||||
t->delay = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int modem_test_ioctl(struct modem *m, unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
struct modem_test *t = m->dev_data;
|
||||
DBG("modem_test_ioctl: cmd %x, arg %lx...\n",cmd,arg);
|
||||
switch (cmd) {
|
||||
case MDMCTL_CAPABILITIES:
|
||||
return -1;
|
||||
case MDMCTL_HOOKSTATE:
|
||||
return 0;
|
||||
case MDMCTL_SPEED:
|
||||
return 0;
|
||||
case MDMCTL_GETFMTS:
|
||||
case MDMCTL_SETFMT:
|
||||
return 0;
|
||||
case MDMCTL_SETFRAGMENT:
|
||||
return 0;
|
||||
case MDMCTL_SPEAKERVOL:
|
||||
return 0;
|
||||
case MDMCTL_CODECTYPE:
|
||||
return CODEC_UNKNOWN;
|
||||
case MDMCTL_IODELAY:
|
||||
return t->delay/2;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct modem_driver modem_test_driver = {
|
||||
.name = "modem_test driver",
|
||||
.start = modem_test_start,
|
||||
.stop = modem_test_stop,
|
||||
.ioctl = modem_test_ioctl,
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
static volatile sig_atomic_t keep_running = 1;
|
||||
|
||||
void mark_termination(int signum)
|
||||
{
|
||||
DBG("signal %d: mark termination.\n",signum);
|
||||
keep_running = 0;
|
||||
}
|
||||
|
||||
|
||||
static int modem_test_run(struct modem_test *modems)
|
||||
{
|
||||
struct timeval tmo;
|
||||
fd_set rset,eset;
|
||||
struct termios termios;
|
||||
struct modem_test *t;
|
||||
void *in;
|
||||
int max_fd = 0;
|
||||
int count, ret;
|
||||
|
||||
#ifdef SIMULATE_RING
|
||||
#define RING_HZ 20
|
||||
#define RING_ON 1*RING_HZ
|
||||
#define RING_OFF 4*RING_HZ
|
||||
unsigned rcount = RING_ON;
|
||||
#endif
|
||||
|
||||
|
||||
while(keep_running) {
|
||||
|
||||
for( t = modems ; t->modem ; t++ )
|
||||
if(t->modem->event)
|
||||
modem_event(t->modem);
|
||||
#ifdef SIMULATE_RING
|
||||
tmo.tv_sec = 0;
|
||||
tmo.tv_usec= 1000000/RING_HZ;
|
||||
#else
|
||||
tmo.tv_sec = 1;
|
||||
tmo.tv_usec= 0;
|
||||
#endif
|
||||
FD_ZERO(&rset);
|
||||
FD_ZERO(&eset);
|
||||
max_fd = 0;
|
||||
|
||||
for( t = modems ; t->modem ; t++ ) {
|
||||
FD_SET(t->in,&rset);
|
||||
FD_SET(t->in,&eset);
|
||||
if(t->in > max_fd)
|
||||
max_fd = t->in;
|
||||
if( t->pty_closed && t->close_count ) {
|
||||
if ( !t->started ||
|
||||
t->close_count++ > CLOSE_COUNT_MAX )
|
||||
t->close_count = 0;
|
||||
}
|
||||
else if (t->modem->xmit.size - t->modem->xmit.count > 0) {
|
||||
FD_SET(t->modem->pty,&rset);
|
||||
if(t->modem->pty > max_fd)
|
||||
max_fd = t->modem->pty;
|
||||
}
|
||||
}
|
||||
|
||||
ret = select(max_fd + 1,&rset,NULL,&eset,&tmo);
|
||||
|
||||
if (ret < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
ERR("select: %s\n",strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
|
||||
//DBG("select = %d\n",ret);
|
||||
if (ret == 0) {
|
||||
#ifdef SIMULATE_RING
|
||||
if(!modems->modem->started) {
|
||||
rcount++;
|
||||
if (rcount <= RING_ON)
|
||||
modem_ring(modems->modem);
|
||||
else if (rcount > RING_OFF)
|
||||
rcount = 0;
|
||||
}
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
for( t = modems ; t->modem ; t++ ) {
|
||||
if(FD_ISSET(t->in,&eset)) {
|
||||
DBG("dev exception...\n");
|
||||
}
|
||||
}
|
||||
|
||||
for( t = modems ; t->modem ; t++ ) {
|
||||
if(FD_ISSET(t->in,&rset)) {
|
||||
//DBG("dev read...\n");
|
||||
count = read(t->in,inbuf,sizeof(inbuf)/2);
|
||||
if(count < 0) {
|
||||
ERR("dev read: %s\n",strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
else if (count == 0) {
|
||||
DBG("dev read = 0\n");
|
||||
continue;
|
||||
}
|
||||
in = inbuf;
|
||||
if(t->modem->update_delay < 0) {
|
||||
if ( -t->modem->update_delay >= count/2) {
|
||||
DBG("change delay -%d...\n", count/2);
|
||||
t->delay -= count;
|
||||
t->modem->update_delay += count/2;
|
||||
continue;
|
||||
}
|
||||
DBG("change delay %d...\n", t->modem->update_delay);
|
||||
in -= t->modem->update_delay*2;
|
||||
count += t->modem->update_delay*2;
|
||||
t->delay += t->modem->update_delay*2;
|
||||
t->modem->update_delay = 0;
|
||||
}
|
||||
if(t->started) {
|
||||
modem_process(t->modem,in,outbuf,count>>1);
|
||||
}
|
||||
else {
|
||||
memset(outbuf,0,count);
|
||||
/* ring here */
|
||||
}
|
||||
count = write(t->out,outbuf,count);
|
||||
if(count < 0) {
|
||||
ERR("dev write: %s\n",strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
else if (count == 0) {
|
||||
DBG("dev write = 0\n");
|
||||
}
|
||||
if(t->modem->update_delay > 0) {
|
||||
DBG("change delay %d...\n", t->modem->update_delay);
|
||||
memset(outbuf, 0, t->modem->update_delay*2);
|
||||
count = write(t->out,outbuf,t->modem->update_delay*2);
|
||||
if(count < 0) {
|
||||
ERR("dev write: %s\n",strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
t->delay += t->modem->update_delay*2;
|
||||
t->modem->update_delay = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( t = modems ; t->modem ; t++ ) {
|
||||
int pty = t->modem->pty;
|
||||
if(FD_ISSET(pty,&rset)) {
|
||||
//DBG("pty read...\n");
|
||||
/* check termios */
|
||||
tcgetattr(pty,&termios);
|
||||
if(memcmp(&termios,&t->modem->termios,
|
||||
sizeof(termios))) {
|
||||
DBG("termios changed.\n");
|
||||
modem_update_termios(t->modem, &termios);
|
||||
}
|
||||
/* read data */
|
||||
count = t->modem->xmit.size - t->modem->xmit.count;
|
||||
if(count == 0)
|
||||
continue;
|
||||
if (count > sizeof(inbuf))
|
||||
count = sizeof(inbuf);
|
||||
count = read(pty,inbuf,count);
|
||||
if(count < 0) {
|
||||
if(errno == EAGAIN) {
|
||||
DBG("pty read, errno = EAGAIN\n");
|
||||
continue;
|
||||
}
|
||||
if(errno == EIO) {
|
||||
if(!t->pty_closed) {
|
||||
DBG("pty closed.\n");
|
||||
t->pty_closed = 1;
|
||||
if(termios.c_cflag&HUPCL)
|
||||
modem_hangup(t->modem);
|
||||
}
|
||||
t->close_count = 1;
|
||||
//DBG("pty read, errno=EIO\n");
|
||||
continue;
|
||||
}
|
||||
else
|
||||
ERR("pty read: %s\n",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
else if (count == 0) {
|
||||
DBG("pty read = 0\n");
|
||||
}
|
||||
t->pty_closed = 0;
|
||||
//DBG("pty read %d\n",count);
|
||||
count = modem_write(t->modem,inbuf,count);
|
||||
if(count < 0) {
|
||||
DBG("modem_write failed.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int modem_test_init(struct modem_test *t, const char *name, int in, int out)
|
||||
{
|
||||
struct termios termios;
|
||||
char *pty_name;
|
||||
int pty;
|
||||
int ret;
|
||||
|
||||
memset(t,0,sizeof(*t));
|
||||
|
||||
t->in = in;
|
||||
t->out = out;
|
||||
|
||||
pty = getpt();
|
||||
if (pty < 0 || grantpt(pty) < 0 || unlockpt(pty) < 0) {
|
||||
ERR("getpt: %s\n",strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
ret = tcgetattr(pty, &termios);
|
||||
/* non canonical raw tty */
|
||||
cfmakeraw(&termios);
|
||||
cfsetispeed(&termios, B115200);
|
||||
cfsetospeed(&termios, B115200);
|
||||
|
||||
ret = tcsetattr(pty, TCSANOW, &termios);
|
||||
if (ret) {
|
||||
ERR("tcsetattr: %s\n",strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fcntl(pty,F_SETFL,O_NONBLOCK);
|
||||
|
||||
pty_name = ptsname(pty);
|
||||
|
||||
t->modem = modem_create(&modem_test_driver,name);
|
||||
if(!t->modem) {
|
||||
return -1;
|
||||
}
|
||||
t->modem->name = name;
|
||||
t->modem->pty = pty;
|
||||
//t->modem->dev = dev;
|
||||
t->modem->dev_name = name;
|
||||
t->modem->pty_name = pty_name;
|
||||
// datafile_load_info(basename(dev_name),&t->modem->dsp_info);
|
||||
modem_update_termios(t->modem,&termios);
|
||||
t->modem->dev_data = t;
|
||||
|
||||
DBG("created %s: %s\n",t->modem->name,t->modem->pty_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void modem_test_free(struct modem_test *t)
|
||||
{
|
||||
int pty = t->modem->pty;
|
||||
modem_delete(t->modem);
|
||||
close(pty);
|
||||
}
|
||||
|
||||
|
||||
int modem_test()
|
||||
{
|
||||
struct modem_test *ma, *mb;
|
||||
struct modem_test modems[3] = {};
|
||||
int pipe1[2], pipe2[2];
|
||||
int ret = 0;
|
||||
|
||||
modem_debug_init("test");
|
||||
|
||||
memset(modems,0,sizeof(modems));
|
||||
|
||||
dp_dummy_init();
|
||||
dp_sinus_init();
|
||||
prop_dp_init();
|
||||
modem_timer_init();
|
||||
|
||||
ma = &modems[0];
|
||||
mb = &modems[1];
|
||||
|
||||
if(pipe(pipe1) < 0 || pipe(pipe2) < 0) {
|
||||
ERR("pipe: %s\n",strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
modem_test_init(ma,"modemA",pipe1[0],pipe2[1]);
|
||||
modem_test_init(mb,"modemB",pipe2[0],pipe1[1]);
|
||||
|
||||
ma->link = mb;
|
||||
mb->link = ma;
|
||||
|
||||
signal(SIGINT, mark_termination);
|
||||
signal(SIGTERM, mark_termination);
|
||||
|
||||
/* main loop here */
|
||||
ret = modem_test_run(modems);
|
||||
|
||||
modem_test_free(ma);
|
||||
modem_test_free(mb);
|
||||
|
||||
dp_dummy_exit();
|
||||
dp_sinus_exit();
|
||||
prop_dp_exit();
|
||||
|
||||
exit(ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
extern void modem_cmdline(int argc, char *argv[]);
|
||||
modem_debug_level = 1;
|
||||
modem_cmdline(argc,argv);
|
||||
return modem_test();
|
||||
}
|
205
slmodemd/modem_timer.c
Normal file
205
slmodemd/modem_timer.c
Normal file
|
@ -0,0 +1,205 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_timer.c -- simple timer (will not in multithreaded env).
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <modem_timer.h>
|
||||
|
||||
#if 0
|
||||
#include <stdio.h>
|
||||
#define WARN(fmt...) fprintf(stderr, fmt);
|
||||
#else
|
||||
#define WARN(fmt...)
|
||||
#endif
|
||||
|
||||
#define MAX_TIME LONG_MAX
|
||||
|
||||
static struct timeval tv_init;
|
||||
|
||||
static struct timer_list_struct {
|
||||
struct timer *list;
|
||||
unsigned long when;
|
||||
struct sigaction old_act;
|
||||
} timer_list;
|
||||
|
||||
|
||||
|
||||
unsigned long get_time()
|
||||
{
|
||||
struct timeval tv_now,tv;
|
||||
gettimeofday(&tv_now,NULL);
|
||||
timersub(&tv_now,&tv_init,&tv);
|
||||
return tv.tv_sec*MODEM_HZ + tv.tv_usec/(1000000/MODEM_HZ);
|
||||
}
|
||||
|
||||
static void set_timer(unsigned long when)
|
||||
{
|
||||
struct itimerval it;
|
||||
long t;
|
||||
t = (long)(when - get_time());
|
||||
if( t <= 0) t = 1;
|
||||
it.it_interval.tv_usec = 0;
|
||||
it.it_interval.tv_sec = 0;
|
||||
it.it_value.tv_usec = (t%MODEM_HZ)*(1000000/MODEM_HZ);
|
||||
it.it_value.tv_sec = t/MODEM_HZ;
|
||||
setitimer(ITIMER_REAL,&it,NULL);
|
||||
}
|
||||
|
||||
|
||||
static void timer_list_handler(int num)
|
||||
{
|
||||
unsigned long now;
|
||||
struct timer *t,*next;
|
||||
now = get_time();
|
||||
t = timer_list.list;
|
||||
timer_list.list = NULL;
|
||||
while(t) {
|
||||
next = t->next;
|
||||
t->next = NULL;
|
||||
if( (long)(t->expires - now) <= 0 ) {
|
||||
t->added = 0;
|
||||
if(t->func) {
|
||||
t->func(t->data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
t->next = timer_list.list;
|
||||
timer_list.list = t;
|
||||
}
|
||||
t = next;
|
||||
}
|
||||
timer_list.when = now + MAX_TIME;
|
||||
t = timer_list.list;
|
||||
while(t) {
|
||||
if((long)(timer_list.when - t->expires) > 0)
|
||||
timer_list.when = t->expires;
|
||||
t = t->next;
|
||||
}
|
||||
set_timer(timer_list.when);
|
||||
}
|
||||
|
||||
|
||||
void timer_init(struct timer *t)
|
||||
{
|
||||
t->next = 0;
|
||||
t->added = 0;
|
||||
t->expires = 0;
|
||||
t->func = NULL;
|
||||
t->data = NULL;
|
||||
}
|
||||
|
||||
int timer_add(struct timer *t)
|
||||
{
|
||||
sigset_t set, old_set;
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set,SIGALRM);
|
||||
sigprocmask(SIG_BLOCK,&set,&old_set);
|
||||
if(t->added) {
|
||||
WARN("timer_add: already.\n");
|
||||
}
|
||||
else {
|
||||
t->added = 1;
|
||||
t->next = timer_list.list;
|
||||
timer_list.list = t;
|
||||
}
|
||||
if((long)(timer_list.when - t->expires) > 0) {
|
||||
timer_list.when = t->expires;
|
||||
set_timer(timer_list.when);
|
||||
}
|
||||
sigprocmask(SIG_SETMASK,&old_set,NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int timer_del(struct timer *t)
|
||||
{
|
||||
sigset_t set, old_set;
|
||||
struct timer *p, **prev;
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set,SIGALRM);
|
||||
sigprocmask(SIG_BLOCK,&set,&old_set);
|
||||
if(t->added) {
|
||||
p = timer_list.list;
|
||||
prev = &timer_list.list;
|
||||
while(p) {
|
||||
if(p == t) {
|
||||
*prev = t->next;
|
||||
t->next = NULL;
|
||||
t->added = 0;
|
||||
break;
|
||||
}
|
||||
prev = &((*prev)->next);
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
else {
|
||||
WARN("timer_del: not added\n");
|
||||
}
|
||||
sigprocmask(SIG_SETMASK,&old_set,NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int modem_timer_init()
|
||||
{
|
||||
struct sigaction act;
|
||||
gettimeofday(&tv_init,NULL);
|
||||
timer_list.list = NULL;
|
||||
timer_list.when = get_time() + MAX_TIME;
|
||||
act.sa_handler = timer_list_handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaddset(&act.sa_mask, SIGALRM);
|
||||
act.sa_flags = SA_SIGINFO;
|
||||
sigaction(SIGALRM,&act,&timer_list.old_act);
|
||||
set_timer(timer_list.when);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void modem_timer_exit()
|
||||
{
|
||||
sigaction(SIGALRM,&timer_list.old_act,NULL);
|
||||
}
|
||||
|
||||
|
70
slmodemd/modem_timer.h
Normal file
70
slmodemd/modem_timer.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* modem_timer.h -- definitions for simple timer.
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MODEM_TIMER_H__
|
||||
#define __MODEM_TIMER_H__
|
||||
|
||||
|
||||
#define MODEM_HZ 100
|
||||
|
||||
struct timer {
|
||||
struct timer *next;
|
||||
unsigned added;
|
||||
unsigned expires;
|
||||
void (*func)(void *);
|
||||
void *data;
|
||||
};
|
||||
|
||||
|
||||
#define time_before(t1,t2) ((long)((t2)-(t1)) > 0)
|
||||
#define time_after(t1,t2) (!time_before(t1,t2))
|
||||
|
||||
unsigned long get_time(void);
|
||||
|
||||
extern void timer_init(struct timer *t);
|
||||
extern int timer_add(struct timer *t);
|
||||
extern int timer_del(struct timer *t);
|
||||
|
||||
extern int modem_timer_init(void);
|
||||
|
||||
#endif /* __MODEM_TIMER_H__ */
|
112
slmodemd/sysdep_common.c
Normal file
112
slmodemd/sysdep_common.c
Normal file
|
@ -0,0 +1,112 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2002, Smart Link Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. Neither the name of the Smart Link Ltd. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* sysdep_common.c -- sysdep API.
|
||||
*
|
||||
* Author: Sasha K (sashak@smlink.com)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
/* memory allocations */
|
||||
void *sysdep_malloc (unsigned int size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void sysdep_free (void *mem)
|
||||
{
|
||||
free(mem);
|
||||
}
|
||||
|
||||
/* strings */
|
||||
size_t sysdep_strlen(const char *s)
|
||||
{
|
||||
return strlen(s);
|
||||
}
|
||||
char *sysdep_strcpy(char *d,const char *s)
|
||||
{
|
||||
return strcpy(d,s);
|
||||
}
|
||||
char *sysdep_strcat(char *d, const char *s)
|
||||
{
|
||||
return strcat(d,s);
|
||||
}
|
||||
int sysdep_strcmp(const char *s1,const char *s2)
|
||||
{
|
||||
return strcmp(s1, s2);
|
||||
}
|
||||
char *sysdep_strstr(const char *s1,const char *s2)
|
||||
{
|
||||
return strstr(s1,s2);
|
||||
}
|
||||
void *sysdep_memset(void *d,int c,size_t l)
|
||||
{
|
||||
return memset(d,c,l);
|
||||
}
|
||||
void *sysdep_memcpy(void *d,const void *s,size_t l)
|
||||
{
|
||||
return memcpy(d,s,l);
|
||||
}
|
||||
void *sysdep_memchr(const void *s,int c,size_t l)
|
||||
{
|
||||
return memchr (s,c,l);
|
||||
}
|
||||
|
||||
int sysdep_vsnprintf(char *str, unsigned size, const char *format, va_list ap)
|
||||
{
|
||||
return vsnprintf(str, size, format, ap);
|
||||
}
|
||||
|
||||
int sysdep_sprintf(char *buf, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int i;
|
||||
va_start(args, fmt);
|
||||
i=vsprintf(buf,fmt,args);
|
||||
va_end(args);
|
||||
return i;
|
||||
}
|
||||
|
Loading…
Reference in a new issue